Skip to content

Commit

Permalink
Added Acronym() class for constructing the acronym tag; CLoses #4
Browse files Browse the repository at this point in the history
  • Loading branch information
bharadwajyarlagadda committed Aug 20, 2016
1 parent 89fd877 commit 9f02528
Show file tree
Hide file tree
Showing 4 changed files with 50 additions and 6 deletions.
25 changes: 22 additions & 3 deletions korona/html/construct.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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. <a>text</a>
text (str): Anchor tag text. (Ex. <a>text</a>)
"""
def __init__(self,
charset=None,
Expand Down Expand Up @@ -167,7 +171,7 @@ class Abbr(object):
"""Class for constructing abbr tag.
Args:
text (str): Abbr tag text. (Ex. <abbr>text</abbr>
text (str): Abbr tag text. (Ex. <abbr>text</abbr>)
"""
def __init__(self, text=None):
self.tag = 'abbr'
Expand All @@ -176,3 +180,18 @@ def __init__(self, text=None):
def construct_tag(self):
"""Returns the constructed abbr tag <abbr></abbr>."""
return abbr_tag.render(self.values)


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

def construct_tag(self):
"""Returns the constructed acronym tag <acronym></acronym>."""
return acronym_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 @@ -2,5 +2,6 @@

from .tags import (
anchor_tag,
abbr_tag
abbr_tag,
acronym_tag
)
4 changes: 4 additions & 0 deletions korona/templates/html/tags.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,3 +21,7 @@
abbr_tag = env.from_string("""
<abbr>{% if text -%} {{ text }}{% endif -%}</abbr>
""")

acronym_tag = env.from_string("""
<acronym>{% if text -%} {{ text }}{% endif -%}</acronym>
""")
24 changes: 22 additions & 2 deletions tests/test_tags.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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)

0 comments on commit 9f02528

Please sign in to comment.