Skip to content

Commit

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


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


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


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


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

.. code-block:: python
from korona.html.construct import Footer
from korona.html.tags import Footer
attributes = {'text': 'abc'}
Expand Down Expand Up @@ -668,7 +668,7 @@ Korona can build <form> tag.

.. code-block:: python
from korona.html.construct import Form
from korona.html.tags import Form
attributes = {'action': 'demo.asp', 'method': 'get', 'name': 'name1', 'target': '_top'}
Expand Down Expand Up @@ -701,7 +701,7 @@ Koron can build <frame> tag.

.. code-block:: python
from korona.html.construct import Frame
from korona.html.tags import Frame
attributes = {'src': 'frame_a.htm', 'scrolling': 'auto', 'marginheight': '250', 'marginwidth': '100', 'name': 'name1', 'longdesc': 'a.txt'}
Expand Down
145 changes: 0 additions & 145 deletions korona/html/construct.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,6 @@
)

from ..templates.html import (
footer_tag,
form_tag,
frame_tag,
frameset_tag,
head_tag,
header_tag,
Expand All @@ -27,148 +24,6 @@
CIRCLE_SHAPE_COORDINATES = 3


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)


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".')


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)


class FrameSet(object):
"""Class for constructing <frameset> tag.
Expand Down
3 changes: 3 additions & 0 deletions korona/html/tags/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,5 +27,8 @@

from .fieldset import FieldSet
from .figure import Figure
from .footer import Footer
from .form import Form
from .frame import Frame

from .heading import H1, H2, H3, H4, H5, H6
22 changes: 22 additions & 0 deletions korona/html/tags/footer.py
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)
74 changes: 74 additions & 0 deletions korona/html/tags/form.py
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".')
60 changes: 60 additions & 0 deletions korona/html/tags/frame.py
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)
17 changes: 17 additions & 0 deletions tests/test_html_tags/test_footer_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 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)
Loading

0 comments on commit fac166e

Please sign in to comment.