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
Instance Method Summary collapse
-
#convert(content, convertible = nil) ⇒ String
Logic to do the content conversion.
-
#initialize(config = {}) ⇒ Converter
constructor
Initialize the converter.
- #inspect ⇒ Object
- #line_start(convertible) ⇒ Object
-
#matches(ext) ⇒ 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.
30 31 32 33 |
# File 'lib/bridgetown-core/converter.rb', line 30 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
22 23 24 |
# File 'lib/bridgetown-core/converter.rb', line 22 def support_slots(bool = true) # rubocop:disable Style/OptionalBooleanParameter @support_slots = bool == true end |
.supports_slots? ⇒ Boolean
18 19 20 |
# File 'lib/bridgetown-core/converter.rb', line 18 def supports_slots? @support_slots == true end |
Instance Method Details
#convert(content, convertible = nil) ⇒ String
Logic to do the content conversion.
41 42 43 |
# File 'lib/bridgetown-core/converter.rb', line 41 def convert(content, convertible = nil) # rubocop:disable Lint/UnusedMethodArgument content end |
#inspect ⇒ Object
74 75 76 |
# File 'lib/bridgetown-core/converter.rb', line 74 def inspect "#<#{self.class}#{self.class.extname_list ? " #{self.class.extname_list.join(", ")}" : nil}>" end |
#line_start(convertible) ⇒ Object
65 66 67 68 69 70 71 72 |
# File 'lib/bridgetown-core/converter.rb', line 65 def line_start(convertible) if convertible.is_a?(Bridgetown::Resource::Base) && convertible.model.origin.respond_to?(:front_matter_line_count) convertible.model.origin.front_matter_line_count + 4 else 1 end end |
#matches(ext) ⇒ Boolean
Does the given extension match this converter's list of acceptable extensions?
51 52 53 |
# File 'lib/bridgetown-core/converter.rb', line 51 def matches(ext) (self.class.extname_list || []).include?(ext.downcase) end |
#output_ext(_ext) ⇒ String
You can override this in Converter subclasses as needed. Default is ".html"
61 62 63 |
# File 'lib/bridgetown-core/converter.rb', line 61 def output_ext(_ext) ".html" end |