Class: TRMNL::Liquid::TemplateTag
- Inherits:
-
Liquid::Block
- Object
- Liquid::Block
- TRMNL::Liquid::TemplateTag
- Defined in:
- lib/trmnl/liquid/template_tag.rb
Overview
The template [name] % tag block is used in conjunction with InlineTemplatesFileSystem to allow users to define custom templates within the context of the current Liquid template. Generally speaking, they will define their own templates in the "shared" markup content, which is prepended to the individual screen templates before rendering.
Constant Summary collapse
- NAME_PATTERN =
%r(\A[a-zA-Z0-9_/]+\z)
Instance Method Summary collapse
-
#initialize(tag_name, markup, options) ⇒ TemplateTag
constructor
A new instance of TemplateTag.
- #parse(tokens) ⇒ Object
- #render(context) ⇒ Object
Constructor Details
#initialize(tag_name, markup, options) ⇒ TemplateTag
Returns a new instance of TemplateTag.
12 13 14 15 16 17 |
# File 'lib/trmnl/liquid/template_tag.rb', line 12 def initialize tag_name, markup, super @name = markup.strip @body = +"" end |
Instance Method Details
#parse(tokens) ⇒ Object
19 20 21 22 23 24 25 26 27 |
# File 'lib/trmnl/liquid/template_tag.rb', line 19 def parse tokens body.clear while (token = tokens.shift) break if token.strip == "{% endtemplate %}" body << token end end |
#render(context) ⇒ Object
29 30 31 32 33 34 35 36 37 |
# File 'lib/trmnl/liquid/template_tag.rb', line 29 def render context unless NAME_PATTERN.match? name return "Liquid error: invalid template name #{name.inspect} - template names " \ "must contain only letters, numbers, underscores, and slashes" end context.registers[:file_system].register name, body.strip "" end |