Class: Luoma::IncludeTag
- Defined in:
- lib/luoma/tags/include.rb,
sig/luoma/tags/include.rbs
Instance Attribute Summary
Attributes inherited from Markup
Class Method Summary collapse
-
.parse(token, tag_name, parser) ⇒ Markup
(t_token, String, Parser) -> Markup.
Instance Method Summary collapse
- #expressions ⇒ Object
-
#initialize(token, tag_name, template_name, args) ⇒ IncludeTag
constructor
(t_token, String, Expression, Array) -> void.
- #partial(static_context) ⇒ Object
- #render(context, buffer) ⇒ Object
Methods inherited from Markup
#block_scope, #children, #template_scope
Constructor Details
#initialize(token, tag_name, template_name, args) ⇒ IncludeTag
(t_token, String, Expression, Array) -> void
19 20 21 22 23 24 |
# File 'lib/luoma/tags/include.rb', line 19 def initialize(token, tag_name, template_name, args) super(token) @tag_name = tag_name @template_name = template_name @args = args end |
Class Method Details
.parse(token, tag_name, parser) ⇒ Markup
(t_token, String, Parser) -> Markup
6 7 8 9 10 11 12 13 14 15 16 |
# File 'lib/luoma/tags/include.rb', line 6 def self.parse(token, tag_name, parser) name_expr = parser.parse_expression # Leading commas are OK parser.next if parser.kind == :token_comma args = parser.parse_keyword_arguments(require_commas: true) parser.carry_whitespace_control parser.eat(:token_tag_end) new(token, tag_name, name_expr, args) end |
Instance Method Details
#expressions ⇒ Object
53 54 55 |
# File 'lib/luoma/tags/include.rb', line 53 def expressions @args.map(&:expression) end |
#partial(static_context) ⇒ Object
58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 |
# File 'lib/luoma/tags/include.rb', line 58 def partial(static_context) name = static_context.env.to_string(@template_name.evaluate(static_context), static_context) template = static_context.env.get_template( name, context: static_context, tag: "include" ) scope = @args.map(&:name) Partial.new( template, :shared, scope, Luoma.fnv1a32("#{name}-#{scope.map(&:value).join(":")}") ) end |
#render(context, buffer) ⇒ Object
27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 |
# File 'lib/luoma/tags/include.rb', line 27 def render(context, buffer) name = context.env.to_string(@template_name.evaluate(context), context) begin template = context.env.get_template( name, context: context, tag: "include" ) rescue TemplateNotFoundError => e raise NoSuchTemplateError.new( e., @template_name.span, context.template.source, context.template.name ) end scope = @args.to_h { |arg| [arg.name.value, arg.expression.evaluate(context)] } context.extends(scope, template: template) do template.render_with_context(context, buffer, isolated: false) end end |