Class: Bridgetown::Converter
- Defined in:
- 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
-
.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.
34 35 36 37 |
# File 'lib/bridgetown-core/converter.rb', line 34 def initialize(config = {}) super @config = config end |
Class Attribute Details
.extname_list ⇒ Object
Returns the value of attribute extname_list.
6 7 8 |
# File 'lib/bridgetown-core/converter.rb', line 6 def extname_list @extname_list end |
Class Method Details
.input(extnames) ⇒ Object
Converters can provide one or more extensions they accept. Examples:
input :erb
input %i(xls xlsx)
12 13 14 15 16 |
# File 'lib/bridgetown-core/converter.rb', line 12 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
20 21 22 |
# File 'lib/bridgetown-core/converter.rb', line 20 def support_slots(bool = true) # rubocop:disable Style/OptionalBooleanParameter @support_slots = bool == true end |
.supports_slots? ⇒ Boolean
18 |
# File 'lib/bridgetown-core/converter.rb', line 18 def supports_slots? = @support_slots |
.template_engine(name = nil) ⇒ Object
24 25 26 27 28 |
# File 'lib/bridgetown-core/converter.rb', line 24 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.
45 46 47 |
# File 'lib/bridgetown-core/converter.rb', line 45 def convert(content, convertible = nil) # rubocop:disable Lint/UnusedMethodArgument content end |
#determine_template_engine(convertible) ⇒ Object
60 61 62 63 64 65 |
# File 'lib/bridgetown-core/converter.rb', line 60 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
102 103 104 |
# File 'lib/bridgetown-core/converter.rb', line 102 def inspect "#<#{self.class}#{self.class.extname_list ? " #{self.class.extname_list.join(", ")}" : nil}>" end |
#line_start(convertible) ⇒ Object
rubocop:disable Metrics/PerceivedComplexity
82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 |
# File 'lib/bridgetown-core/converter.rb', line 82 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?
56 57 58 |
# File 'lib/bridgetown-core/converter.rb', line 56 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
74 75 76 77 78 79 80 |
# File 'lib/bridgetown-core/converter.rb', line 74 def output_ext(ext) if self.class.template_engine (self.class.extname_list || []).include?(ext.downcase) ? ".html" : ext else ".html" end end |