Module: Zafu::Process::Context

Defined in:
lib/zafu/process/context.rb

Overview

This module manages the change of contexts by opening (each) or moving into the NodeContext. The ‘@context’ holds many information on the current compilation environment. Inside this context, the “node” context holds information on the type of “this” (first responder).

Instance Method Summary collapse

Instance Method Details

#expand_with_node(name, klass) ⇒ Object



26
27
28
# File 'lib/zafu/process/context.rb', line 26

def expand_with_node(name, klass)
  expand_with(:node => @context[:node].move_to(name, klass))
end

#helperObject



15
16
17
# File 'lib/zafu/process/context.rb', line 15

def helper
  @context[:helper]
end

#node(klass = nil) ⇒ Object

Return the node context for a given class (looks up into the hierarchy) or the current node context if klass is nil.



21
22
23
24
# File 'lib/zafu/process/context.rb', line 21

def node(klass = nil)
  return @context[:node] if !klass
  @context[:node].get(klass)
end

#r_eachObject



7
8
9
10
11
12
13
# File 'lib/zafu/process/context.rb', line 7

def r_each
  if node.klass.kind_of?(Array)
    out "<% #{node}.each do |#{var}| -%>"
    out render_html_tag(expand_with_node(var, node.klass.first))
    out "<% end -%>"
  end
end

#varObject

def context_with_node(name, klass)

context = @context.dup
context[:node] = context[:node].move_to(name, klass)

end



35
36
37
38
39
40
41
42
# File 'lib/zafu/process/context.rb', line 35

def var
  return @var if @var
  if node.name =~ /^var(\d+)$/
    @var = "var#{$1.to_i + 1}"
  else
    @var = "var1"
  end
end