Skip to content

Commit

Permalink
Added B() class for constructing a bold tag <b></b>; Closes #8
Browse files Browse the repository at this point in the history
  • Loading branch information
bharadwajyarlagadda committed Aug 21, 2016
1 parent 9f02528 commit f8f1be5
Show file tree
Hide file tree
Showing 4 changed files with 39 additions and 4 deletions.
18 changes: 17 additions & 1 deletion korona/html/construct.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,8 @@
from ..templates.html import (
anchor_tag,
abbr_tag,
acronym_tag
acronym_tag,
bold_tag
)

RECTANGLE_SHAPE_COORDINATES = 4
Expand Down Expand Up @@ -195,3 +196,18 @@ def __init__(self, text=None):
def construct_tag(self):
"""Returns the constructed acronym tag <acronym></acronym>."""
return acronym_tag.render(self.values)


class B(object):
"""Class for constructing bold tag.
Args:
text (str): Bold tag text. (Ex. <b>text</b>)
"""
def __init__(self, text=None):
self.tag = 'b'
self.values = {'text': text}

def construct_tag(self):
"""Returns the constructed bold tag <b></b>."""
return bold_tag.render(self.values)
3 changes: 2 additions & 1 deletion korona/templates/html/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,6 @@
from .tags import (
anchor_tag,
abbr_tag,
acronym_tag
acronym_tag,
bold_tag
)
4 changes: 4 additions & 0 deletions korona/templates/html/tags.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,3 +25,7 @@
acronym_tag = env.from_string("""
<acronym>{% if text -%} {{ text }}{% endif -%}</acronym>
""")

bold_tag = env.from_string("""
<b>{% if text -%} {{ text }}{% endif -%}</b>
""")
18 changes: 16 additions & 2 deletions tests/test_tags.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,14 @@
from korona.html.construct import (
A,
Abbr,
Acronym
Acronym,
B
)
from korona.templates.html import (
anchor_tag,
abbr_tag,
acronym_tag
acronym_tag,
bold_tag
)
from korona.lib.utils import validate_tag

Expand Down Expand Up @@ -138,3 +140,15 @@ def test_construct_acronym_tag(attributes):
"""
acronym = Acronym(**attributes)
assert acronym.construct_tag() == acronym_tag.render(attributes)


@parametrize('attributes', [
({'text': 'abc'}),
({'text': None})
])
def test_construct_bold_tag(attributes):
"""Test for validating whether the bold tag is constructed correctly or
not.
"""
bold = B(**attributes)
assert bold.construct_tag() == bold_tag.render(attributes)

0 comments on commit f8f1be5

Please sign in to comment.