Class: Bridgetown::Converters::ERBTemplates
- Inherits:
-
Bridgetown::Converter
- Object
- Plugin
- Bridgetown::Converter
- Bridgetown::Converters::ERBTemplates
- Defined in:
- lib/bridgetown-core/converters/erb_templates.rb
Instance Method Summary collapse
-
#convert(content, convertible) ⇒ String
Logic to do the ERB content conversion.
- #matches(ext, convertible) ⇒ Object
- #output_ext(ext) ⇒ Object
Methods inherited from Bridgetown::Converter
#initialize, input, #inspect, #line_start, support_slots, supports_slots?
Methods inherited from Plugin
Methods included from Prioritizable
Constructor Details
This class inherits a constructor from Bridgetown::Converter
Instance Method Details
#convert(content, convertible) ⇒ String
Logic to do the ERB content conversion.
115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 |
# File 'lib/bridgetown-core/converters/erb_templates.rb', line 115 def convert(content, convertible) return content if convertible.data[:template_engine].to_s != "erb" erb_view = Bridgetown::ERBView.new(convertible) erb_renderer = Tilt::ErubiTemplate.new( convertible.path, line_start(convertible), outvar: "@_erbout", bufval: "Bridgetown::OutputBuffer.new", engine_class: ERBEngine ) { content } if convertible.is_a?(Bridgetown::Layout) erb_renderer.render(erb_view) do convertible.current_document_output.html_safe end else erb_renderer.render(erb_view) end end |
#matches(ext, convertible) ⇒ Object
139 140 141 142 143 144 145 146 147 148 149 150 |
# File 'lib/bridgetown-core/converters/erb_templates.rb', line 139 def matches(ext, convertible) if convertible.data[:template_engine].to_s == "erb" || (convertible.data[:template_engine].nil? && @config[:template_engine].to_s == "erb") convertible.data[:template_engine] = "erb" return true end super(ext).tap do |ext_matches| convertible.data[:template_engine] = "erb" if ext_matches end end |
#output_ext(ext) ⇒ Object
152 153 154 |
# File 'lib/bridgetown-core/converters/erb_templates.rb', line 152 def output_ext(ext) ext == ".erb" ? ".html" : ext end |