Skip to content

Commit

Permalink
Moved classes HR(), Html() and I() from html/construct.py to html/tags/
Browse files Browse the repository at this point in the history
  • Loading branch information
bharadwajyarlagadda committed Sep 16, 2016
1 parent 41439ce commit e823133
Show file tree
Hide file tree
Showing 11 changed files with 183 additions and 149 deletions.
6 changes: 3 additions & 3 deletions docs/api.rst
Original file line number Diff line number Diff line change
Expand Up @@ -146,15 +146,15 @@ API Reference
:members:


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


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


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


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

.. code-block:: python
from korona.html.construct import HR
from korona.html.tags import HR
attributes = {'align': 'center', 'size': '100'}
Expand All @@ -957,7 +957,7 @@ Korona can help you build <html> tag.

.. code-block:: python
from korona.html.construct import Html
from korona.html.tags import Html
attributes = {'manifest': 'demo.appcache', 'text': 'abcd'}
Expand All @@ -979,7 +979,7 @@ Korona can help you build <i> tag.

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

from ..templates.html import (
hr_tag,
html_tag,
italics_tag,
iframe_tag,
img_tag
)

RECTANGLE_SHAPE_COORDINATES = 4
CIRCLE_SHAPE_COORDINATES = 3


class HR(object):
"""Class for constructing hr tag.
Args:
align (str): Specifies the alignment of a <hr> element.
noshade (bool): Specifies that a <hr> element should render in one
solid color (noshaded), instead of a shaded color.
size (str): Specifies the height of a <hr> element.
width (str): Specifies the width of a <hr> element
.. versionadded:: 0.3.0
"""
def __init__(self, align=None, noshade=False, size=None, width=None):
self.tag = 'hr'
validate_attribute_values(tag=self.tag,
attribute_name='align',
value=align)
self.values = {'align': align,
'noshade': noshade,
'size': size,
'width': width}

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


class Html(object):
"""Class for constructing html tag.
Args:
manifest (str): Specifies the address of the document's cache manifest
(for offline browsing)
xmlns (str): Specifies the XML namespace attribute (If you need your
content to conform to XHTML)
text (str): Specifies the html text. (As in <html>{text}</html>)
.. versionadded:: 0.4.0-dev
"""
def __init__(self, manifest=None, xmlns=None, text=None):
# TODO: Add support for inner tags.
self.tag = 'html'
validate_url(attribute_name='manifest', url=manifest)
self.values = {'manifest': manifest,
'xmlns': xmlns,
'text': text}

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


class I(object):
"""Class for constructing <i> tag.
Args:
text (str): Specifies the italics text. (As in <i>{text}</i>)
.. versionadded:: 0.4.0-dev
"""
def __init__(self, text=None):
self.tag = 'i'
self.values = {'text': text}

def construct(self):
"""Returns the constructed italics tag <i>."""
return italics_tag.render(self.values)


class IFrame(object):
"""Class for constructing <iframe> tag.
Expand Down
4 changes: 4 additions & 0 deletions korona/html/tags/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,5 +34,9 @@

from .head import Head
from .header import Header
from .horizontal_rule import HR
from .html import Html

from .italics import I

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

from __future__ import absolute_import

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


class HR(object):
"""Class for constructing hr tag.
Args:
align (str): Specifies the alignment of a <hr> element.
noshade (bool): Specifies that a <hr> element should render in one
solid color (noshaded), instead of a shaded color.
size (str): Specifies the height of a <hr> element.
width (str): Specifies the width of a <hr> element
.. versionadded:: 0.3.0
"""
def __init__(self, align=None, noshade=False, size=None, width=None):
self.tag = 'hr'
validate_attribute_values(tag=self.tag,
attribute_name='align',
value=align)
self.values = {'align': align,
'noshade': noshade,
'size': size,
'width': width}

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

from __future__ import absolute_import

from ...lib.utils import validate_url
from ...templates.html.tags import html_tag


class Html(object):
"""Class for constructing html tag.
Args:
manifest (str): Specifies the address of the document's cache manifest
(for offline browsing)
xmlns (str): Specifies the XML namespace attribute (If you need your
content to conform to XHTML)
text (str): Specifies the html text. (As in <html>{text}</html>)
.. versionadded:: 0.4.0-dev
"""
def __init__(self, manifest=None, xmlns=None, text=None):
# TODO: Add support for inner tags.
self.tag = 'html'
validate_url(attribute_name='manifest', url=manifest)
self.values = {'manifest': manifest,
'xmlns': xmlns,
'text': text}

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

from __future__ import absolute_import

from ...templates.html.tags import italics_tag


class I(object):
"""Class for constructing <i> tag.
Args:
text (str): Specifies the italics text. (As in <i>{text}</i>)
.. versionadded:: 0.4.0-dev
"""
def __init__(self, text=None):
self.tag = 'i'
self.values = {'text': text}

def construct(self):
"""Returns the constructed italics tag <i>."""
return italics_tag.render(self.values)
33 changes: 33 additions & 0 deletions tests/test_html_tags/test_hr_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 HR
from korona.templates.html.tags import hr_tag


@parametrize('attributes', [
({'align': 'left', 'width': '50%'}),
({'align': 'center', 'size': '100'}),
({'noshade': True})
])
def test_construct_hr_tag(attributes):
"""Test for validating whether the hr tag is constructed correctly or not.
"""
hr = HR(**attributes)
assert hr.construct() == hr_tag.render(attributes)


@parametrize('attributes,exception,error_msg', [
({'align': 'top-right'},
AttributeError,
'attribute values should be one of these')
])
def test_construct_hr_tag_error(attributes, exception, error_msg):
"""Test for validating hr tag's attributes."""
with pytest.raises(exception) as exc:
HR(**attributes)

assert error_msg in str(exc)
34 changes: 34 additions & 0 deletions tests/test_html_tags/test_html_tag.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
# -*- coding: utf-8 -*-

import pytest

from ..fixtures import parametrize

from korona.html.tags import Html
from korona.templates.html.tags import html_tag


@parametrize('attributes', [
({'text': 'abc'}),
({'xmlns': 'www.w3.org', 'text': 'abcd'}),
({'manifest': 'demo.appcache', 'text': 'abcd'})
])
def test_construct_html_tag(attributes):
"""Test for validating whether the html tag is constructed correctly or
not.
"""
html = Html(**attributes)
assert html.construct() == html_tag.render(attributes)


@parametrize('attributes,exception,error_msg', [
({'manifest': 12},
ValueError,
'is not a valid url.')
])
def test_construct_html_tag_error(attributes, exception, error_msg):
"""Test for validating html tag's attributes."""
with pytest.raises(exception) as exc:
Html(**attributes)

assert error_msg in str(exc)
17 changes: 17 additions & 0 deletions tests/test_html_tags/test_italics_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 I
from korona.templates.html.tags import italics_tag


@parametrize('attributes', [
({'text': 'abcd'})
])
def test_construct_italics_tag(attributes):
"""Test for validating whether the italics tag is constructed correctly or
not.
"""
italics = I(**attributes)
assert italics.construct() == italics_tag.render(attributes)
Loading

0 comments on commit e823133

Please sign in to comment.