class Bridgetown::Converter
Attributes
extname_list[RW]
Public Class Methods
input(extnames)
click to toggle source
Converters
can provide one or more extensions they accept. Examples:
-
`input :erb`
-
`input %i(xls xlsx)`
# 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
new(config = {})
click to toggle source
Initialize the converter.
Returns an initialized Converter
.
# File lib/bridgetown-core/converter.rb, line 22 def initialize(config = {}) @config = config end
Public Instance Methods
convert(content, convertible = nil)
click to toggle source
Logic to do the content conversion.
@param content [String] content of file (without front matter). @param convertible [Bridgetown::Document, Bridgetown::Layout
, Bridgetown::Resource::Base]
@return [String] the converted content.
# File lib/bridgetown-core/converter.rb, line 32 def convert(content, convertible = nil) # rubocop:disable Lint/UnusedMethodArgument content end
inspect()
click to toggle source
# File lib/bridgetown-core/converter.rb, line 65 def inspect "#<#{self.class}#{self.class.extname_list ? " #{self.class.extname_list.join(", ")}" : nil}>" end
line_start(convertible)
click to toggle source
# File lib/bridgetown-core/converter.rb, line 56 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)
click to toggle source
Does the given extension match this converter's list of acceptable extensions?
@param [String] ext
The file's extension (including the dot)
@return [Boolean] Whether the extension matches one in the list
# File lib/bridgetown-core/converter.rb, line 42 def matches(ext) (self.class.extname_list || []).include?(ext.downcase) end
output_ext(_ext)
click to toggle source
You can override this in Converter
subclasses as needed. Default is “.html”
@param [String] ext
The extension of the original file
@return [String] The output file extension (including the dot)
# File lib/bridgetown-core/converter.rb, line 52 def output_ext(_ext) ".html" end