-
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 Details(), Dialog() and Div() from html/construct.py to…
… html/tags
- Loading branch information
1 parent
53f4b70
commit 49fc713
Showing
11 changed files
with
155 additions
and
125 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,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) |
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,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) |
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,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) |
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,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) |
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,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) |
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 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) |
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