Class: Bridgetown::Converters::SlimTemplates

Inherits:
Converter
  • Object
show all
Defined in:
lib/bridgetown-slim/slim_templates.rb

Instance Method Summary collapse

Instance Method Details

#convert(content, convertible) ⇒ String

Logic to do the Slim content conversion.

Parameters:

  • content (String)

    Content of the file (without front matter).

Returns:

  • (String)

    The converted content.



32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
# File 'lib/bridgetown-slim/slim_templates.rb', line 32

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

  slim_view = Bridgetown::SlimView.new(convertible)

  slim_renderer = Slim::Template.new(convertible.relative_path) { content }

  if convertible.is_a?(Bridgetown::Layout)
    slim_renderer.render(slim_view) do
      convertible.current_document_output
    end
  else
    slim_renderer.render(slim_view)
  end
end

#matches(ext, convertible) ⇒ Object



48
49
50
51
52
53
54
# File 'lib/bridgetown-slim/slim_templates.rb', line 48

def matches(ext, convertible)
  return true if convertible.data[:template_engine] == "slim"

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

#output_ext(ext) ⇒ Object



56
57
58
# File 'lib/bridgetown-slim/slim_templates.rb', line 56

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