Class: Rbjs::Root

Inherits:
Object
  • Object
show all
Defined in:
lib/rbjs.rb,
lib/rbjs/setup_action_view.rb

Instance Method Summary collapse

Constructor Details

#initialize(view_context, &block) ⇒ Root

Returns a new instance of Root.



19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
# File 'lib/rbjs.rb', line 19

def initialize view_context, &block
  @_view_context = view_context and
  if view_context.respond_to?(:assigns)
    for instance_var, val in view_context.assigns
      instance_variable_set '@'+instance_var, val
    end
  else
    for instance_var in view_context.instance_variables.map(&:to_s)
      instance_variable_set instance_var, view_context.instance_variable_get(instance_var)
    end
  end
  if @_view_context.respond_to?(:helpers) && @_view_context.helpers
    extend @_view_context.helpers
  end
  @_block = block
  @_called_expressions = []
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(name, *args, &block) ⇒ Object Also known as: const_missing



42
43
44
45
46
47
48
49
50
# File 'lib/rbjs.rb', line 42

def method_missing name, *args, &block
  if @_view_context and @_view_context.respond_to?(name)
    @_view_context.send name, *args, &block
  else
    expression = Expression.new name.to_s.gsub('!', '()'), @_view_context, *args, &block
    @_called_expressions << expression
    expression
  end
end

Instance Method Details

#<<(line) ⇒ Object



53
54
55
# File 'lib/rbjs.rb', line 53

def << line
  @_called_expressions << Expression.new(line)
end

#evaluate(function_parameters = nil) ⇒ Object



37
38
39
40
# File 'lib/rbjs.rb', line 37

def evaluate function_parameters = nil
  instance_exec *function_parameters, &@_block
  @_called_expressions.map(&:last_childs).flatten.reject(&:is_argument).map(&:to_s).join(";\n")+";\n"
end

#render(options = {}, locals = {}, &block) ⇒ Object

make respond_to?(:render) return true.



27
28
29
# File 'lib/rbjs/setup_action_view.rb', line 27

def render(options = {}, locals = {}, &block)
  @_view_context.render(options, locals, &block) 
end