-
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 Footer(), Form() and Frame() from html/construct.py to …
…html/tags/
- Loading branch information
1 parent
4c93e40
commit fac166e
Showing
11 changed files
with
278 additions
and
248 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,22 @@ | ||
# -*- coding: utf-8 -*- | ||
"""Module for constructing <footer> tag.""" | ||
|
||
from ...templates.html.tags import footer_tag | ||
|
||
|
||
class Footer(object): | ||
"""Class for constructing the footer tag. | ||
Args: | ||
text (str): Specifies the footer text. (As in <footer>{text}</footer>) | ||
.. versionadded:: 0.2.0 | ||
""" | ||
def __init__(self, text=None): | ||
# TODO: Add support for inner tags. | ||
self.tag = 'footer' | ||
self.values = {'text': text} | ||
|
||
def construct(self): | ||
"""Returns the constructed footer tag <footer></footer>.""" | ||
return footer_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,74 @@ | ||
# -*- coding: utf-8 -*- | ||
"""Module for constructing <form> tag.""" | ||
|
||
from ...lib.utils import validate_attribute_values | ||
from ...templates.html.tags import form_tag | ||
|
||
|
||
class Form(object): | ||
"""Class for constructing <form> tag. | ||
Args: | ||
accept (str): Specifies a comma-separated list of file types that the | ||
server accepts (that can be submitted through the file upload). | ||
action (str): Specifies where to send the form-data when a form is | ||
submitted. | ||
autocomplete (str): Specifies whether a form should have autocomplete | ||
on or off. | ||
enctype (str): Specifies how the form-data should be encoded when | ||
submitting it to the server (only for method="post"). | ||
method (str): Specifies the HTTP method to use when sending form-data. | ||
name (str): Specifies the name of a form. | ||
novalidate (bool): Specifies that the form should not be validated | ||
when submitted. | ||
target (str): Specifies where to display the response that is received | ||
after submitting the form. | ||
text (str): Specifies the form text. (As in <form>{text}</form>) | ||
.. versionadded:: 0.2.0 | ||
""" | ||
def __init__(self, | ||
accept=None, | ||
action=None, | ||
autocomplete=None, | ||
enctype=None, | ||
method=None, | ||
name=None, | ||
novalidate=False, | ||
target=None, | ||
text=None): | ||
self.tag = 'form' | ||
validate_attribute_values(tag=self.tag, | ||
attribute_name='autocomplete', | ||
value=autocomplete) | ||
self.validate_enctype_attribute(method=method, enctype=enctype) | ||
validate_attribute_values(tag=self.tag, | ||
attribute_name='enctype', | ||
value=enctype) | ||
validate_attribute_values(tag=self.tag, | ||
attribute_name='method', | ||
value=method) | ||
self.values = {'accept': accept, | ||
'action': action, | ||
'autocomplete': autocomplete, | ||
'enctype': enctype, | ||
'method': method, | ||
'name': name, | ||
'novalidate': novalidate, | ||
'target': target, | ||
'text': text} | ||
|
||
def construct(self): | ||
"""Returns the constructed form tag <form></form>.""" | ||
return form_tag.render(self.values) | ||
|
||
def validate_enctype_attribute(self, method, enctype): | ||
"""Validates enctype attribute. The enctype attribute can be used only | ||
if method is post. | ||
""" | ||
if not enctype: | ||
return | ||
|
||
if enctype and method != 'post': | ||
raise AttributeError('<form>: The enctype attribute can be ' | ||
'used/set only if method="post".') |
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,60 @@ | ||
# -*- coding: utf-8 -*- | ||
"""Module for constructing <frame> tag.""" | ||
|
||
from ...lib.utils import validate_attribute_values, validate_url | ||
from ...templates.html.tags import frame_tag | ||
|
||
|
||
class Frame(object): | ||
"""Class for constructing <frame> tag. | ||
Args: | ||
frameborder (str): Specifies whether or not to display a border around | ||
a frame. | ||
longdesc (str): Specifies a page that contains a long description of | ||
the content of a frame. | ||
marginheight (str): Specifies the top and bottom margins of a frame. | ||
marginwidth (str): Specifies the left and right margins of a frame. | ||
name (str): Specifies the name of a frame. | ||
noresize (str): Specifies that a frame is not resizable. | ||
scrolling (str): Specifies whether or not to display scrollbars in a | ||
frame. | ||
src (str): Specifies the URL of the document to show in a frame. | ||
.. versionadded:: 0.2.0 | ||
.. versionchanged:: 0.3.1 | ||
Added URL validation for src attribute. | ||
""" | ||
def __init__(self, | ||
frameborder=None, | ||
longdesc=None, | ||
marginheight=None, | ||
marginwidth=None, | ||
name=None, | ||
noresize=None, | ||
scrolling=None, | ||
src=None): | ||
self.tag = 'frame' | ||
validate_attribute_values(tag=self.tag, | ||
attribute_name='frameborder', | ||
value=frameborder) | ||
validate_attribute_values(tag=self.tag, | ||
attribute_name='noresize', | ||
value=noresize) | ||
validate_attribute_values(tag=self.tag, | ||
attribute_name='scrolling', | ||
value=scrolling) | ||
validate_url(attribute_name='src', url=src) | ||
self.values = {'frameborder': frameborder, | ||
'longdesc': longdesc, | ||
'marginheight': marginheight, | ||
'marginwidth': marginwidth, | ||
'name': name, | ||
'noresize': noresize, | ||
'scrolling': scrolling, | ||
'src': src} | ||
|
||
def construct(self): | ||
"""Returns the constructed tag <frame>.""" | ||
return frame_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,17 @@ | ||
# -*- coding: utf-8 -*- | ||
|
||
from ..fixtures import parametrize | ||
|
||
from korona.html.tags import Footer | ||
from korona.templates.html.tags import footer_tag | ||
|
||
|
||
@parametrize('attributes', [ | ||
({'text': 'abcd'}) | ||
]) | ||
def test_construct_footer_tag(attributes): | ||
"""Test for validating whether the footer tag is constructed correctly or | ||
not. | ||
""" | ||
footer = Footer(**attributes) | ||
assert footer.construct() == footer_tag.render(attributes) |
Oops, something went wrong.