Skip to content

Commit

Permalink
Moved classes Details(), Dialog() and Div() from html/construct.py to…
Browse files Browse the repository at this point in the history
… html/tags
  • Loading branch information
bharadwajyarlagadda committed Sep 16, 2016
1 parent 53f4b70 commit 49fc713
Show file tree
Hide file tree
Showing 11 changed files with 155 additions and 125 deletions.
6 changes: 3 additions & 3 deletions docs/api.rst
Original file line number Diff line number Diff line change
Expand Up @@ -66,15 +66,15 @@ API Reference
:members:


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


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


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


Expand Down
6 changes: 3 additions & 3 deletions docs/guide.rst
Original file line number Diff line number Diff line change
Expand Up @@ -441,7 +441,7 @@ Korona supports ``open`` attribute for ``<details>`` tag. Korona can help you bu

.. code-block:: python
from korona.html.construct import Details
from korona.html.tags import Details
attributes = {'open': True, 'text': 'abcd'}
Expand All @@ -463,7 +463,7 @@ Korona supports ``open`` attribute for ``<dialog>`` tag. Korona can help you bui

.. code-block:: python
from korona.html.construct import Dialog
from korona.html.tags import Dialog
attributes = {'open': True, 'text': 'abcd'}
Expand All @@ -485,7 +485,7 @@ Korona supports ``align`` attribute for ``<div>`` tag. Korona can help you build

.. code-block:: python
from korona.html.construct import Div
from korona.html.tags import Div
attributes = {'align': 'left', 'text': 'abcd'}
Expand Down
62 changes: 0 additions & 62 deletions korona/html/construct.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,68 +33,6 @@
CIRCLE_SHAPE_COORDINATES = 3


class Details(object):
"""Class for constructing details tag.
Args:
open (bool): Specifies that the details should be visible (open) to
the user.
text (str): Specifies the details text. (As in
<details>{text}</details>)
.. versionadded:: 0.2.0
"""
def __init__(self, open=False, text=None):
self.tag = 'details'
self.values = {'open': open, 'text': text}

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


class Dialog(object):
"""Class for constructing dialog tag.
Args:
open (bool): Specifies that the dialog element is active and that the
user can interact with it.
text (str): Specifies the dialog text. (As in
<dialog>{text}</dialog>)
.. versionadded:: 0.2.0
"""
def __init__(self, open=False, text=None):
self.tag = 'dialog'
self.values = {'open': open, 'text': text}

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


class Div(object):
"""Class for constructing div tag.
Args:
align (str): Specifies the alignment of the content inside a <div>
element.
text (str): Specifies the div text. (As in <div>{text}</div>)
.. versionadded:: 0.2.0
"""
def __init__(self, align=None, text=None):
self.tag = 'div'
validate_attribute_values(tag=self.tag,
attribute_name='align',
value=align)
self.values = {'align': align, 'text': text}

def construct(self):
"""Returns the constructed div tag <div></div>."""
return div_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 @@ -19,5 +19,8 @@

from .description import DD, DL, DT
from .delete import Del
from .details import Details
from .dialog import Dialog
from .div import Div

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

from ...templates.html.tags import details_tag


class Details(object):
"""Class for constructing details tag.
Args:
open (bool): Specifies that the details should be visible (open) to
the user.
text (str): Specifies the details text. (As in
<details>{text}</details>)
.. versionadded:: 0.2.0
"""
def __init__(self, open=False, text=None):
self.tag = 'details'
self.values = {'open': open, 'text': text}

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

from ...templates.html.tags import dialog_tag


class Dialog(object):
"""Class for constructing dialog tag.
Args:
open (bool): Specifies that the dialog element is active and that the
user can interact with it.
text (str): Specifies the dialog text. (As in
<dialog>{text}</dialog>)
.. versionadded:: 0.2.0
"""
def __init__(self, open=False, text=None):
self.tag = 'dialog'
self.values = {'open': open, 'text': text}

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

from ...lib.utils import validate_attribute_values
from ...templates.html.tags import div_tag


class Div(object):
"""Class for constructing div tag.
Args:
align (str): Specifies the alignment of the content inside a <div>
element.
text (str): Specifies the div text. (As in <div>{text}</div>)
.. versionadded:: 0.2.0
"""
def __init__(self, align=None, text=None):
self.tag = 'div'
validate_attribute_values(tag=self.tag,
attribute_name='align',
value=align)
self.values = {'align': align, 'text': text}

