diff --git a/src/synthale/markdown.py b/src/synthale/markdown.py index db4d373..f341a9a 100644 --- a/src/synthale/markdown.py +++ b/src/synthale/markdown.py @@ -17,3 +17,13 @@ def setext_heading(text, level): hchar = '-' 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) diff --git a/src/synthale/recipes.py b/src/synthale/recipes.py index 2b46916..2c89a96 100644 --- a/src/synthale/recipes.py +++ b/src/synthale/recipes.py @@ -38,8 +38,32 @@ class MarkdownRecipe: @property def markdown(self): """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) + @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): """Parse BeerXML file located at `path`. diff --git a/tests/test_markdown.py b/tests/test_markdown.py index e7823c0..c8f4f59 100644 --- a/tests/test_markdown.py +++ b/tests/test_markdown.py @@ -12,3 +12,13 @@ from synthale import markdown def test_setext_heading(text, level, expected): """Test for valid setext headings from setext_heading function.""" 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**' diff --git a/tests/test_recipes.py b/tests/test_recipes.py index 1890072..7ba6fb6 100644 --- a/tests/test_recipes.py +++ b/tests/test_recipes.py @@ -36,12 +36,30 @@ def test_markdown_recipe_filename(): assert recipe.filename == 'validate_this.md' -def test_markdown_recipe_markdown(): - """Validate the generated markdown.""" +def test_markdown_recipe_name(): + """Validate generated name for recipe.""" xml_recipe = pybeerxml.Recipe() xml_recipe.name = 'Foobar' 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):