Skip to content

Commit

Permalink
Moved classes DD(), DL(), DT() and Del() from html/construct.py to ht…
Browse files Browse the repository at this point in the history
…ml/tags
  • Loading branch information
bharadwajyarlagadda committed Sep 16, 2016
1 parent a4b9142 commit 53f4b70
Show file tree
Hide file tree
Showing 9 changed files with 144 additions and 134 deletions.
8 changes: 4 additions & 4 deletions docs/api.rst
Original file line number Diff line number Diff line change
Expand Up @@ -58,11 +58,11 @@ API Reference
:members:


.. autoclass:: korona.html.construct.DD
.. autoclass:: korona.html.tags.DD
:members:


.. autoclass:: korona.html.construct.Del
.. autoclass:: korona.html.tags.Del
:members:


Expand All @@ -78,11 +78,11 @@ API Reference
:members:


.. autoclass:: korona.html.construct.DL
.. autoclass:: korona.html.tags.DL
:members:


.. autoclass:: korona.html.construct.DT
.. autoclass:: korona.html.tags.DT
:members:


Expand Down
8 changes: 4 additions & 4 deletions docs/guide.rst
Original file line number Diff line number Diff line change
Expand Up @@ -392,7 +392,7 @@ Korona can build <dd> tag.

.. code-block:: python
from korona.html.construct import DD
from korona.html.tags import DD
attributes = {'text': 'abc'}
Expand All @@ -419,7 +419,7 @@ Korona can build <del> tag.

.. code-block:: python
from korona.html.construct import Del
from korona.html.tags import Del
attributes = {'cite': 'www.abcd.com', 'text': 'abcd'}
Expand Down Expand Up @@ -507,7 +507,7 @@ Korona can build <dl> tag.

.. code-block:: python
from korona.html.construct import DL
from korona.html.tags import DL
attributes = {'text': 'abc'}
Expand All @@ -529,7 +529,7 @@ Korona can build <dt> tag.

.. code-block:: python
from korona.html.construct import DT
from korona.html.tags import DT
attributes = {'text': 'abc'}
Expand Down
76 changes: 0 additions & 76 deletions korona/html/construct.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,9 @@
)

