Class: Luoma::WhenBlock

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

Constant Summary collapse

END_CASE_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, right, block) ⇒ WhenBlock

(t_token, String, Array, t_block) -> void

Parameters:

  • token (t_token)
  • tag_name (String)
  • right (Array[Expression])
  • block (t_block)


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

#blockt_block (readonly)

Returns the value of attribute block.

Returns:

  • (t_block)


74
75
76
# File 'lib/luoma/tags/case.rb', line 74

def block
  @block
end

#rightArray[Expression] (readonly)

Returns the value of attribute right.

Returns:



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

Parameters:

  • tag_name (String)
  • parser (Parser)

Returns:



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

Signature:

  • (RenderContext) -> Array[Markup]



124
125
126
# File 'lib/luoma/tags/case.rb', line 124

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

#expressionsObject

Signature:

  • () -> Array[Expression]



129
130
131
# File 'lib/luoma/tags/case.rb', line 129

def expressions
  @right
end

#filter_stringsvoid

This method returns an undefined value.

Signature:

  • () -> void



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

Signature:

  • (RenderContext, String) -> void



119
120
121
# File 'lib/luoma/tags/case.rb', line 119

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