Class: Luoma::AssignTag

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

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, #children, #partial

Constructor Details

#initialize(token, tag_name, bindings) ⇒ AssignTag

(t_token, Array) -> void

Parameters:

  • token (t_token)
  • tag_name (String)
  • (Array[Item])


39
40
41
42
43
44
# File 'lib/luoma/tags/assign.rb', line 39

def initialize(token, tag_name, bindings)
  super(token)
  @blank = true
  @tag_name = tag_name
  @bindings = bindings
end

Instance Attribute Details

#bindingsObject (readonly)

Returns the value of attribute bindings.



5
6
7
# File 'lib/luoma/tags/assign.rb', line 5

def bindings
  @bindings
end

Class Method Details

.parse(token, tag_name, parser) ⇒ Markup

(t_token, String, Parser) -> Markup

Parameters:

  • token (t_token)
  • tag_name (String)
  • parser (Parser)

Returns:



8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
# File 'lib/luoma/tags/assign.rb', line 8

def self.parse(token, tag_name, parser)
  bindings = [] #: Array[Item]

  name = parser.parse_ident
  assign_token = parser.eat(
    :token_assign,
    message: "bad identifier or missing assignment operator"
  )

  bindings << Item.new(assign_token, name, parser.parse_expression)

  until parser.kind != :token_comma
    parser.next
    name = parser.parse_ident
    assign_token = parser.eat(
      :token_assign,
      message: "bad identifier or missing assignment operator"
    )

    bindings << Item.new(assign_token, name, parser.parse_expression)
  end

  parser.carry_whitespace_control
  parser.eat(
    :token_tag_end,
    message: "bad expression or missing markup delimiter"
  )
  new(token, tag_name, bindings)
end

Instance Method Details

#expressionsObject

Signature:

  • () -> Array[Expression]



54
55
56
# File 'lib/luoma/tags/assign.rb', line 54

def expressions
  @bindings.map(&:expr)
end

#render(context, buffer) ⇒ Object

Signature:

  • (RenderContext, String) -> void



47
48
49
50
51
# File 'lib/luoma/tags/assign.rb', line 47

def render(context, buffer)
  @bindings.each do |binding|
    context.assign(binding.key.value, binding.expr.evaluate(context))
  end
end

#template_scopeObject

Signature:

  • () -> Array[Name]



59
60
61
# File 'lib/luoma/tags/assign.rb', line 59

def template_scope
  @bindings.map(&:key)
end