lib/awestruct/handlers/asciidoctor_handler.rb in awestruct-0.5.4.rc3 vs lib/awestruct/handlers/asciidoctor_handler.rb in awestruct-0.5.4

- old
+ new

@@ -13,27 +13,15 @@ class AsciidoctorTiltMatcher < TiltMatcher # Use a lightweight lookup to avoid loading Tilt templates for # non-matching paths. Once we are sure this is a match, then # attempt to load the Tilt template for AsciiDoc files. def match(path) - # formal lookup as implemented in Tilt - pattern = File.basename(path.downcase) - registered = false - until pattern.empty? || (registered = Tilt.registered?(pattern)) - # shave pattern down to next extension - pattern = pattern.sub(/^[^.]*\.?/, '') + extensions = ['ad', 'adoc', 'asciidoc'] + if (extensions.include? File.extname(path)[1..-1]) + return true end - if registered && (Tilt.mappings[pattern] || []).include?(Tilt::AsciidoctorTemplate) - begin - Tilt[File.basename(path)] - rescue LoadError - # swallowing error as it will be picked up again by primary TiltHandler - false - end - else - false - end + false end end class AsciidoctorHandler < BaseTiltHandler @@ -47,15 +35,16 @@ def initialize(site, delegate) super( site, delegate ) @site = site - @front_matter = {} + @front_matter = front_matter end 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 @@ -141,26 +130,24 @@ end @parsed_parts = true end def parse_document_attributes(content) - warned = false - template = Tilt::new(delegate.path.to_s, delegate.content_line_offset + 1, options) - template.parse_headers(content, /^(?:page|awestruct)\-(?=.)/).inject({'interpolate' => false}) do |hash, (k,v)| + 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 : 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 end end end -require 'awestruct/handlers/template/asciidoc' -Tilt::register Tilt::AsciidoctorTemplate, '.ad', '.adoc', '.asciidoc'