Class: Luoma::WhenBlock
- Defined in:
- lib/luoma/tags/case.rb,
sig/luoma/tags/case.rbs
Constant Summary collapse
- END_CASE_BLOCK =
Instance Attribute Summary collapse
-
#block ⇒ t_block
readonly
Returns the value of attribute block.
-
#right ⇒ Array[Expression]
readonly
Returns the value of attribute right.
Attributes inherited from Markup
Class Method Summary collapse
-
.parse(tag_name, parser) ⇒ WhenBlock
(String, Parser) -> WhenBlock.
Instance Method Summary collapse
- #children(static_context) ⇒ Object
- #expressions ⇒ Object
- #filter_strings ⇒ void
-
#initialize(token, tag_name, right, block) ⇒ WhenBlock
constructor
(t_token, String, Array, t_block) -> void.
- #render(context, buffer) ⇒ Object
Methods inherited from Markup
#block_scope, #partial, #template_scope
Constructor Details
#initialize(token, tag_name, right, block) ⇒ WhenBlock
(t_token, String, Array, t_block) -> void
110 111 112 113 114 115 116 |
# File 'lib/luoma/tags/case.rb', line 110 def initialize(token, tag_name, right, block) super(token) @tag_name = tag_name @right = right @block = block @blank = Luoma.blank_block?(block) end |
Instance Attribute Details
#block ⇒ t_block (readonly)
Returns the value of attribute block.
74 75 76 |
# File 'lib/luoma/tags/case.rb', line 74 def block @block end |
#right ⇒ Array[Expression] (readonly)
Returns the value of attribute right.
74 75 76 |
# File 'lib/luoma/tags/case.rb', line 74 def right @right end |
Class Method Details
.parse(tag_name, parser) ⇒ WhenBlock
(String, Parser) -> WhenBlock
79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 |
# File 'lib/luoma/tags/case.rb', line 79 def self.parse(tag_name, parser) parser.eat(:token_tag_start) parser.skip_whitespace_control token = parser.eat(:token_tag_name) right = [] #: Array[Expression] loop do expr = parser.parse_expression right << if parser.kind == :token_question && expr.is_a?(Variable) && expr.segments.empty? && expr.root.is_a?(Name) parser.next Predicate.new(expr.token, expr.root.value) else expr end break unless parser.kind == :token_comma parser.next end parser.carry_whitespace_control parser.eat(:token_tag_end) block = parser.parse_block(stop: END_CASE_BLOCK) new(token, tag_name, right, block) end |
Instance Method Details
#children(static_context) ⇒ Object
124 125 126 |
# File 'lib/luoma/tags/case.rb', line 124 def children(static_context) @block.grep_v(String) #: Array[Markup] end |
#expressions ⇒ Object
129 130 131 |
# File 'lib/luoma/tags/case.rb', line 129 def expressions @right end |
#filter_strings ⇒ void
This method returns an undefined value.
34 35 36 |
# File 'sig/luoma/tags/case.rbs', line 34 def filter_strings @block.filter! { |node| !node.is_a?(String) } end |
#render(context, buffer) ⇒ Object
119 120 121 |
# File 'lib/luoma/tags/case.rb', line 119 def render(context, buffer) Luoma.render_block(@block, context, buffer) end |