Skip to content

Commit

Permalink
Remove the requirement to include the YAML directive.
Browse files Browse the repository at this point in the history
This was stupid to foist on users. Fixes #25
  • Loading branch information
mblayman committed Sep 20, 2015
1 parent cfa2d26 commit 59b6cc5
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 1 deletion.
6 changes: 6 additions & 0 deletions docs/configuration.rst
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,12 @@ handroll will read the extra data and pass it along to the template. In the
template, the data will be accessible by whatever name was provided. An
example Markdown source document would look like:

.. literalinclude:: ../sample/frontmatter.md
:lines: 2-

You may also include the YAML directive (e.g., ``%YAML 1.1``).
The following example is equally valid.

.. literalinclude:: ../sample/frontmatter.md

Note: When using front matter, handroll does not infer the title from the first
Expand Down
2 changes: 2 additions & 0 deletions docs/releases.rst
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ Version 2.1, In Development
marks for Markdown.
* Composers can be forced to compose with the ``--force`` flag.
* Translated to Arabic.
* Relax the frontmatter requirement and don't force the
inclusion of the YAML directive (e.g., ``%YAML 1.1``).

Version 2.0, Released July 25, 2015
-----------------------------------
Expand Down
2 changes: 1 addition & 1 deletion handroll/composers/generic.py
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ def _get_data(self, source_file):
def _has_frontmatter(self, first_line):
"""Check if the document has any front matter. handroll only supports
front matter from YAML documents."""
return first_line.startswith('%YAML')
return first_line.startswith(('%YAML', '---'))

def _needs_update(self, template, source_file, output_file):
"""Check if the output file needs to be updated by looking at the
Expand Down
12 changes: 12 additions & 0 deletions handroll/tests/test_composers.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import inspect
import os
import re
import stat
import tempfile

Expand Down Expand Up @@ -246,6 +247,17 @@ def test_fires_frontmatter_loaded(self, signals):
signals.frontmatter_loaded.send.assert_called_once_with(
f.name, frontmatter={'title': 'A Fake Title'})

def test_looks_like_frontmatter(self):
composer = self._make_one()
self.assertTrue(composer._has_frontmatter('%YAML 1.1'))
self.assertTrue(composer._has_frontmatter('---'))

def test_frontmatter_pattern_captures_markup(self):
minimal = '---\n---\nabc'
composer = self._make_one()
match = re.search(composer.yaml_scanner, minimal)
self.assertEqual('abc', match.group('markup'))

def test_needs_update(self):
site = tempfile.mkdtemp()
output_file = os.path.join(site, 'output.md')
Expand Down

0 comments on commit 59b6cc5

Please sign in to comment.