from ..templates.html import (
dd_tag,
del_tag,
details_tag,
dialog_tag,
div_tag,
dl_tag,
dt_tag,
embed_tag,
fieldset_tag,
figure_tag,
Expand All @@ -37,44 +33,6 @@
CIRCLE_SHAPE_COORDINATES = 3


class DD(object):
"""Class for constructing dd tag.
Args:
text (str): Specifies the dd text. (As in <dd>{text}</dd>)
.. versionadded:: 0.2.0
"""
def __init__(self, text=None):
self.tag = 'dd'
self.values = {'text': text}

def construct(self):
"""Returns the constructed dd tag <dd></dd>."""
return dd_tag.render(self.values)


class Del(object):
"""Class for constructing del tag.
Args:
cite (str): Specifies a URL to a document that explains the reason
why the text was deleted.
datetime (datetime): Specifies the date and time of when the text was
deleted.
.. versionadded:: 0.2.0
"""
def __init__(self, cite=None, datetime=None, text=None):
self.tag = 'del'
# TODO: If possible, add validation for attribute cite
self.values = {'cite': cite, 'datetime': datetime, 'text': text}

def construct(self):
"""Returns the constructed del tag <del>."""
return del_tag.render(self.values)


class Details(object):
"""Class for constructing details tag.
Expand Down Expand Up @@ -137,40 +95,6 @@ def construct(self):
return div_tag.render(self.values)


class DL(object):
"""Class for constructing dl tag.
Args:
text (str): Specifies the dl text. (As in <dl>{text}</dl>)
.. versionadded:: 0.2.0
"""
def __init__(self, text=None):
self.tag = 'dl'
self.values = {'text': text}

def construct(self):
"""Returns the constructed dl tag <dl></dl>."""
return dl_tag.render(self.values)


class DT(object):
"""Class for constructing dt tag.
Args:
text (str): Specifies the dt text. (As in <dt>{text}</dt>)
.. versionadded:: 0.2.0
"""
def __init__(self, text=None):
self.tag = 'dt'
self.values = {'text': text}

def construct(self):
"""Returns the constructed dt tag <dt></dt>."""
return dt_tag.render(self.values)


class Embed(object):
"""Class for constructing embed tag.
Expand Down
3 changes: 3 additions & 0 deletions korona/html/tags/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,4 +17,7 @@
from .col import Col
from .colgroup import ColGroup

from .description import DD, DL, DT
from .delete import Del

from .heading import H1, H2, H3, H4, H5, H6
25 changes: 25 additions & 0 deletions korona/html/tags/delete.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
# -*- coding: utf-8 -*-
"""Module for constructing delete tags <del>."""

from ...templates.html.tags import del_tag


class Del(object):
"""Class for constructing del tag.
Args:
cite (str): Specifies a URL to a document that explains the reason
why the text was deleted.
datetime (datetime): Specifies the date and time of when the text was
deleted.
.. versionadded:: 0.2.0
"""
def __init__(self, cite=None, datetime=None, text=None):
self.tag = 'del'
# TODO: If possible, add validation for attribute cite
self.values = {'cite': cite, 'datetime': datetime, 'text': text}

def construct(self):
"""Returns the constructed del tag <del>."""
return del_tag.render(self.values)
55 changes: 55 additions & 0 deletions korona/html/tags/description.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
# -*- coding: utf-8 -*-
"""Module for constructing description tags <dd>, <dl>, <dt>."""

from ...templates.html.tags import dd_tag, dl_tag, dt_tag


class DD(object):
"""Class for constructing dd tag.
Args:
text (str): Specifies the dd text. (As in <dd>{text}</dd>)
.. versionadded:: 0.2.0
"""
def __init__(self, text=None):
self.tag = 'dd'
self.values = {'text': text}

def construct(self):
"""Returns the constructed dd tag <dd></dd>."""
return dd_tag.render(self.values)


class DL(object):
"""Class for constructing dl tag.
Args:
text (str): Specifies the dl text. (As in <dl>{text}</dl>)
.. versionadded:: 0.2.0
"""
def __init__(self, text=None):
self.tag = 'dl'
self.values = {'text': text}

def construct(self):
"""Returns the constructed dl tag <dl></dl>."""
return dl_tag.render(self.values)


class DT(object):
"""Class for constructing dt tag.
Args:
text (str): Specifies the dt text. (As in <dt>{text}</dt>)
.. versionadded:: 0.2.0
"""
def __init__(self, text=None):
self.tag = 'dt'
self.values = {'text': text}

def construct(self):
"""Returns the constructed dt tag <dt></dt>."""
return dt_tag.render(self.values)
17 changes: 17 additions & 0 deletions tests/test_html_tags/test_del_tag.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@

from ..fixtures import parametrize

from korona.html.tags import Del
from korona.templates.html.tags import del_tag


@parametrize('attributes', [
({'cite': 'www.abcd.com'}),
({'datetime': '2014-11-15T22:55:03Z'}),
({'datetime': '2015-11-15T22:55:03Z', 'text': 'abcd'})
])
def test_construct_del_tag(attributes):
"""Test for validating whether the del tag is constructed correctly or not.
"""
del_ = Del(**attributes)
assert del_.construct() == del_tag.render(attributes)
36 changes: 36 additions & 0 deletions tests/test_html_tags/test_description_tags.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
# -*- coding: utf-8 -*-

from ..fixtures import parametrize

from korona.html.tags import DD, DL, DT
from korona.templates.html.tags import dd_tag, dl_tag, dt_tag


@parametrize('attributes', [
({'text': 'abc'})
])
def test_construct_dd_tag(attributes):
"""Test for validating whether the dd tag is constructed correctly or not.
"""
dd = DD(**attributes)
assert dd.construct() == dd_tag.render(attributes)


@parametrize('attributes', [
({'text': 'abc'})
])
def test_construct_dl_tag(attributes):
"""Test for validating whether the dl tag is constructed correctly or not.
"""
dl = DL(**attributes)
assert dl.construct() == dl_tag.render(attributes)


@parametrize('attributes', [
({'text': 'abc'})
])
def test_construct_dt_tag(attributes):
"""Test for validating whether the dt tag is constructed correctly or not.
"""
dt = DT(**attributes)
assert dt.construct() == dt_tag.render(attributes)
50 changes: 0 additions & 50 deletions tests/test_tags.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,9 @@
import pytest

from korona.html.construct import (
DD,
Del,
Details,
Dialog,
Div,
DL,
DT,
Embed,
FieldSet,
Figure,
Expand All @@ -26,13 +22,9 @@
Img
)
from korona.templates.html import (
dd_tag,
del_tag,
details_tag,
dialog_tag,
div_tag,
dl_tag,
dt_tag,
embed_tag,
fieldset_tag,
figure_tag,
Expand Down Expand Up @@ -65,28 +57,6 @@ def test_validate_invalid_tags(tag, error, error_msg):
assert error_msg in str(exc)


@parametrize('attributes', [
({'text': 'abc'})
])
def test_construct_dd_tag(attributes):
"""Test for validating whether the dd tag is constructed correctly or not.
"""
dd = DD(**attributes)
assert dd.construct() == dd_tag.render(attributes)


@parametrize('attributes', [
({'cite': 'www.abcd.com'}),
({'datetime': '2014-11-15T22:55:03Z'}),
({'datetime': '2015-11-15T22:55:03Z', 'text': 'abcd'})
])
def test_construct_del_tag(attributes):
"""Test for validating whether the del tag is constructed correctly or not.
"""
del_ = Del(**attributes)
assert del_.construct() == del_tag.render(attributes)


@parametrize('attributes', [
({'open': True}),
({'text': 'abcd'}),
Expand Down Expand Up @@ -138,26 +108,6 @@ def test_construct_div_tag_error(attributes, exception, error_msg):
assert error_msg in str(exc)


@parametrize('attributes', [
({'text': 'abc'})
])
def test_construct_dl_tag(attributes):
"""Test for validating whether the dl tag is constructed correctly or not.
"""
dl = DL(**attributes)
assert dl.construct() == dl_tag.render(attributes)


@parametrize('attributes', [
({'text': 'abc'})
])
def test_construct_dt_tag(attributes):
"""Test for validating whether the dt tag is constructed correctly or not.
"""
dt = DT(**attributes)
assert dt.construct() == dt_tag.render(attributes)


@parametrize('attributes', [
({'height': '200'}),
({'height': '200', 'width': '100'}),
Expand Down

0 comments on commit 53f4b70

Please sign in to comment.