Class: Bridgetown::Converters::LiquidTemplates
- Inherits:
-
Bridgetown::Converter
- Object
- Plugin
- Bridgetown::Converter
- Bridgetown::Converters::LiquidTemplates
- Defined in:
- bridgetown-core/lib/bridgetown-core/converters/liquid_templates.rb
Class Attribute Summary collapse
-
.cached_partials ⇒ Object
Returns the value of attribute cached_partials.
Instance Attribute Summary collapse
-
#document ⇒ Object
readonly
Returns the value of attribute document.
-
#layout ⇒ Object
readonly
Returns the value of attribute layout.
-
#site ⇒ Object
readonly
Returns the value of attribute site.
Instance Method Summary collapse
-
#configure_payload(content = nil) ⇒ void
Set page content to payload and assign paginator if document has one.
-
#convert(content, convertible) ⇒ String
Logic to do the Liquid content conversion.
-
#liquid_context ⇒ Object
-
#payload ⇒ Bridgetown::Drops::UnifiedPayloadDrop
Fetches the payload used in Liquid rendering, aka
site.site_payload.
Methods inherited from Bridgetown::Converter
#determine_template_engine, helper_delimiters, #initialize, input, #inspect, #line_start, #matches, #output_ext, support_slots, supports_slots?, template_engine
Methods inherited from Plugin
Methods included from Prioritizable
Constructor Details
This class inherits a constructor from Bridgetown::Converter
Class Attribute Details
.cached_partials ⇒ Object
Returns the value of attribute cached_partials.
14 15 16 |
# File 'bridgetown-core/lib/bridgetown-core/converters/liquid_templates.rb', line 14 def cached_partials @cached_partials end |
Instance Attribute Details
#document ⇒ Object (readonly)
Returns the value of attribute document.
11 12 13 |
# File 'bridgetown-core/lib/bridgetown-core/converters/liquid_templates.rb', line 11 def document @document end |
#layout ⇒ Object (readonly)
Returns the value of attribute layout.
11 12 13 |
# File 'bridgetown-core/lib/bridgetown-core/converters/liquid_templates.rb', line 11 def layout @layout end |
#site ⇒ Object (readonly)
Returns the value of attribute site.
11 12 13 |
# File 'bridgetown-core/lib/bridgetown-core/converters/liquid_templates.rb', line 11 def site @site end |
Instance Method Details
#configure_payload(content = nil) ⇒ void
This method returns an undefined value.
Set page content to payload and assign paginator if document has one.
68 69 70 71 72 73 74 |
# File 'bridgetown-core/lib/bridgetown-core/converters/liquid_templates.rb', line 68 def configure_payload(content = nil) payload["page"] = document.to_liquid payload["paginator"] = document.respond_to?(:paginator) ? document.paginator.to_liquid : nil payload["layout"] = @layout ? @layout.to_liquid.merge({ data: @layout.data }) : {} payload["content"] = content payload["data"] = payload["page"].data end |
#convert(content, convertible) ⇒ String
Logic to do the Liquid content conversion.
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 |
# File 'bridgetown-core/lib/bridgetown-core/converters/liquid_templates.rb', line 27 def convert(content, convertible) self.class.cached_partials ||= {} @payload = nil @site = convertible.site if convertible.is_a?(Bridgetown::Layout) @document = convertible.current_document @layout = convertible configure_payload(layout.current_document_output) else @document = convertible @layout = site.layouts[document.data["layout"]] configure_payload end template = site.liquid_renderer.file(convertible.path).parse(content) template.warnings.each do |e| Bridgetown.logger.warn "Liquid Warning:", LiquidRenderer.format_error(e, convertible.path) end template.render!(payload, liquid_context) # rubocop: disable Lint/RescueException rescue Exception => e Bridgetown.logger.error "Liquid Exception:", LiquidRenderer.format_error(e, convertible.path) raise e end |
#liquid_context ⇒ Object
76 77 78 79 80 81 82 83 84 85 86 |
# File 'bridgetown-core/lib/bridgetown-core/converters/liquid_templates.rb', line 76 def liquid_context { registers: { site:, page: payload["page"], cached_partials: self.class.cached_partials, }, strict_filters: site.config["liquid"]["strict_filters"], strict_variables: site.config["liquid"]["strict_variables"], } end |
#payload ⇒ Bridgetown::Drops::UnifiedPayloadDrop
Fetches the payload used in Liquid rendering, aka site.site_payload
61 62 63 |
# File 'bridgetown-core/lib/bridgetown-core/converters/liquid_templates.rb', line 61 def payload @payload ||= site.site_payload end |