Class: Sourcerer::Jekyll::Tags::EmbedTag
- Inherits:
-
Liquid::Tag
- Object
- Liquid::Tag
- Sourcerer::Jekyll::Tags::EmbedTag
- Defined in:
- lib/sourcerer/jekyll/liquid/tags.rb
Overview
A Liquid tag for embedding and rendering a file within a template.
It searches for the file in the configured include paths.
Instance Method Summary collapse
-
#initialize(tag_name, markup, tokens) ⇒ EmbedTag
constructor
A new instance of EmbedTag.
-
#render(context) ⇒ String
Renders the embedded file.
Constructor Details
#initialize(tag_name, markup, tokens) ⇒ EmbedTag
Returns a new instance of EmbedTag.
13 14 15 16 |
# File 'lib/sourcerer/jekyll/liquid/tags.rb', line 13 def initialize tag_name, markup, tokens super @partial_name = markup.strip end |
Instance Method Details
#render(context) ⇒ String
Renders the embedded file.
23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 |
# File 'lib/sourcerer/jekyll/liquid/tags.rb', line 23 def render context includes_paths = context.registers[:includes_load_paths] || [] found_path = includes_paths.find do |base| candidate = File.(@partial_name, base) File.exist?(candidate) end raise "Embed file not found: #{@partial_name}" unless found_path full_path = File.(@partial_name, found_path) source = File.read(full_path) partial = ::Liquid::Template.parse(source) partial.render!(context) end |