Class: Markup::TemplateTag
- Inherits:
-
Liquid::Block
- Object
- Liquid::Block
- Markup::TemplateTag
- Defined in:
- lib/markup/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_REGEX =
%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.
8 9 10 11 |
# File 'lib/markup/template_tag.rb', line 8 def initialize(tag_name, markup, ) super @name = markup.strip end |
Instance Method Details
#parse(tokens) ⇒ Object
13 14 15 16 17 18 19 20 |
# File 'lib/markup/template_tag.rb', line 13 def parse(tokens) @body = "" while (token = tokens.shift) break if token.strip == "{% endtemplate %}" @body << token end end |
#render(context) ⇒ Object
22 23 24 25 26 27 28 29 |
# File 'lib/markup/template_tag.rb', line 22 def render(context) unless @name =~ NAME_REGEX 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 |