def construct(self):
"""Returns the constructed div tag <div></div>."""
return div_tag.render(self.values)
19 changes: 19 additions & 0 deletions tests/test_html_tags/test_details_tag.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
# -*- coding: utf-8 -*-

from ..fixtures import parametrize

from korona.html.tags import Details
from korona.templates.html.tags import details_tag


@parametrize('attributes', [
({'open': True}),
({'text': 'abcd'}),
({'open': True, 'text': 'abcd'})
])
def test_construct_details_tag(attributes):
"""Test for validating whether the details tag is constructed correctly or
not.
"""
details = Details(**attributes)
assert details.construct() == details_tag.render(attributes)
19 changes: 19 additions & 0 deletions tests/test_html_tags/test_dialog_tag.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
# -*- coding: utf-8 -*-

from ..fixtures import parametrize

from korona.html.tags import Dialog
from korona.templates.html.tags import dialog_tag


@parametrize('attributes', [
({'open': True}),
({'text': 'abcd'}),
({'open': True, 'text': 'abcd'})
])
def test_construct_dialog_tag(attributes):
"""Test for validating whether the dialog tag is constructed correctly or
not.
"""
dialog = Dialog(**attributes)
assert dialog.construct() == dialog_tag.render(attributes)
33 changes: 33 additions & 0 deletions tests/test_html_tags/test_div_tag.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
# -*- coding: utf-8 -*-

import pytest

from ..fixtures import parametrize

from korona.html.tags import Div
from korona.templates.html.tags import div_tag


@parametrize('attributes', [
({'align': 'left'}),
({'text': 'abcd'}),
({'align': 'right', 'text': 'abcd'})
])
def test_construct_div_tag(attributes):
"""Test for validating whether the div tag is constructed correctly or not.
"""
div = Div(**attributes)
assert div.construct() == div_tag.render(attributes)


@parametrize('attributes,exception,error_msg', [
({'align': 'abcd'},
AttributeError,
'attribute values should be one of these')
])
def test_construct_div_tag_error(attributes, exception, error_msg):
"""Test for validating div tag's attributes."""
with pytest.raises(exception) as exc:
Div(**attributes)

assert error_msg in str(exc)
57 changes: 0 additions & 57 deletions tests/test_tags.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,6 @@
import pytest

from korona.html.construct import (
Details,
Dialog,
Div,
Embed,
FieldSet,
Figure,
Expand All @@ -22,9 +19,6 @@
Img
)
from korona.templates.html import (
details_tag,
dialog_tag,
div_tag,
embed_tag,
fieldset_tag,
figure_tag,
Expand Down Expand Up @@ -57,57 +51,6 @@ def test_validate_invalid_tags(tag, error, error_msg):
assert error_msg in str(exc)


@parametrize('attributes', [
({'open': True}),
({'text': 'abcd'}),
({'open': True, 'text': 'abcd'})
])
def test_construct_details_tag(attributes):
"""Test for validating whether the details tag is constructed correctly or
not.
"""
details = Details(**attributes)
assert details.construct() == details_tag.render(attributes)


@parametrize('attributes', [
({'open': True}),
({'text': 'abcd'}),
({'open': True, 'text': 'abcd'})
])
def test_construct_dialog_tag(attributes):
"""Test for validating whether the dialog tag is constructed correctly or
not.
"""
dialog = Dialog(**attributes)
assert dialog.construct() == dialog_tag.render(attributes)


@parametrize('attributes', [
({'align': 'left'}),
({'text': 'abcd'}),
({'align': 'right', 'text': 'abcd'})
])
def test_construct_div_tag(attributes):
"""Test for validating whether the div tag is constructed correctly or not.
"""
div = Div(**attributes)
assert div.construct() == div_tag.render(attributes)


@parametrize('attributes,exception,error_msg', [
({'align': 'abcd'},
AttributeError,
'attribute values should be one of these')
])
def test_construct_div_tag_error(attributes, exception, error_msg):
"""Test for validating div tag's attributes."""
with pytest.raises(exception) as exc:
Div(**attributes)

assert error_msg in str(exc)


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

0 comments on commit 49fc713

Please sign in to comment.