Skip to content

Commit

Permalink
resolves asciidoctor#63 allow layout to be disabled
Browse files Browse the repository at this point in the history
- false disables layout, enables standalone output
- nil disables layout, does not enable standalone output
- not specified or empty string uses default (inherited) layout
  • Loading branch information
mojavelinux committed May 30, 2016
1 parent 59136c3 commit 2119196
Showing 1 changed file with 26 additions and 4 deletions.
30 changes: 26 additions & 4 deletions lib/jekyll-asciidoc.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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
Expand All @@ -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
Expand Down Expand Up @@ -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) :
Expand All @@ -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
Expand All @@ -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
Expand Down

0 comments on commit 2119196

Please sign in to comment.