Skip to content

Commit

Permalink
resolves asciidoctor#57 make front matter header optional
Browse files Browse the repository at this point in the history
  • Loading branch information
mojavelinux committed May 30, 2016
1 parent afd9422 commit e4a69df
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 9 deletions.
15 changes: 7 additions & 8 deletions README.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ There are a few conditions that must be met for an AsciiDoc file to be qualified
. The file must have an AsciiDoc file extension (see <<configuration>>).
. The name of the file must not begin with a dot (`.`) or underscore (`_`).footnoteref:[excluded_files,These files are excluded by Jekyll.]
. The file must not be located in a folder whose name begins with a dot (`.`) or underscore (`_`), except for posts.footnoteref:[excluded_files]
. The document must begin with a {uri-front-matter}[front matter header] (and cannot have a Byte Order Mark, or BOM).
//. The document may begin with a {uri-front-matter}[front matter header] (in which case it cannot begin with a Byte Order Mark, or BOM).

Here's a sample AsciiDoc file that meets these criteria:

Expand Down Expand Up @@ -171,15 +171,14 @@ If you want the Liquid template preprocessor to be applied to an AsciiDoc file (
:page-liquid:
----

IMPORTANT: Each AsciiDoc file must begin with a {uri-front-matter}[front matter header].
Otherwise, Jekyll won't treat the file as a page, but rather as a static file.
The front matter header must be the very first character of the file.
If the file begins with whitespace or a Byte Order Mark (BOM), then the front matter header won't be seen.
IMPORTANT: AsciiDoc files may include a {uri-front-matter}[front matter header] for declaring page settings and variables.
If present, the front matter header must be the very first character of the file.
The front matter header won't be seen if the file begins with whitespace or a Byte Order Mark (BOM).

TIP: You can use an empty front matter header, as shown in the second example above.
In this case, you define all the document metadata (e.g., layout) using AsciiDoc attributes instead of in the front matter.
TIP: You can exclude the front matter header, as shown in the first example above, or leave it empty, as shown in the second example.
In these cases, you'll define all the page metadata (e.g., layout) using AsciiDoc attributes instead of in the front matter.
You can also use a combination of both.
In this case, the attributes defined in the AsciiDoc header take precedence.
When combined, the attributes defined in the AsciiDoc header take precedence.

You can now build your site using:

Expand Down
19 changes: 18 additions & 1 deletion lib/jekyll-asciidoc.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,15 @@
JEKYLL_MIN_VERSION_3 = Gem::Version.new(Jekyll::VERSION) >= Gem::Version.new('3.0.0') unless defined? JEKYLL_MIN_VERSION_3

module Jekyll
module AsciiDoc
module Utils
extend self
def has_front_matter?(delegate_method, asciidoc_ext_re, path)
::File.extname(path) =~ asciidoc_ext_re ? true : delegate_method.call(path)
end
end
end

module Converters
class AsciiDocConverter < Converter
IMPLICIT_ATTRIBUTES = %W(
Expand All @@ -17,7 +26,7 @@ def initialize(config)
@config = config
config['asciidoc'] ||= 'asciidoctor'
asciidoc_ext = (config['asciidoc_ext'] ||= 'asciidoc,adoc,ad')
config['asciidoc_ext_re'] = /^\.(?:#{asciidoc_ext.tr ',', '|'})$/i
asciidoc_ext_re = (config['asciidoc_ext_re'] = /^\.(?:#{asciidoc_ext.tr ',', '|'})$/i)
config['asciidoc_page_attribute_prefix'] ||= 'page'
unless (asciidoctor_config = (config['asciidoctor'] ||= {})).frozen?
# NOTE convert keys to symbols
Expand All @@ -29,6 +38,14 @@ def initialize(config)
attributes.unshift('notitle', 'hardbreaks', 'idprefix', 'idseparator=-', 'linkattrs')
attributes.concat(IMPLICIT_ATTRIBUTES)
end
if JEKYLL_MIN_VERSION_3 && !config['asciidoc_require_front_matter']
if (del_method = ::Jekyll::Utils.method(:has_yaml_header?))
unless (new_method = ::Jekyll::AsciiDoc::Utils.method(:has_front_matter?)).respond_to?(:curry)
new_method = new_method.to_proc # Ruby < 2.2
end
del_method.owner.define_singleton_method(:has_yaml_header?, new_method.curry[del_method][asciidoc_ext_re])
end
end
asciidoctor_config.freeze
end
end
Expand Down

0 comments on commit e4a69df

Please sign in to comment.