From 21191966e76753c9785af7093580ef4ff05d9f6d Mon Sep 17 00:00:00 2001 From: Dan Allen Date: Sat, 28 May 2016 01:29:59 -0600 Subject: [PATCH] resolves #63 allow layout to be disabled - false disables layout, enables standalone output - nil disables layout, does not enable standalone output - not specified or empty string uses default (inherited) layout --- lib/jekyll-asciidoc.rb | 30 ++++++++++++++++++++++++++---- 1 file changed, 26 insertions(+), 4 deletions(-) diff --git a/lib/jekyll-asciidoc.rb b/lib/jekyll-asciidoc.rb index 2eb28a3..450515c 100644 --- a/lib/jekyll-asciidoc.rb +++ b/lib/jekyll-asciidoc.rb @@ -15,6 +15,7 @@ class AsciiDocConverter < Converter env=site env-site site-gen=jekyll site-gen-jekyll builder=jekyll builder-jekyll jekyll-version=#{Jekyll::VERSION} ) HEADER_BOUNDARY_RE = /(?<=\p{Graph})\n\n/ + STANDALONE_HEADER = %([%standalone]\n) safe true @@ -67,7 +68,7 @@ def setup raise FatalException.new("Invalid AsciiDoc processor: #{@config['asciidoc']}") end end - + def matches(ext) ext =~ @config['asciidoc_ext_re'] end @@ -79,9 +80,12 @@ def output_ext(ext) def convert(content) return content if content.empty? setup + if (standalone = content.start_with?(STANDALONE_HEADER)) + content = content[STANDALONE_HEADER.length..-1] + end case @config['asciidoc'] when 'asciidoctor' - Asciidoctor.convert(content, @config['asciidoctor']) + Asciidoctor.convert(content, @config['asciidoctor'].merge(header_footer: standalone)) else warn 'Unknown AsciiDoc converter. Passing through unparsed content.' content @@ -112,6 +116,8 @@ def render_with_liquid? end end + STANDALONE_HEADER = Converters::AsciiDocConverter::STANDALONE_HEADER + def generate(site) asciidoc_converter = JEKYLL_MIN_VERSION_3 ? site.find_converter_instance(Jekyll::Converters::AsciiDocConverter) : @@ -135,7 +141,15 @@ def generate(site) page.data.update(SafeYAML.load(adoc_front_matter * "\n")) end - page.data['layout'] = 'default' unless page.data.key? 'layout' + case page.data['layout'] + when nil + page.data['layout'] = 'default' unless page.data.key? 'layout' + when '' + page.data['layout'] = 'default' + when false + page.data.delete('layout') + page.content = STANDALONE_HEADER + page.content + end page.extend NoLiquid unless page.data['liquid'] end @@ -155,7 +169,15 @@ def generate(site) post.data.update(SafeYAML.load(adoc_front_matter * "\n")) end - post.data['layout'] = 'post' unless post.data.key? 'layout' + case post.data['layout'] + when nil + post.data['layout'] = 'default' unless post.data.key? 'layout' + when '' + post.data['layout'] = 'default' + when false + post.data.delete('layout') + post.content = STANDALONE_HEADER + post.content + end post.extend NoLiquid unless post.data['liquid'] end