Class: Luoma::RenderTag
- Defined in:
- lib/luoma/tags/render.rb,
sig/luoma/tags/render.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) ⇒ RenderTag
constructor
(t_token, String, Name, Array) -> void.
- #partial(static_context) ⇒ Object
- #render(context, buffer) ⇒ Object
Methods inherited from Markup
#block_scope, #children, #template_scope
Constructor Details
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 17 18 19 20 21 22 23 24 25 26 27 28 |
# File 'lib/luoma/tags/render.rb', line 6 def self.parse(token, tag_name, parser) name_expr = parser.parse_string_literal name_value = name_expr.value unless name_value raise TemplateSyntaxError.new( "expected a string literal", name_expr.span, parser.source, parser.template_name ) end name = Name.new(name_expr.token, name_value) # 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, args) end |
Instance Method Details
#expressions ⇒ Object
68 69 70 |
# File 'lib/luoma/tags/render.rb', line 68 def expressions @args.map(&:expression) end |
#partial(static_context) ⇒ Object
73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 |
# File 'lib/luoma/tags/render.rb', line 73 def partial(static_context) name = @template_name.value template = static_context.env.get_template( name, context: static_context, tag: "render" ) scope = @args.map(&:name) Partial.new( template, :isolated, scope, Luoma.fnv1a32("#{name}-#{scope.map(&:value).join(":")}") ) end |
#render(context, buffer) ⇒ Object
39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 |
# File 'lib/luoma/tags/render.rb', line 39 def render(context, buffer) name = @template_name.value begin template = context.env.get_template( name, context: context, tag: "render" ) rescue TemplateNotFoundError => e raise NoSuchTemplateError.new( e., @template_name.span, context.template.source, context.template.name ) end ctx = context.copy( @args.to_h { |arg| [arg.name.value, arg.expression.evaluate(context)] }, block_scope: false, template: template ) template.render_with_context(ctx, buffer) context.render_score_cumulative += ctx.render_score end |