Class: Jekyll::Tags::JekyllPug_IncludeTag
- Inherits:
-
IncludeTag
- Object
- IncludeTag
- Jekyll::Tags::JekyllPug_IncludeTag
- Defined in:
- lib/jekyll-pug/include-tag.rb
Instance Method Summary collapse
-
#initialize(tag_name, markup, tokens) ⇒ JekyllPug_IncludeTag
constructor
A new instance of JekyllPug_IncludeTag.
- #locate_include_file(context, file, safe) ⇒ Object
- #render(context) ⇒ Object
-
#render_variable(context) ⇒ Object
Render the variable if required.
Constructor Details
#initialize(tag_name, markup, tokens) ⇒ JekyllPug_IncludeTag
Returns a new instance of JekyllPug_IncludeTag.
6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 |
# File 'lib/jekyll-pug/include-tag.rb', line 6 def initialize(tag_name, markup, tokens) super matched = markup.strip.match(VARIABLE_SYNTAX) if matched @file = matched["variable"].strip @params = matched["params"].strip else @file, @params = markup.strip.split(%r!\s+!, 2) end # If file does not have an extension... if @file !~ /\.\w+$/ # ...add a .pug # "navigation" -> "navigation.pug" @file = @file + ".pug" @isPug = true else @isPug = false end validate_params if @params @tag_name = tag_name end |
Instance Method Details
#locate_include_file(context, file, safe) ⇒ Object
39 40 41 42 43 44 45 46 47 48 |
# File 'lib/jekyll-pug/include-tag.rb', line 39 def locate_include_file(context, file, safe) includes_dirs = tag_includes_dirs(context) includes_dirs.each do |dir| path = File.join(dir.to_s, file.to_s) return path if valid_include_file?(path, dir.to_s, safe) end raise IOError, "Could not locate the included file '#{file}' in any of "\ "#{includes_dirs}. Ensure it exists in one of those directories and, "\ "if it is a symlink, does not point outside your site source." end |
#render(context) ⇒ Object
50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 |
# File 'lib/jekyll-pug/include-tag.rb', line 50 def render(context) site = context.registers[:site] file = render_variable(context) || @file validate_file_name(file) path = locate_include_file(context, file, site.safe) return unless path add_include_to_dependency(site, path, context) partial = load_cached_partial(path, context) context.stack do context["include"] = parse_params(context) if @params begin partial.render!(context) rescue Liquid::Error => e e.template_name = path e.markup_context = "included " if e.markup_context.nil? raise e end end end |
#render_variable(context) ⇒ Object
Render the variable if required
29 30 31 32 33 34 35 36 37 |
# File 'lib/jekyll-pug/include-tag.rb', line 29 def render_variable(context) if @file.match(VARIABLE_SYNTAX) partial = context.registers[:site] .liquid_renderer .file("(variable)") .parse(@file) partial.render!(context) end end |