class Bridgetown::Layout
Attributes
Gets/Sets the content of this layout. @return [String]
Gets/Sets the current document (for layout-compatible converters)
Gets/Sets the document output (for layout-compatible converters)
Gets/Sets the Hash that holds the metadata for this layout.
Gets/Sets the extension of this layout.
Gets/Sets the extension of this layout.
@return [Integer]
Gets the name of this layout.
Gets the path to this layout.
Gets the path to this layout relative to its base
Gets the Site
object.
Public Class Methods
Determines the label a layout should use based on its filename
@param file [String] @return [String]
# File lib/bridgetown-core/layout.rb, line 46 def self.label_for_file(file) # TODO: refactor this so multi-extension layout filenames don't leak # middle extensions into layout label file.split(".")[0..-2].join(".") end
Initialize a new Layout
.
@param site [Bridgetown::Site] @param base [String] The path to the source. @param name [String] The filename of the layout file. @param from_plugin [Boolean] if the layout comes from a Gem-based plugin folder.
# File lib/bridgetown-core/layout.rb, line 58 def initialize(site, base, name, from_plugin: false) @site = site @base = base @name = name if from_plugin @base_dir = base.sub("/layouts", "") @path = File.join(base, name) else @base_dir = site.source @path = site.in_source_dir(base, name) end @relative_path = @path.sub(@base_dir, "") @ext = File.extname(name) @data = read_front_matter(@path)&.with_dot_access rescue SyntaxError => e Bridgetown.logger.error "Error:", "Ruby Exception in #{e.message}" rescue StandardError => e handle_read_error(e) ensure @data ||= HashWithDotAccess::Hash.new end
Public Instance Methods
# File lib/bridgetown-core/layout.rb, line 83 def handle_read_error(error) if error.is_a? Psych::SyntaxError Bridgetown.logger.warn "YAML Exception reading #{@path}: #{error.message}" else Bridgetown.logger.warn "Error reading file #{@path}: #{error.message}" end if site.config["strict_front_matter"] || error.is_a?(Bridgetown::Errors::FatalException) raise error end end
The inspect string for this layout. Includes the relative path.
@return [String]
# File lib/bridgetown-core/layout.rb, line 107 def inspect "#<#{self.class} #{relative_path}>" end
The label of the layout (should match what would used in front matter references).
@return [String]
# File lib/bridgetown-core/layout.rb, line 100 def label @label ||= self.class.label_for_file(name) end
Provide this Layout's data for use by Liquid.
@return [HashWithDotAccess::Hash]
# File lib/bridgetown-core/layout.rb, line 114 def to_liquid data end