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

#initialize, input, #inspect, #line_start, support_slots, supports_slots?

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.



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

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

Parameters:



142
143
144
145
146
147
148
149
150
151
152
153
# File 'bridgetown-core/lib/bridgetown-core/converters/erb_templates.rb', line 142

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



155
156
157
# File 'bridgetown-core/lib/bridgetown-core/converters/erb_templates.rb', line 155

def output_ext(ext)
  ext == ".erb" ? ".html" : ext
end