Class: JekyllBookshop::CommonTag
- Inherits:
-
Jekyll::Tags::IncludeTag
- Object
- Jekyll::Tags::IncludeTag
- JekyllBookshop::CommonTag
- Defined in:
- lib/jekyll-bookshop/tags/bookshop-common-tag.rb
Direct Known Subclasses
Instance Method Summary collapse
-
#parse_params(context) ⇒ Object
Support the bind syntax, spreading an object into params.
- #render_once_found(context, file) ⇒ Object
Instance Method Details
#parse_params(context) ⇒ Object
Support the bind syntax, spreading an object into params
6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 |
# File 'lib/jekyll-bookshop/tags/bookshop-common-tag.rb', line 6 def parse_params(context) params = super params.each do |key, value| next unless key == "bind" && value.is_a?(Hash) value_hash = {}.merge(value) params = value_hash.merge(params) next end params.delete("bind") params end |
#render_once_found(context, file) ⇒ Object
22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 |
# File 'lib/jekyll-bookshop/tags/bookshop-common-tag.rb', line 22 def render_once_found(context, file) site = context.registers[:site] validate_file_name(file) begin path = locate_include_file(context, file, site.safe) rescue IOError return false end return false unless path add_include_to_dependency(site, path, context) partial = load_cached_partial(path, context) loop_context = "" if context.scopes[0]["forloop"] name = context.scopes[0]["forloop"].name index = context.scopes[0]["forloop"].index0 loop_context = "#{name}[#{index}]" end # If this component is not a subcomponent, # we also drop in some site metadata here so that it can be used in the render. version = "3.12.0" = context["__bookshop__nested"] ? "" : "<!--bookshop-live meta(version=\"#{version}\" baseurl=\"#{site.baseurl}\" title=\"#{site.config["title"]&.gsub('"', '\"') || ""}\") -->\n" context.stack do context["include"] = parse_params(context) if @params context["__bookshop__nested"] = true begin "#{}<!--bookshop-live name(#{file}) params(#{@params}) context(#{loop_context.gsub(/-/, '=').gsub(/=include\./, '=')}) --> #{partial.render!(context)} <!--bookshop-live end-->" rescue Liquid::Error => e e.template_name = path e.markup_context = "included " if e.markup_context.nil? raise e end end end |