Sha256: 0674ebd0c9a96d80b469bd80a403d8ea7b018e57db666aabbf26541323e8ffe9
Contents?: true
Size: 1.95 KB
Versions: 18
Compression:
Stored size: 1.95 KB
Contents
# frozen_string_literal: true module Bridgetown class Converter < Plugin class << self attr_accessor :extname_list # Converters can provide one or more extensions they accept. Examples: # # * `input :erb` # * `input %i(xls xlsx)` def input(extnames) extnames = Array(extnames) self.extname_list ||= [] self.extname_list += extnames.map { |e| ".#{e.to_s.downcase}" } end end # Initialize the converter. # # Returns an initialized Converter. def initialize(config = {}) super @config = config end # 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. def convert(content, convertible = nil) # rubocop:disable Lint/UnusedMethodArgument content end # 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 def matches(ext) (self.class.extname_list || []).include?(ext.downcase) end # 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) def output_ext(_ext) ".html" end 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 def inspect "#<#{self.class}#{self.class.extname_list ? " #{self.class.extname_list.join(", ")}" : nil}>" end end end
Version data entries
18 entries across 18 versions & 1 rubygems