Class: Curlybars::Node::Template

Inherits:
Struct
  • Object
show all
Defined in:
lib/curlybars/node/template.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#itemsObject

Returns the value of attribute items

Returns:

  • (Object)

    the current value of items



3
4
5
# File 'lib/curlybars/node/template.rb', line 3

def items
  @items
end

#positionObject

Returns the value of attribute position

Returns:

  • (Object)

    the current value of position



3
4
5
# File 'lib/curlybars/node/template.rb', line 3

def position
  @position
end

Instance Method Details

#cache_keyObject



27
28
29
# File 'lib/curlybars/node/template.rb', line 27

def cache_key
  Digest::MD5.hexdigest(items.map(&:cache_key).join("/"))
end

#compileObject



4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
# File 'lib/curlybars/node/template.rb', line 4

def compile
  compiled_items = items.map(&:compile).join("\n")

  # NOTE: the following is a heredoc string, representing the ruby code fragment
  # outputted by this node.
  <<-RUBY
    ::Module.new do
      def self.exec(contexts, rendering, variables, buffer)
        unless contexts.length < ::Curlybars.configuration.nesting_limit
          message = "Nesting too deep"
          position = rendering.position(#{position.line_number}, #{position.line_offset})
          raise ::Curlybars::Error::Render.new('nesting_too_deep', message, position)
        end
        #{compiled_items}
      end
    end.exec(contexts, rendering, variables, buffer)
  RUBY
end

#validate(branches) ⇒ Object



23
24
25
# File 'lib/curlybars/node/template.rb', line 23

def validate(branches)
  items.map { |item| item.validate(branches) }
end