class Awestruct::Handlers::FrontMatterHandler
Public Class Methods
new(site, delegate)
click to toggle source
Calls superclass method
Awestruct::Handlers::BaseHandler::new
# File lib/awestruct/handlers/front_matter_handler.rb, line 9 def initialize(site, delegate) super @parsed_parts = false end
Public Instance Methods
content_line_offset()
click to toggle source
# File lib/awestruct/handlers/front_matter_handler.rb, line 29 def content_line_offset parse_parts() @content_line_offset end
front_matter()
click to toggle source
# File lib/awestruct/handlers/front_matter_handler.rb, line 14 def front_matter parse_parts() @front_matter end
inherit_front_matter(page)
click to toggle source
Calls superclass method
Awestruct::Handlers::BaseHandler#inherit_front_matter
# File lib/awestruct/handlers/front_matter_handler.rb, line 34 def inherit_front_matter(page) page.inherit_front_matter_from( front_matter ) super end
raw_content()
click to toggle source
# File lib/awestruct/handlers/front_matter_handler.rb, line 19 def raw_content parse_parts() @raw_content end
rendered_content(context, with_layouts)
click to toggle source
# File lib/awestruct/handlers/front_matter_handler.rb, line 24 def rendered_content(context, with_layouts) parse_parts() @raw_content end
Private Instance Methods
parse_parts()
click to toggle source
# File lib/awestruct/handlers/front_matter_handler.rb, line 41 def parse_parts return if ( @parsed_parts && ! delegate.stale? ) full_content = delegate.raw_content #if force_encoding is supported then set to charset defined in site config full_content.force_encoding(site.encoding) if (site.encoding && full_content.respond_to?(:force_encoding)) yaml_content = '' dash_lines = 0 mode = :yaml @raw_content = nil @content_line_offset = 0 first_line = true full_content.each_line do |line| if line.rstrip == '---' && mode == :yaml unless first_line @content_line_offset += 1 yaml_content << line mode = :page next end elsif first_line mode = :page end if mode == :yaml @content_line_offset += 1 yaml_content << line elsif @raw_content.nil? @raw_content = line else @raw_content << line end first_line = false end if mode == :yaml @raw_content = nil @content_line_offset = -1 end begin @front_matter = yaml_content.empty? ? {} : (Awestruct.yaml_load(yaml_content) || {}) rescue => e ExceptionHelper.log_message "could not parse #{relative_source_path}" ExceptionHelper.mark_failed raise e end @parsed_parts = true end