Class: Bridgetown::Converter
- Defined in:
- bridgetown-core/lib/bridgetown-core/converter.rb
Direct Known Subclasses
Bridgetown::Converters::ERBTemplates, Bridgetown::Converters::Identity, Bridgetown::Converters::LiquidTemplates, Bridgetown::Converters::Markdown, Bridgetown::Converters::RubyTemplates, Bridgetown::Converters::SerbeaTemplates
Class Attribute Summary collapse
-
.extname_list ⇒ Object
Returns the value of attribute extname_list.
Class Method Summary collapse
-
.helper_delimiters(delimiters = nil) ⇒ Object
Set or return the delimiters used for helper calls in template code (e.g.
["<%=", "%>"]
for ERB). -
.input(extnames) ⇒ Object
Converters can provide one or more extensions they accept.
-
.support_slots(bool = true) ⇒ Object
rubocop:disable Style/OptionalBooleanParameter.
-
.supports_slots? ⇒ Boolean
-
.template_engine(name = nil) ⇒ Object
Instance Method Summary collapse
-
#convert(content, convertible = nil) ⇒ String
Logic to do the content conversion.
-
#determine_template_engine(convertible) ⇒ Object
-
#initialize(config = {}) ⇒ Converter
constructor
Initialize the converter.
-
#inspect ⇒ Object
-
#line_start(convertible) ⇒ Object
rubocop:disable Metrics/PerceivedComplexity.
-
#matches(ext, _convertible = nil) ⇒ Boolean
Does the given extension match this converter’s list of acceptable extensions?.
-
#output_ext(ext) ⇒ String
You can override this in Converter subclasses as needed.
Methods included from Prioritizable
Constructor Details
#initialize(config = {}) ⇒ Converter
Initialize the converter.
Returns an initialized Converter.
47 48 49 50 |
# File 'bridgetown-core/lib/bridgetown-core/converter.rb', line 47 def initialize(config = {}) super @config = config end |
Class Attribute Details
.extname_list ⇒ Object
Returns the value of attribute extname_list.
6 7 8 |
# File 'bridgetown-core/lib/bridgetown-core/converter.rb', line 6 def extname_list @extname_list end |
Class Method Details
.helper_delimiters(delimiters = nil) ⇒ Object
Set or return the delimiters used for helper calls in template code
(e.g. ["<%=", "%>"]
for ERB). This is purely informational for the framework’s benefit,
not used within a rendering pipeline.
25 26 27 28 29 |
# File 'bridgetown-core/lib/bridgetown-core/converter.rb', line 25 def helper_delimiters(delimiters = nil) return @helper_delimiters if delimiters.nil? @helper_delimiters = delimiters end |
.input(extnames) ⇒ Object
Converters can provide one or more extensions they accept. Examples:
input :erb
input %i(xls xlsx)
14 15 16 17 18 |
# File 'bridgetown-core/lib/bridgetown-core/converter.rb', line 14 def input(extnames) extnames = Array(extnames) self.extname_list ||= [] self.extname_list += extnames.map { |e| ".#{e.to_s.downcase}" } end |
.support_slots(bool = true) ⇒ Object
rubocop:disable Style/OptionalBooleanParameter
33 34 35 |
# File 'bridgetown-core/lib/bridgetown-core/converter.rb', line 33 def support_slots(bool = true) # rubocop:disable Style/OptionalBooleanParameter @support_slots = bool == true end |
.supports_slots? ⇒ Boolean
31 |
# File 'bridgetown-core/lib/bridgetown-core/converter.rb', line 31 def supports_slots? = @support_slots |
.template_engine(name = nil) ⇒ Object
37 38 39 40 41 |
# File 'bridgetown-core/lib/bridgetown-core/converter.rb', line 37 def template_engine(name = nil) return @template_engine unless name @template_engine = name.to_s end |
Instance Method Details
#convert(content, convertible = nil) ⇒ String
Logic to do the content conversion.
57 58 59 |
# File 'bridgetown-core/lib/bridgetown-core/converter.rb', line 57 def convert(content, convertible = nil) # rubocop:disable Lint/UnusedMethodArgument content end |
#determine_template_engine(convertible) ⇒ Object
70 71 72 73 74 75 |
# File 'bridgetown-core/lib/bridgetown-core/converter.rb', line 70 def determine_template_engine(convertible) template_engine = self.class.template_engine convertible_engine = convertible.data["template_engine"].to_s convertible_engine == template_engine || (convertible_engine == "" && @config["template_engine"].to_s == template_engine) end |
#inspect ⇒ Object
110 111 112 |
# File 'bridgetown-core/lib/bridgetown-core/converter.rb', line 110 def inspect "#<#{self.class}#{self.class.extname_list ? " #{self.class.extname_list.join(", ")}" : nil}>" end |
#line_start(convertible) ⇒ Object
rubocop:disable Metrics/PerceivedComplexity
90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 |
# File 'bridgetown-core/lib/bridgetown-core/converter.rb', line 90 def line_start(convertible) # rubocop:disable Metrics/PerceivedComplexity if convertible.is_a?(Bridgetown::Resource::Base) && convertible.model.origin.respond_to?(:front_matter_line_count) if convertible.model.origin.front_matter_line_count.nil? 1 else convertible.model.origin.front_matter_line_count + 4 end elsif convertible.is_a?(Bridgetown::GeneratedPage) && convertible.original_resource res = convertible.original_resource if res.model.origin.respond_to?(:front_matter_line_count) res.model.origin.front_matter_line_count + 4 else 1 end else 1 end end |
#matches(ext, _convertible = nil) ⇒ Boolean
Does the given extension match this converter’s list of acceptable extensions?
66 67 68 |
# File 'bridgetown-core/lib/bridgetown-core/converter.rb', line 66 def matches(ext, _convertible = nil) (self.class.extname_list || []).include?(ext.downcase) end |
#output_ext(ext) ⇒ String
You can override this in Converter subclasses as needed. Default is “.html”, unless the converter is a template engine and the input file doesn’t match the normal template extension
82 83 84 85 86 87 88 |
# File 'bridgetown-core/lib/bridgetown-core/converter.rb', line 82 def output_ext(ext) if self.class.template_engine (self.class.extname_list || []).include?(ext.downcase) ? ".html" : ext else ".html" end end |