1
0
Fork 0
mirror of https://github.com/shouptech/synthale.git synced 2026-02-03 15:39:45 +00:00

Generate recipe's style

This commit is contained in:
Emma 2018-12-23 14:13:46 -07:00
parent 45d3a57dd0
commit 22aad84b9b
4 changed files with 65 additions and 3 deletions

View file

@ -17,3 +17,13 @@ def setext_heading(text, level):
hchar = '-' hchar = '-'
return '{}\n{}'.format(text.strip(), hchar * len(text.strip())) return '{}\n{}'.format(text.strip(), hchar * len(text.strip()))
def emphasis(text):
"""Wrap text with asterisks."""
return '*{}*'.format(text)
def strong(text):
"""Wrap text with double asterisks."""
return '**{}**'.format(text)

View file

@ -38,8 +38,32 @@ class MarkdownRecipe:
@property @property
def markdown(self): def markdown(self):
"""Return generated markdown for the recipe.""" """Return generated markdown for the recipe."""
return '\n'.join((
self.name,
'',
self.style,
'',
))
@property
def name(self):
"""Return markdown for the recipe's name."""
return markdown.setext_heading(self.recipe.name, 1) return markdown.setext_heading(self.recipe.name, 1)
@property
def style(self):
"""Return markdown for the recipe's style."""
return '\n'.join((
markdown.setext_heading('Style', 2),
'{}: {}'.format(markdown.strong('Style guide'),
self.recipe.style.style_guide),
'{}: {}{}'.format(markdown.strong('Style category'),
int(self.recipe.style.category_number),
self.recipe.style.style_letter),
'{}: {}'.format(markdown.strong('Style name'),
self.recipe.style.name)
))
def load_file(path): def load_file(path):
"""Parse BeerXML file located at `path`. """Parse BeerXML file located at `path`.

View file

@ -12,3 +12,13 @@ from synthale import markdown
def test_setext_heading(text, level, expected): def test_setext_heading(text, level, expected):
"""Test for valid setext headings from setext_heading function.""" """Test for valid setext headings from setext_heading function."""
assert markdown.setext_heading(text, level) == expected assert markdown.setext_heading(text, level) == expected
def test_emphasis():
"""Test emphasis."""
assert markdown.emphasis('Foo') == '*Foo*'
def test_strong():
"""Test strong."""
assert markdown.strong('Foo') == '**Foo**'

View file

@ -36,12 +36,30 @@ def test_markdown_recipe_filename():
assert recipe.filename == 'validate_this.md' assert recipe.filename == 'validate_this.md'
def test_markdown_recipe_markdown(): def test_markdown_recipe_name():
"""Validate the generated markdown.""" """Validate generated name for recipe."""
xml_recipe = pybeerxml.Recipe() xml_recipe = pybeerxml.Recipe()
xml_recipe.name = 'Foobar' xml_recipe.name = 'Foobar'
recipe = MarkdownRecipe(xml_recipe) recipe = MarkdownRecipe(xml_recipe)
assert recipe.markdown == 'Foobar\n======' assert recipe.name == 'Foobar\n======'
def test_markdown_recipe_style():
"""Validate generated style for recipe."""
xml_recipe = pybeerxml.Recipe()
xml_recipe.style = pybeerxml.style.Style()
xml_recipe.style.style_guide = 'BJCP'
xml_recipe.style.style_letter = 'E'
xml_recipe.style.category_number = 13
xml_recipe.style.name = 'American Stout'
recipe = MarkdownRecipe(xml_recipe)
assert recipe.style == (
'Style\n'
'-----\n'
'**Style guide**: BJCP\n'
'**Style category**: 13E\n'
'**Style name**: American Stout'
)
def test_write_recipes(md_recipes, tmpdir): def test_write_recipes(md_recipes, tmpdir):