Skip to content

Commit

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


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


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


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


Expand Down
6 changes: 3 additions & 3 deletions docs/guide.rst
Original file line number Diff line number Diff line change
Expand Up @@ -558,7 +558,7 @@ Korona can build <embed> tag.

.. code-block:: python
from korona.html.construct import Embed
from korona.html.tags import Embed
attributes = {'src': 'helloworld.swf', 'height': '200', 'width': '100'}
Expand Down Expand Up @@ -586,7 +586,7 @@ Korona can build <fieldset> tag.

.. code-block:: python
from korona.html.construct import FieldSet
from korona.html.tags import FieldSet
attributes = {'disabled': True, 'form': 'form1', 'name': 'name1'}
Expand All @@ -608,7 +608,7 @@ Korona can build <figure> tag.

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

from ..templates.html import (
details_tag,
dialog_tag,
div_tag,
embed_tag,
fieldset_tag,
figure_tag,
footer_tag,
form_tag,
frame_tag,
Expand All @@ -33,68 +27,6 @@
CIRCLE_SHAPE_COORDINATES = 3


class Embed(object):
"""Class for constructing embed tag.
Args:
height (str): Specifies the height of the embedded content (in pixels).
width (str): Specifies the width of the embedded content (in pixels).
src (str): Specifies the address of the external file to embed.
type (str): Specifies the media type of the embedded content.
.. versionadded:: 0.2.0
"""
def __init__(self, height=None, width=None, src=None, type=None):
self.tag = 'embed'
self.values = {'height': height,
'width': width,
'src': src,
'type': type}

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


class FieldSet(object):
"""Class for constructing fieldset tag.
Args:
disabled (bool): Specifies that a group of related form elements
should be disabled.
form (str): Specifies one or more forms the fieldset belongs to.
name (str): Specifies a name for the fieldset.
.. versionadded:: 0.2.0
"""
def __init__(self, disabled=False, form=None, name=None):
# TODO: Add support for inner tags.
self.tag = 'fieldset'
self.values = {'disabled': disabled, 'form': form, 'name': name}

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


class Figure(object):
"""Class for constructing figure tag.
Args:
text (str): Specifies the figure text. (As in <figure>{text}</figure>)
.. versionadded:: 0.2.0
"""
def __init__(self, text=None):
# TODO: Add support for inner tags.
self.tag = 'figure'
self.values = {'text': text}

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


class Footer(object):
"""Class for constructing the footer tag.
Expand Down
5 changes: 5 additions & 0 deletions korona/html/tags/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,4 +23,9 @@
from .dialog import Dialog
from .div import Div

from .embed import Embed

from .fieldset import FieldSet
from .figure import Figure

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

from ...templates.html.tags import embed_tag


class Embed(object):
"""Class for constructing embed tag.
Args:
height (str): Specifies the height of the embedded content (in pixels).
width (str): Specifies the width of the embedded content (in pixels).
src (str): Specifies the address of the external file to embed.
type (str): Specifies the media type of the embedded content.
.. versionadded:: 0.2.0
"""
def __init__(self, height=None, width=None, src=None, type=None):
self.tag = 'embed'
self.values = {'height': height,
'width': width,
'src': src,
'type': type}

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

from ...templates.html.tags import fieldset_tag


class FieldSet(object):
"""Class for constructing fieldset tag.
Args:
disabled (bool): Specifies that a group of related form elements
should be disabled.
form (str): Specifies one or more forms the fieldset belongs to.
name (str): Specifies a name for the fieldset.
.. versionadded:: 0.2.0
"""
def __init__(self, disabled=False, form=None, name=None):
# TODO: Add support for inner tags.
self.tag = 'fieldset'
self.values = {'disabled': disabled, 'form': form, 'name': name}

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

from ...templates.html.tags import figure_tag


class Figure(object):
"""Class for constructing figure tag.
Args:
text (str): Specifies the figure text. (As in <figure>{text}</figure>)
.. versionadded:: 0.2.0
"""
def __init__(self, text=None):
# TODO: Add support for inner tags.
self.tag = 'figure'
self.values = {'text': text}

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

from ..fixtures import parametrize

from korona.html.tags import Embed
from korona.templates.html.tags import embed_tag


@parametrize('attributes', [
({'height': '200'}),
({'height': '200', 'width': '100'}),
({'src': 'helloworld.swf', 'height': '200', 'width': '100'}),
({'src': 'helloworld.swf',
'height': '200',
'width': '100',
'type': 'application'})
])
def test_construct_embed_tag(attributes):
"""Test for validating whether the embed tag is constructed correctly or
not.
"""
embed = Embed(**attributes)
assert embed.construct() == embed_tag.render(attributes)
20 changes: 20 additions & 0 deletions tests/test_html_tags/test_fieldset_tag.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
# -*- coding: utf-8 -*-

from ..fixtures import parametrize

from korona.html.tags import FieldSet
from korona.templates.html.tags import fieldset_tag


@parametrize('attributes', [
({'disabled': True}),
({'form': 'form1'}),
({'name': 'name1'}),
({'disabled': True, 'form': 'form1', 'name': 'name1'})
])
def test_construct_fieldset_tag(attributes):
"""Test for validating whether the fieldset tag is constructed correctly
or not.
"""
fieldset = FieldSet(**attributes)
assert fieldset.construct() == fieldset_tag.render(attributes)
17 changes: 17 additions & 0 deletions tests/test_html_tags/test_figure_tag.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
# -*- coding: utf-8 -*-

from ..fixtures import parametrize

from korona.html.tags import Figure
from korona.templates.html.tags import figure_tag


@parametrize('attributes', [
({'text': 'abcd'})
])
def test_construct_figure_tag(attributes):
"""Test for validating whether the figure tag is constructed correctly or
not.
"""
figure = Figure(**attributes)
assert figure.construct() == figure_tag.render(attributes)
48 changes: 0 additions & 48 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 (
Embed,
FieldSet,
Figure,
Footer,
Form,
Frame,
Expand All @@ -19,9 +16,6 @@
Img
)
from korona.templates.html import (
embed_tag,
fieldset_tag,
figure_tag,
footer_tag,
form_tag,
frame_tag,
Expand Down Expand Up @@ -51,48 +45,6 @@ def test_validate_invalid_tags(tag, error, error_msg):
assert error_msg in str(exc)


@parametrize('attributes', [
({'height': '200'}),
({'height': '200', 'width': '100'}),
({'src': 'helloworld.swf', 'height': '200', 'width': '100'}),
({'src': 'helloworld.swf',
'height': '200',
'width': '100',
'type': 'application'})
])
def test_construct_embed_tag(attributes):
"""Test for validating whether the embed tag is constructed correctly or
not.
"""
embed = Embed(**attributes)
assert embed.construct() == embed_tag.render(attributes)


@parametrize('attributes', [
({'disabled': True}),
({'form': 'form1'}),
({'name': 'name1'}),
({'disabled': True, 'form': 'form1', 'name': 'name1'})
])
def test_construct_fieldset_tag(attributes):
"""Test for validating whether the fieldset tag is constructed correctly
or not.
"""
fieldset = FieldSet(**attributes)
assert fieldset.construct() == fieldset_tag.render(attributes)


@parametrize('attributes', [
({'text': 'abcd'})
])
def test_construct_figure_tag(attributes):
"""Test for validating whether the figure tag is constructed correctly or
not.
"""
figure = Figure(**attributes)
assert figure.construct() == figure_tag.render(attributes)


@parametrize('attributes', [
({'text': 'abcd'})
])
Expand Down

0 comments on commit 4c93e40

Please sign in to comment.