Class: Bridgetown::Converters::ERBTemplates

Inherits:
Bridgetown::Converter show all
Defined in:
bridgetown-core/lib/bridgetown-core/converters/erb_templates.rb

Instance Method Summary collapse

Methods inherited from Bridgetown::Converter

#determine_template_engine, #initialize, input, #inspect, #line_start, #matches, #output_ext, support_slots, supports_slots?, template_engine

Methods inherited from Plugin

#initialize

Methods included from Prioritizable

#<=>, included

Constructor Details

This class inherits a constructor from Bridgetown::Converter

Instance Method Details

#convert(content, convertible) ⇒ String

Logic to do the ERB content conversion.

Parameters:

Returns:

  • (String)

    The converted content.



119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
# File 'bridgetown-core/lib/bridgetown-core/converters/erb_templates.rb', line 119

def convert(content, convertible)
  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