Skip to content

Commit 74f9cb2

Browse files
committed
resolves #187 honor layout defined in frontmatter defaults (PR #188)
1 parent 694c056 commit 74f9cb2

File tree

9 files changed

+75
-3
lines changed

9 files changed

+75
-3
lines changed

CHANGELOG.adoc

+4
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,10 @@
55
This document provides a high-level view of the changes to the {project-name} by release.
66
For a detailed view of what has changed, refer to the {uri-repo}/commits/master[commit history] on GitHub.
77

8+
== Unreleased
9+
10+
* honor layout defined in frontmatter defaults (#187)
11+
812
== 2.1.0 (2017-05-21) - @mojavelinux
913

1014
* Add `tocify_asciidoc` Liquid filter for generating a table of contents from the parsed AsciiDoc document (Jekyll 3+ only) (#37)

README.adoc

+1-1
Original file line numberDiff line numberDiff line change
@@ -206,7 +206,7 @@ To review, here are the different ways to specify a layout using the AsciiDoc at
206206
* `:page-layout: info` -- use the layout named `info` (e.g., [.path]__layout/info.html_)
207207
* _not specified_, `:page-layout:` or `:page-layout: _auto` -- use the automatic layout (i.e., `page` for pages, `post` for posts, the singular form of the collection label for a document; if the auto-selected layout isn't available, the layout `default` is used)
208208
* `:!page-layout:` or `:page-layout: false` -- don't use a layout; instead, generate a standalone HTML document
209-
* `:page-layout: ~` -- don't use a layout (often results in an incomplete HTML file)
209+
* `:page-layout: ~` or `:page-layout: none` -- don't use a layout or create a standalone HTML document (often produces an HTML fragment); the `~` value only works when defined as an AsciiDoc page attribute; otherwise, the value `none` must be used
210210

211211
=== Implicit Page Variables
212212

lib/jekyll-asciidoc/integrator.rb

+2-2
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ def generate site
5656
# Returns a [Boolean] indicating whether the document should be published.
5757
def integrate document, collection_name = nil
5858
data = document.data
59-
document.content = [%(:#{@page_attr_prefix}layout: _auto), document.content] * NewLine unless data.key? 'layout'
59+
document.content = [%(:#{@page_attr_prefix}layout: _auto), document.content] * NewLine unless data['layout']
6060
return true unless (doc = @converter.load_header document)
6161

6262
# NOTE id is already reserved in Jekyll for another purpose, so we'll map id to docid instead
@@ -93,7 +93,7 @@ def integrate document, collection_name = nil
9393
layout = collection_name ? (collection_name.chomp 's') : 'page'
9494
data['layout'] = (document.site.layouts.key? layout) ? layout : 'default'
9595
when false
96-
data.delete 'layout'
96+
data['layout'] = 'none'
9797
document.content = %(#{StandaloneOptionLine}#{document.content})
9898
end
9999

Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
gems:
2+
- jekyll-asciidoc
3+
defaults:
4+
- values:
5+
layout: general
6+
- scope:
7+
path: docs
8+
type: pages
9+
values:
10+
layout: docs
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
<!DOCTYPE html>
2+
<html>
3+
<head>
4+
<meta charset="utf-8">
5+
<title>{{ page.title }}</title>
6+
</head>
7+
<body>
8+
<div class="page-content">
9+
{{ content }}
10+
</div>
11+
<footer>
12+
<p>Footer for docs layout.</p>
13+
</footer>
14+
</body>
15+
</html>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
<!DOCTYPE html>
2+
<html>
3+
<head>
4+
<meta charset="utf-8">
5+
<title>{{ page.title }}</title>
6+
</head>
7+
<body>
8+
<div class="page-content">
9+
{{ content }}
10+
</div>
11+
<footer>
12+
<p>Footer for general layout.</p>
13+
</footer>
14+
</body>
15+
</html>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
= Docs Page
2+
3+
Content of docs page.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
= General Page
2+
3+
Content of general page.

spec/jekyll-asciidoc_spec.rb

+22
Original file line numberDiff line numberDiff line change
@@ -633,6 +633,28 @@
633633
end
634634
end
635635

636+
describe 'use front matter defaults' do
637+
let :name do
638+
'front_matter_defaults'
639+
end
640+
641+
before(:each) { site.process }
642+
643+
it 'should use the layout for the default scope when no layout is specified' do
644+
file = output_file 'page.html'
645+
expect(::File).to exist(file)
646+
contents = ::File.read file
647+
expect(contents).to include('<p>Footer for general layout.</p>')
648+
end
649+
650+
it 'should use the layout for the matching scope when no layout is specified' do
651+
file = output_file 'docs/page.html'
652+
expect(::File).to exist(file)
653+
contents = ::File.read file
654+
expect(contents).to include('<p>Footer for docs layout.</p>')
655+
end
656+
end
657+
636658
describe 'require front matter header' do
637659
let :name do
638660
'require_front_matter_header'

0 commit comments

Comments
 (0)