-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Moved classes HR(), Html() and I() from html/construct.py to html/tags/
- Loading branch information
1 parent
41439ce
commit e823133
Showing
11 changed files
with
183 additions
and
149 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) |
Oops, something went wrong.