Module: Netzke::Core::ClientCode::ClassMethods

Defined in:
lib/netzke/core/client_code.rb

Instance Method Summary collapse

Instance Method Details

#client_class(&block) ⇒ Object

Configures client class Example:

client_class do |c|
  # c is an instance of ClientClassConfig
  c.title = "My title"
  c.require :extra_js
  # ...etc
end

For more details see Netzke::Core::ClientClassConfig

Raises:

  • (ArgumentError)


18
19
20
21
22
# File 'lib/netzke/core/client_code.rb', line 18

def client_class &block
  raise ArgumentError, "client_class called without block" unless block_given?
  @configure_blocks ||= []
  @configure_blocks << [block, dir(caller.first)]
end

#client_class_configObject

Class-level client class config. Note: late evaluation of `client_class` blocks allows us using class-level configs in those blocks, e.g.:

class ConfigurableOnClassLevel < Netzke::Base
  class_attribute :title
  self.title = "Default"
  client_class do |c|
    c.title = self.title
  end
end

ConfigurableOnClassLevel.title = "Overridden"


36
37
38
39
40
41
42
43
44
45
46
47
# File 'lib/netzke/core/client_code.rb', line 36

def client_class_config
  return @client_class_config if @client_class_config

  @client_class_config = Netzke::Core::ClientClassConfig.new(self, called_from)

  (@configure_blocks || []).each do |block, dir|
    @client_class_config.dir = dir
    block.call(@client_class_config) if block
  end

  @client_class_config
end

#dir(cllr) ⇒ Object

Path to the dir with this component/extension's extra code (ruby modules, scripts, stylesheets)



50
51
52
# File 'lib/netzke/core/client_code.rb', line 50

def dir(cllr)
  %Q(#{cllr.split(".rb:").first})
end

#l(str) ⇒ Object

Converts given string to a string that returns itself as its JSON-encoded form for given string. See Netzke::Core::ClientCode#l



56
57
58
# File 'lib/netzke/core/client_code.rb', line 56

def l(str)
 Netzke::Core::JsonLiteral.new(str)
end