Class: Luoma::IfBlock

Inherits:
Markup
  • Object
show all
Defined in:
lib/luoma/tags/if.rb,
sig/luoma/tags/if.rbs

Constant Summary collapse

END_IF_BLOCK =

Returns:

  • (Set[String])

Instance Attribute Summary collapse

Attributes inherited from Markup

#blank, #tag_name, #token

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from Markup

#block_scope, #partial, #template_scope

Constructor Details

#initialize(token, tag_name, expression, block) ⇒ IfBlock

Returns a new instance of IfBlock.

Parameters:

  • token (t_token)
  • tag_name (String)
  • expression (Expression)
  • block (t_block)


82
83
84
85
86
87
88
# File 'lib/luoma/tags/if.rb', line 82

def initialize(token, tag_name, expression, block)
  super(token)
  @tag_name = tag_name
  @expression = expression
  @block = block
  @blank = Luoma.blank_block?(block)
end

Instance Attribute Details

#blockt_block (readonly)

Returns the value of attribute block.

Returns:

  • (t_block)


66
67
68
# File 'lib/luoma/tags/if.rb', line 66

def block
  @block
end

#expressionExpression (readonly)

Returns the value of attribute expression.

Returns:



66
67
68
# File 'lib/luoma/tags/if.rb', line 66

def expression
  @expression
end

Class Method Details

.parse(tag_name, parser) ⇒ IfBlock

(Parser) -> Markup

Parameters:

  • tag_name (String)
  • parser (Parser)

Returns:



71
72
73
74
75
76
77
78
79
80
# File 'lib/luoma/tags/if.rb', line 71

def self.parse(tag_name, parser)
  parser.eat(:token_tag_start)
  parser.skip_whitespace_control
  token = parser.eat(:token_tag_name)
  parser.expect_expression
  expression = parser.parse_expression
  parser.carry_whitespace_control
  parser.eat(:token_tag_end)
  IfBlock.new(token, tag_name, expression, parser.parse_block(stop: END_IF_BLOCK))
end

Instance Method Details

#children(static_context) ⇒ Array[Markup]

(RenderContext) -> Array

Parameters:

Returns:



96
97
98
# File 'lib/luoma/tags/if.rb', line 96

def children(static_context)
  @block.grep_v(String) #: Array[Markup]
end

#expressions::Array[Expression]

() -> Array

Returns:



101
102
103
# File 'lib/luoma/tags/if.rb', line 101

def expressions
  [@expression]
end

#filter_stringsvoid

This method returns an undefined value.



105
106
107
# File 'lib/luoma/tags/if.rb', line 105

def filter_strings
  @block.filter! { |node| !node.is_a?(String) }
end

#render(context, buffer) ⇒ Object

Signature:

  • (RenderContext, String) -> void



91
92
93
# File 'lib/luoma/tags/if.rb', line 91

def render(context, buffer)
  Luoma.render_block(@block, context, buffer)
end