class Awestruct::Handlers::AsciidoctorHandler
Constants
- CHAIN
Public Class Methods
new(site, delegate)
click to toggle source
Calls superclass method
# File lib/awestruct/handlers/asciidoctor_handler.rb, line 37 def initialize(site, delegate) super( site, delegate ) @site = site @front_matter = front_matter end
Public Instance Methods
content_line_offset()
click to toggle source
# File lib/awestruct/handlers/asciidoctor_handler.rb, line 61 def content_line_offset parse_header() @delegate.content_line_offset if @delegate end
front_matter()
click to toggle source
# File lib/awestruct/handlers/asciidoctor_handler.rb, line 45 def front_matter @front_matter ||= {} parse_header() if @delegate @front_matter.update @delegate.front_matter # push front matter forward as well @delegate.front_matter.replace @front_matter @front_matter end end
inherit_front_matter(page)
click to toggle source
Calls superclass method
# File lib/awestruct/handlers/asciidoctor_handler.rb, line 120 def inherit_front_matter(page) parse_header() page.inherit_front_matter_from(front_matter) super end
options()
click to toggle source
Calls superclass method
# File lib/awestruct/handlers/asciidoctor_handler.rb, line 80 def options opts = super opts[:attributes] ||= {} opts[:attributes].update(@front_matter.inject({}) {|collector, (key,val)| collector["page-#{key}"] = "#{val}@" collector }) # Keep only values that can be coerced to as string types = [String, Numeric, TrueClass, FalseClass, Date, Time] opts[:attributes].update(@site.inject({}) {|collector, (key,val)| collector["site-#{key}"] = "#{val}@" if types.detect {|t| val.kind_of? t } collector }) opts[:attributes]['env'] = @site opts[:attributes]['env-site'] = true opts[:attributes]['awestruct-version'] = Awestruct::VERSION if @front_matter['header_footer'] opts[:header_footer] = true end path_expanded = File.expand_path path opts[:attributes]['docdir'] = File.dirname path_expanded opts[:attributes]['docfile'] = path_expanded opts[:attributes]['docname'] = simple_name path_mtime = path.mtime opts[:attributes]['docdate'] = docdate = path_mtime.strftime('%Y-%m-%d') opts[:attributes]['doctime'] = doctime = path_mtime.strftime('%H:%M:%S %Z') opts[:attributes]['docdatetime'] = %(#{docdate} #{doctime}) # TODO once Asciidoctor 1.5.0 is release, we should set the base_dir as a jail # we can't do this before 1.5.0 due to a bug in how includes are resolved if (Object.const_defined? 'Asciidoctor') && Asciidoctor::VERSION >= '1.5.0' opts[:base_dir] ||= @site.config.dir end opts end
parse_document_attributes(content)
click to toggle source
# File lib/awestruct/handlers/asciidoctor_handler.rb, line 136 def parse_document_attributes(content) template = ::Tilt::new(delegate.path.to_s, delegate.content_line_offset + 1, options) headers = template.parse_headers(content, /^(?:page|awestruct)\-(?=.)/).inject({'interpolate' => false}) do |hash, (k,v)| unless v.nil? hash[k] = v.empty? ? v : Awestruct.yaml_load(v) if hash[k].kind_of? Time # use DateTime to preserve timezone information hash[k] = DateTime.parse(v) end end hash end headers end
parse_header()
click to toggle source
# File lib/awestruct/handlers/asciidoctor_handler.rb, line 126 def parse_header return if @parsed_parts content = delegate.raw_content unless content.nil? @front_matter = parse_document_attributes(content) end @parsed_parts = true end
raw_content()
click to toggle source
# File lib/awestruct/handlers/asciidoctor_handler.rb, line 56 def raw_content parse_header() @delegate.raw_content if @delegate end
rendered_content(context, with_layouts)
click to toggle source
Calls superclass method
# File lib/awestruct/handlers/asciidoctor_handler.rb, line 66 def rendered_content(context, with_layouts) parse_header() front_matter_ref = front_matter types = [String, Numeric, TrueClass, FalseClass, Array] front_matter_ref.update(context.page.inject({}) {|hash, (k,v)| hash[k.to_s] = v if not k.to_s.start_with?('__') and types.detect { |t| v.kind_of? t } hash }) if with_layouts && !context.page.layout front_matter_ref['header_footer'] = true end super end