Class: Luoma::WithTag

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

Constant Summary collapse

END_WITH_BLOCK =

Returns:

  • (Set[String])
Set["endwith"]

Instance Attribute Summary

Attributes inherited from Markup

#blank, #tag_name, #token

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from Markup

#partial, #template_scope

Constructor Details

#initialize(token, tag_name, args, block) ⇒ WithTag

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

Parameters:

  • token (t_token)
  • tag_name (String)
  • args (Array[KeywordArgument])
  • block (t_block)


18
19
20
21
22
23
24
# File 'lib/luoma/tags/with.rb', line 18

def initialize(token, tag_name, args, block)
  super(token)
  @tag_name = tag_name
  @args = args
  @block = block
  @blank = Luoma.blank_block?(block)
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
# File 'lib/luoma/tags/with.rb', line 8

def self.parse(token, tag_name, parser)
  args = parser.parse_keyword_arguments(require_commas: true)
  parser.carry_whitespace_control
  parser.eat(:token_tag_end)
  block = parser.parse_block(stop: END_WITH_BLOCK)
  parser.eat_empty_tag("endwith")
  new(token, tag_name, args, block)
end

Instance Method Details

#block_scopeObject

Signature:

  • () -> Array[Name]



51
52
53
# File 'lib/luoma/tags/with.rb', line 51

def block_scope
  @args.map(&:name)
end

#children(static_context) ⇒ Object

Signature:

  • (RenderContext) -> Array[Markup]



41
42
43
# File 'lib/luoma/tags/with.rb', line 41

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

#expressionsObject

Signature:

  • () -> Array[Expression]



46
47
48
# File 'lib/luoma/tags/with.rb', line 46

def expressions
  @args.map(&:expression)
end

#render(context, buffer) ⇒ Object

Signature:

  • (RenderContext, String) -> void



27
28
29
30
31
32
33
34
35
36
37
38
# File 'lib/luoma/tags/with.rb', line 27

def render(context, buffer)
  scope = {} #: t_namespace

  context.extends(scope) do
    # NOTE: Later arguments can use earlier arguments.
    @args.each do |arg|
      scope[arg.name.value] = arg.expression.evaluate(context)
    end

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