Skip to content

Commit

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


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


Expand Down Expand Up @@ -138,11 +138,11 @@ API Reference
:members:


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


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


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

.. code-block:: python
from korona.html.construct import FrameSet
from korona.html.tags import FrameSet
attributes = {'cols': '25%'}
Expand Down Expand Up @@ -882,7 +882,7 @@ Korona can help you build ``<head>`` tag.

.. code-block:: python
from korona.html.construct import Head
from korona.html.tags import Head
attributes = {'text': 'abcd'}
Expand All @@ -906,7 +906,7 @@ Korona can help you build <header> tag.

.. code-block:: python
from korona.html.construct import Header
from korona.html.tags import Header
attributes = {'text': 'abc'}
Expand Down
58 changes: 0 additions & 58 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 (
frameset_tag,
head_tag,
header_tag,
hr_tag,
html_tag,
italics_tag,
Expand All @@ -24,61 +21,6 @@
CIRCLE_SHAPE_COORDINATES = 3


class FrameSet(object):
"""Class for constructing <frameset> tag.
Args:
cols (str): Specifies the number and size of columns in a frameset.
rows (str): Specifies the number and size of rows in a frameset.
.. versionadded:: 0.2.0
"""
def __init__(self, cols=None, rows=None):
self.tag = 'frameset'
self.values = {'cols': cols, 'rows': rows}

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


class Head(object):
"""Class for constructing <head> tag.
Args:
text (str): Specifies the head text. (As in <head>{text}</head>)
.. versionadded:: 0.3.0
"""
def __init__(self, text=None):
# TODO: Add the ability to validate which inner tags can go into the
# <head> tag.
self.tag = 'head'
self.values = {'text': text}

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


class Header(object):
"""Class for constructing the header tag.
Args:
text (str): Specifies the header text. (As in <header>{text}</header>)
.. versionadded:: 0.3.0
"""
def __init__(self, text=None):
# TODO: Add support for inner tags.
self.tag = 'header'
self.values = {'text': text}

def construct(self):
"""Returns the constructed header tag <header></header>."""
return header_tag.render(self.values)


class HR(object):
"""Class for constructing hr 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 @@ -30,5 +30,9 @@
from .footer import Footer
from .form import Form
from .frame import Frame
from .frameset import FrameSet

from .head import Head
from .header import Header

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

from ...templates.html.tags import frameset_tag


class FrameSet(object):
"""Class for constructing <frameset> tag.
Args:
cols (str): Specifies the number and size of columns in a frameset.
rows (str): Specifies the number and size of rows in a frameset.
.. versionadded:: 0.2.0
"""
def __init__(self, cols=None, rows=None):
self.tag = 'frameset'
self.values = {'cols': cols, 'rows': rows}

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

from ...templates.html.tags import head_tag


class Head(object):
"""Class for constructing <head> tag.
Args:
text (str): Specifies the head text. (As in <head>{text}</head>)
.. versionadded:: 0.3.0
"""
def __init__(self, text=None):
# TODO: Add the ability to validate which inner tags can go into the
# <head> tag.
self.tag = 'head'
self.values = {'text': text}

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

from ...templates.html.tags import header_tag


class Header(object):
"""Class for constructing the header tag.
Args:
text (str): Specifies the header text. (As in <header>{text}</header>)
.. versionadded:: 0.3.0
"""
def __init__(self, text=None):
# TODO: Add support for inner tags.
self.tag = 'header'
self.values = {'text': text}

def construct(self):
"""Returns the constructed header tag <header></header>."""
return header_tag.render(self.values)
18 changes: 18 additions & 0 deletions tests/test_html_tags/test_frameset_tag.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
# -*- coding: utf-8 -*-

from ..fixtures import parametrize

from korona.html.tags import FrameSet
from korona.templates.html.tags import frameset_tag


@parametrize('attributes', [
({'cols': '25%'}),
({'rows': '50%'})
])
def test_construct_frameset_tag(attributes):
"""Test for validating whether the frameset tag is constructed correctly or
not.
"""
frameset = FrameSet(**attributes)
assert frameset.construct() == frameset_tag.render(attributes)
17 changes: 17 additions & 0 deletions tests/test_html_tags/test_head_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 Head
from korona.templates.html.tags import head_tag


@parametrize('attributes', [
({'text': 'abcd'})
])
def test_construct_head_tag(attributes):
"""Test for validating whether the head tag is constructed correctly or
not.
"""
head = Head(**attributes)
assert head.construct() == head_tag.render(attributes)
17 changes: 17 additions & 0 deletions tests/test_html_tags/test_header_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 Header
from korona.templates.html.tags import header_tag


@parametrize('attributes', [
({'text': 'abcd'})
])
def test_construct_header_tag(attributes):
"""Test for validating whether the header tag is constructed correctly or
not.
"""
header = Header(**attributes)
assert header.construct() == header_tag.render(attributes)
40 changes: 0 additions & 40 deletions tests/test_tags.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,19 +3,13 @@
import pytest

from korona.html.construct import (
FrameSet,
Head,
Header,
HR,
Html,
I,
IFrame,
Img
)
from korona.templates.html import (
frameset_tag,
head_tag,
header_tag,
hr_tag,
html_tag,
italics_tag,
Expand All @@ -39,40 +33,6 @@ def test_validate_invalid_tags(tag, error, error_msg):
assert error_msg in str(exc)


@parametrize('attributes', [
({'cols': '25%'}),
({'rows': '50%'})
])
def test_construct_frameset_tag(attributes):
"""Test for validating whether the frameset tag is constructed correctly or
not.
"""
frameset = FrameSet(**attributes)
assert frameset.construct() == frameset_tag.render(attributes)


@parametrize('attributes', [
({'text': 'abcd'})
])
def test_construct_head_tag(attributes):
"""Test for validating whether the head tag is constructed correctly or
not.
"""
head = Head(**attributes)
assert head.construct() == head_tag.render(attributes)


@parametrize('attributes', [
({'text': 'abcd'})
])
def test_construct_header_tag(attributes):
"""Test for validating whether the header tag is constructed correctly or
not.
"""
header = Header(**attributes)
assert header.construct() == header_tag.render(attributes)


@parametrize('attributes', [
({'align': 'left', 'width': '50%'}),
({'align': 'center', 'size': '100'}),
Expand Down

0 comments on commit 41439ce

Please sign in to comment.