diff --git a/korona/html/construct.py b/korona/html/construct.py index c5fffff..3e0d423 100644 --- a/korona/html/construct.py +++ b/korona/html/construct.py @@ -6,7 +6,11 @@ from __future__ import absolute_import from .attributes import TAG_ATTRIBUTES -from ..templates.html import anchor_tag, abbr_tag +from ..templates.html import ( + anchor_tag, + abbr_tag, + acronym_tag +) RECTANGLE_SHAPE_COORDINATES = 4 CIRCLE_SHAPE_COORDINATES = 3 @@ -30,7 +34,7 @@ class A(object): shape (str): Specifies the shape of a link. target(str): Specifies where to open the linked document. type (str): Specifies the media type of the linked document. - text (str): Anchor tag text. (Ex. text + text (str): Anchor tag text. (Ex. text) """ def __init__(self, charset=None, @@ -167,7 +171,7 @@ class Abbr(object): """Class for constructing abbr tag. Args: - text (str): Abbr tag text. (Ex. text + text (str): Abbr tag text. (Ex. text) """ def __init__(self, text=None): self.tag = 'abbr' @@ -176,3 +180,18 @@ def __init__(self, text=None): def construct_tag(self): """Returns the constructed abbr tag .""" return abbr_tag.render(self.values) + + +class Acronym(object): + """Class for constructing acronym tag. + + Args: + text (str): Acronym tag text. (Ex. text) + """ + def __init__(self, text=None): + self.tag = 'acronym' + self.values = {'text': text} + + def construct_tag(self): + """Returns the constructed acronym tag .""" + return acronym_tag.render(self.values) diff --git a/korona/templates/html/__init__.py b/korona/templates/html/__init__.py index 8779ff5..2f4fd6b 100644 --- a/korona/templates/html/__init__.py +++ b/korona/templates/html/__init__.py @@ -2,5 +2,6 @@ from .tags import ( anchor_tag, - abbr_tag + abbr_tag, + acronym_tag ) diff --git a/korona/templates/html/tags.py b/korona/templates/html/tags.py index 05d0da0..ac9abd3 100644 --- a/korona/templates/html/tags.py +++ b/korona/templates/html/tags.py @@ -21,3 +21,7 @@ abbr_tag = env.from_string(""" {% if text -%} {{ text }}{% endif -%} """) + +acronym_tag = env.from_string(""" +{% if text -%} {{ text }}{% endif -%} +""") diff --git a/tests/test_tags.py b/tests/test_tags.py index 0775f48..d694f68 100644 --- a/tests/test_tags.py +++ b/tests/test_tags.py @@ -2,8 +2,16 @@ import pytest -from korona.html.construct import A, Abbr -from korona.templates.html import anchor_tag, abbr_tag +from korona.html.construct import ( + A, + Abbr, + Acronym +) +from korona.templates.html import ( + anchor_tag, + abbr_tag, + acronym_tag +) from korona.lib.utils import validate_tag from .fixtures import parametrize @@ -118,3 +126,15 @@ def test_construct_abbr_tag(attributes): """ abbr = Abbr(**attributes) assert abbr.construct_tag() == abbr_tag.render(attributes) + + +@parametrize('attributes', [ + ({'text': 'abc'}), + ({'text': None}) +]) +def test_construct_acronym_tag(attributes): + """Test for validating whether the acronym tag is constructed correctly or + not. + """ + acronym = Acronym(**attributes) + assert acronym.construct_tag() == acronym_tag.render(attributes)