Class: Bridgetown::Converters::SerbeaTemplates

Inherits:
Bridgetown::Converter show all
Defined in:
lib/bridgetown-core/converters/serbea_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 Serbea content conversion.

Parameters:

Returns:

  • (String)

    The converted content.



31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
# File 'lib/bridgetown-core/converters/serbea_templates.rb', line 31

def convert(content, convertible)
  return content if convertible.data[:template_engine].to_s != "serbea"

  serb_view = Bridgetown::SerbeaView.new(convertible)

  serb_renderer = Tilt::SerbeaTemplate.new(convertible.path) { content }

  if convertible.is_a?(Bridgetown::Layout)
    serb_renderer.render(serb_view) do
      convertible.current_document_output
    end
  else
    serb_renderer.render(serb_view)
  end
end

#matches(ext, convertible) ⇒ Object



47
48
49
50
51
52
53
54
55
56
57
58
# File 'lib/bridgetown-core/converters/serbea_templates.rb', line 47

def matches(ext, convertible)
  if convertible.data[:template_engine].to_s == "serbea" ||
      (convertible.data[:template_engine].nil? &&
        @config[:template_engine].to_s == "serbea")
    convertible.data[:template_engine] = "serbea"
    return true
  end

  super(ext).tap do |ext_matches|
    convertible.data[:template_engine] = "serbea" if ext_matches
  end
end

#output_ext(ext) ⇒ Object



60
61
62
# File 'lib/bridgetown-core/converters/serbea_templates.rb', line 60

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