Class: Curlybars::Node::WithElse
- Inherits:
-
Struct
- Object
- Struct
- Curlybars::Node::WithElse
- Defined in:
- lib/curlybars/node/with_else.rb
Instance Attribute Summary collapse
-
#else_template ⇒ Object
Returns the value of attribute else_template.
-
#path ⇒ Object
Returns the value of attribute path.
-
#position ⇒ Object
Returns the value of attribute position.
-
#with_template ⇒ Object
Returns the value of attribute with_template.
Instance Method Summary collapse
Instance Attribute Details
#else_template ⇒ Object
Returns the value of attribute else_template
3 4 5 |
# File 'lib/curlybars/node/with_else.rb', line 3 def else_template @else_template end |
#path ⇒ Object
Returns the value of attribute path
3 4 5 |
# File 'lib/curlybars/node/with_else.rb', line 3 def path @path end |
#position ⇒ Object
Returns the value of attribute position
3 4 5 |
# File 'lib/curlybars/node/with_else.rb', line 3 def position @position end |
#with_template ⇒ Object
Returns the value of attribute with_template
3 4 5 |
# File 'lib/curlybars/node/with_else.rb', line 3 def with_template @with_template end |
Instance Method Details
#cache_key ⇒ Object
49 50 51 52 53 54 55 |
# File 'lib/curlybars/node/with_else.rb', line 49 def cache_key [ path, with_template, else_template ].map(&:cache_key).push(self.class.name).join("/") end |
#compile ⇒ Object
4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 |
# File 'lib/curlybars/node/with_else.rb', line 4 def compile # NOTE: the following is a heredoc string, representing the ruby code fragment # outputted by this node. <<-RUBY compiled_path = rendering.cached_call(#{path.compile}) if rendering.to_bool(compiled_path) position = rendering.position(#{position.line_number}, #{position.line_offset}) rendering.check_context_is_presenter(compiled_path, #{presenter_path.path.inspect}, position) contexts.push(compiled_path) begin #{with_template.compile} ensure contexts.pop end else #{else_template.compile} end RUBY end |
#presenter_path ⇒ Object
45 46 47 |
# File 'lib/curlybars/node/with_else.rb', line 45 def presenter_path path.subexpression? ? path.helper : path end |
#validate(branches) ⇒ Object
26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 |
# File 'lib/curlybars/node/with_else.rb', line 26 def validate(branches) sub_tree = path.resolve_and_check!(branches, check_type: :presenterlike) with_template_errors = begin branches.push(sub_tree) with_template.validate(branches) ensure branches.pop end else_template_errors = else_template.validate(branches) [ with_template_errors, else_template_errors ] rescue Curlybars::Error::Validate => path_error path_error end |