Example #1
0
def test_head_render_render4():
    """ XHTML namespace unit test - HeadRender - Render - call render two times with css_url method"""
    h = xhtml.HeadRenderer('/tmp/static_directory/')
    h << h.css_url('css')
    presentation.render(h, None, None, None)
    renderResult = presentation.render(h, None, None, None)
    assert not isinstance(renderResult, ListType)
    assert c14n(presentation.render(h, None, None, None)) == c14n('<head><link href="/tmp/static_directory/css" type="text/css" rel="stylesheet"/></head>')
Example #2
0
def head_render_render_test4():
    """ XHTML namespace unit test - HeadRender - Render - call render two times with css_url method"""
    h = xhtml.HeadRenderer('/tmp/static_directory/')
    h << h.css_url('css')
    presentation.render(h, None, None, None)
    renderResult = presentation.render(h, None, None, None)
    assert not isinstance(renderResult, ListType)
    assert presentation.render(h, None, None, None).write_htmlstring().replace('\n', '') == '<head><link href="/tmp/static_directory/css" type="text/css" rel="stylesheet"></head>'
Example #3
0
def test_head_render_render4():
    """ XHTML namespace unit test - HeadRender - Render - call render two times with css_url method"""
    h = xhtml.HeadRenderer('/tmp/static_directory/')
    h << h.css_url('css')
    presentation.render(h, None, None, None)
    renderResult = presentation.render(h, None, None, None)
    assert not isinstance(renderResult, ListType)
    assert c14n(presentation.render(h, None, None, None)) == c14n(
        '<head><link href="/tmp/static_directory/css" type="text/css" rel="stylesheet"/></head>'
    )
Example #4
0
def test_head_render_render2():
    """ XHTML namespace unit test - HeadRender - Render - render only css_url method """
    h = xhtml.HeadRenderer('/tmp/static_directory/')
    h << h.css_url('css')
    assert c14n(presentation.render(h, None, None, None)) == c14n(
        '<head><link href="/tmp/static_directory/css" type="text/css" rel="stylesheet"/></head>'
    )
Example #5
0
def test_head_render_render5():
    """ XHTML namespace unit test - HeadRender - Render - render only css method """
    h = xhtml.HeadRenderer('/tmp/static_directory/')
    h << h.css('css_test', 'test')
    assert c14n(presentation.render(
        h, None, None,
        None)) == c14n('<head><style type="text/css">test</style></head>')
Example #6
0
def test_head_render_render6():
    """ XHTML namespace unit test - HeadRender - Render - render only javascript_url method """
    h = xhtml.HeadRenderer('/tmp/static_directory/')
    h << h.javascript_url('test.js')
    assert c14n(presentation.render(h, None, None, None)) == c14n(
        '<head><script src="/tmp/static_directory/test.js" type="text/javascript"></script></head>'
    )
Example #7
0
def test_head_render_render7():
    """ XHTML namespace unit test - HeadRender - Render - render only string js method """
    h = xhtml.HeadRenderer('/tmp/static_directory/')
    h << h.javascript('test.js', 'function test() { return True }')
    assert c14n(presentation.render(h, None, None, None)) == c14n(
        '<head><script type="text/javascript">function test() { return True }</script></head>'
    )
Example #8
0
def test_head_render_render10():
    """ XHTML namespace unit test - HeadRender - Render - render with head & style """
    h = xhtml.HeadRenderer('/tmp/static_directory/')
    with h.head({'id': 'id'}):
        h << h.style('test', {'id': 'id'})
    assert c14n(presentation.render(
        h, None, None,
        None)) == c14n('<head id="id"><style id="id">test</style></head>')
Example #9
0
def test_head_render_render8():
    """ XHTML namespace unit test - HeadRender - Render - render only python2js method """

    def js_method(arg1):
        return True

    h = xhtml.HeadRenderer('/tmp/static_directory/')
    with h.head({'lang': 'lang', 'dir': 'dir', 'id': 'id', 'profile': 'profile'}):
        h << h.javascript('test', js_method)
    assert c14n(presentation.render(h, None, None, None)) == c14n('<head lang="lang" profile="profile" id="id" dir="dir"><script src="/static/nagare/pyjslib.js" type="text/javascript"></script><script type="text/javascript">function nagare_namespaces_test_test_xhtmlns_js_method(arg1) {    return true;}</script></head>')
Example #10
0
def wrap(content_type, h, content):
    """Add the tags ``<html>``, ``<head>`` and ``<body>`` is they don't exist

    In:
      - ``content_type`` -- the content type to send to the browser
      - ``h`` -- the current renderer
      - ``content`` -- the rendered tree

    Return:
      - new tree with ``<html>``, ``<head>`` and ``<body>``
    """
    if 'html' not in content_type:
        return content

    if h.response.xml_output:
        h.namespaces = {None: 'http://www.w3.org/1999/xhtml'}

    if not isinstance(content, (list, tuple, types.GeneratorType)):
        content = [content]

    i, html = search_element('html', content)
    if html is None:
        html = content

    j, head = search_element('head', html)
    _, body = search_element('body', html[j:])

    if body is None:
        # No ``<body>`` found, add it
        html[j:] = [h.body(html[j:])]

    if head is None:
        # No ``<head>`` found, add it
        head = h.head.head
        html.insert(0, head)

    if i == 0:
        # No ``<html>`` found, add it
        content = h.html(content)

    head1 = presentation.render(h.head, None, None,
                                None)  # The automatically generated ``<head>``

    url = h.request.upath_info.strip('/')
    if url and not head1.xpath('./link[@rel="canonical"]'):
        head1.append(
            h.head.link(rel='canonical',
                        href=h.request.uscript_name + '/' + url))

    # Merge the attributes and child of the automatically generated ``<head>``
    head.attrib.update(head1.attrib.items())
    head.add_child(head1[:])

    return content
Example #11
0
def wrap(content_type, h, content):
    """Add the tags ``<html>``, ``<head>`` and ``<body>`` is they don't exist

    In:
      - ``content_type`` -- the content type to send to the browser
      - ``h`` -- the current renderer
      - ``content`` -- the rendered tree

    Return:
      - new tree with ``<html>``, ``<head>`` and ``<body>``
    """
    if 'html' not in content_type:
        return content

    if h.response.xml_output:
        h.namespaces = {None: 'http://www.w3.org/1999/xhtml'}

    if not isinstance(content, (list, tuple, types.GeneratorType)):
        content = [content]

    i, html = search_element('html', content)
    if html is None:
        html = content

    j, head = search_element('head', html)
    _, body = search_element('body', html[j:])

    if body is None:
        # No ``<body>`` found, add it
        html[j:] = [h.body(html[j:])]

    if head is None:
        # No ``<head>`` found, add it
        head = h.head.head
        html.insert(0, head)

    if i == 0:
        # No ``<html>`` found, add it
        content = h.html(content)

    head1 = presentation.render(h.head, None, None, None)  # The automatically generated ``<head>``

    url = h.request.upath_info.strip('/')
    if url and not head1.xpath('./link[@rel="canonical"]'):
        head1.append(h.head.link(rel='canonical', href=h.request.uscript_name + '/' + url))

    # Merge the attributes and child of the automatically generated ``<head>``
    head.attrib.update(head1.attrib.items())
    head.add_child(head1[:])

    return content
Example #12
0
def test_head_render_render8():
    """ XHTML namespace unit test - HeadRender - Render - render only python2js method """
    def js_method(arg1):
        return True

    h = xhtml.HeadRenderer('/tmp/static_directory/')
    with h.head({
            'lang': 'lang',
            'dir': 'dir',
            'id': 'id',
            'profile': 'profile'
    }):
        h << h.javascript('test', js_method)
    assert c14n(presentation.render(h, None, None, None)) == c14n(
        '<head lang="lang" profile="profile" id="id" dir="dir"><script src="/static/nagare/pyjslib.js" type="text/javascript"></script><script type="text/javascript">function nagare_namespaces_test_test_xhtmlns_js_method(arg1) {    return true;}</script></head>'
    )
Example #13
0
def serialize(self, content_type, doctype, declaration):
    """Wrap a view into a javascript code

    In:
      - ``content_type`` -- the rendered content type
      - ``doctype`` -- the (optional) doctype
      - ``declaration`` -- is the XML declaration to be outputed?

    Return:
      - a tuple ('text/plain', Javascript to evaluate on the client)
    """
    if self.output is None:
        return 'text/plain', ''

    # Get the javascript for the header
    head = presentation.render(self.renderer.head, self.renderer, None, None)

    # Wrap the body and the header into a javascript code
    return 'text/plain', serialize_body(self, content_type, doctype) + '; ' + head
Example #14
0
def render(self, renderer, comp, model):
    """Rendering of a ``Component``

    In:
      - ``renderer`` -- the renderer
      - ``comp`` -- the component
      - ``model`` -- the name of the view

    Return:
      - the view of the component object
    """
    renderer = renderer.new()   # Create a new renderer of the same class than the current renderer
    renderer.start_rendering(self, model)

    if model == 0:
        model = self.model

    output = presentation.render(self(), renderer, self, model)
    return renderer.end_rendering(output)
Example #15
0
def serialize(self, content_type, doctype, declaration):
    """Wrap a view into a javascript code

    In:
      - ``content_type`` -- the rendered content type
      - ``doctype`` -- the (optional) doctype
      - ``declaration`` -- is the XML declaration to be outputed?

    Return:
      - a tuple ('text/plain', Javascript to evaluate on the client)
    """
    if self.output is None:
        return ('text/plain', '')

    # Get the javascript for the header
    head = presentation.render(self.renderer.head, self.renderer, None, None)

    # Wrap the body and the header into a javascript code
    return ('text/plain', serialize_body(self, content_type, doctype) + '; ' + head)
Example #16
0
File: top.py Project: apoirier/test
def wrap(content_type, h, body):
    """Add the tags is they don't exist or merge them into the existing ones

    In:
      - ``content_type`` -- the content type to send to the browser
      - ``h`` -- the current renderer
      - ``body`` -- the rendered tree

    Return:
      - new tree with ``<html>``, ``<head>`` and ``<body>``
    """
    if 'html' in content_type:
        # Add the tags only for a (x)html content

        if not isinstance(body, xhtml_base._HTMLTag) or not body.tag.endswith('html'):
            # No ``<html>`` found, add it
            if h.response.xml_output:
                h.namespaces = { None : 'http://www.w3.org/1999/xhtml' }

            if not isinstance(body, xhtml_base._HTMLTag) or not body.tag.endswith('body'):
                # No ``<body>`` found, add it
                body = h.body(body)
            body = h.html(body)

        head1 = presentation.render(h.head, None, None, None) # The automatically generated ``<head>``

        url = h.request.path_info.strip('/')
        if url:
            head1.append(h.head.link(rel='canonical', href=h.request.script_name+'/'+url))

        head2 = body[0]

        if not head2.tag.endswith('head'):
            # No ``<head>`` found, add the automatically generated ``<head>``
            body.insert(0, head1)
        else:
            # ``<head>`` found, merge the attributes and child of the automatically
            # generated ``<head>`` to it
            head2.attrib.update(head1.attrib.items())
            head2.add_child(head1[:])

    return body
Example #17
0
def serialize_views(self, content_type, doctype, declaration):
    """Wrap a view into a javascript code

    In:
      - ``content_type`` -- the rendered content type
      - ``doctype`` -- the (optional) doctype
      - ``declaration`` -- is the XML declaration to be outputed?

    Return:
      - a tuple ('text/plain', Javascript to evaluate on the client)
    """
    bodies = [serialize_body(view_to_js, content_type, doctype) for view_to_js in self if view_to_js.output is not None]

    if not bodies:
        return 'text/plain', ''

    # Get the javascript for the header
    head = presentation.render(self[0].renderer.head, self[0].renderer, None, None)

    return 'text/plain', '; '.join(bodies) + '; ' + head
Example #18
0
def render(self, renderer, comp, model):
    """Rendering of a ``Component``

    In:
      - ``renderer`` -- the renderer
      - ``comp`` -- the component
      - ``model`` -- the name of the view

    Return:
      - the view of the component object
    """
    renderer = renderer.new(
    )  # Create a new renderer of the same class than the current renderer
    renderer.start_rendering(self, model)

    if model == 0:
        model = self.model

    output = presentation.render(self(), renderer, self, model)
    return renderer.end_rendering(output)
Example #19
0
def serialize(self, content_type, doctype, declaration):
    """Wrap a view into a javascript code

    In:
      - ``content_type`` -- the rendered content type
      - ``doctype`` -- the (optional) doctype
      - ``declaration`` -- is the XML declaration to be outputed?

    Return:
      - a tuple ('text/plain', Javascript to evaluate on the client)
    """
    bodies = [serialize_body(view_to_js, content_type, doctype) for view_to_js in self if view_to_js.output is not None]

    if not bodies:
        return ('text/plain', '')

    # Get the javascript for the header
    head = presentation.render(self[0].renderer.head, self[0].renderer, None, None)

    return ('text/plain', '; '.join(bodies) + '; ' + head)
Example #20
0
def head_render_render_test7():
    """ XHTML namespace unit test - HeadRender - Render - render only string js method """
    h = xhtml.HeadRenderer('/tmp/static_directory/')
    h << h.javascript('test.js', 'function test() { return True }')
    assert presentation.render(h, None, None, None).write_htmlstring().replace('\n', '') == '<head><script type="text/javascript">function test() { return True }</script></head>'
Example #21
0
    h = Renderer()

    h.head << h.head.title('A test')
    h.head << h.head.javascript('__foo__', 'function() {}')
    h.head << h.head.meta(name='meta1', content='content1')

    with h.body(onload='javascript:alert()'):
        with h.ul:
            with h.li('Hello'): pass
            with h.li:
                h << 'world'
            h << h.li('yeah')

        with h.div(class_='foo'):
            with h.h1('moi'):
                h << h.i('foo')

        with h.div:
            h << 'yeah'
            for i in range(3):
                h << i

        with h.table(foo='foo'):
            for row in t:
                with h.tr:
                    for column in row:
                        with h.td:
                            h << column

    print h.html(presentation.render(h.head, None, None, None), h.root).write_htmlstring(pretty_print=True)
Example #22
0
def render_task(self, renderer, comp, *args):
    return presentation.render(self._go, renderer, comp, *args)
Example #23
0
def head_render_render_test5():
    """ XHTML namespace unit test - HeadRender - Render - render only css method """
    h = xhtml.HeadRenderer('/tmp/static_directory/')
    h << h.css('css_test', 'test')
    assert presentation.render(h, None, None, None).write_htmlstring().replace('\n', '') == '<head><style type="text/css">test</style></head>'
Example #24
0
def render(self, renderer, comp, *args):
    return presentation.render(self._go, renderer, comp, *args)
Example #25
0
        h << h.keygen
        h << h.output

        with h.ul:
            with h.li('Hello'):
                pass
            with h.li:
                h << 'world'
            h << h.li('yeah')

        with h.div(class_='foo'):
            with h.h1('moi'):
                h << h.i('foo')

        with h.div:
            h << 'yeah'
            for i in range(3):
                h << i

        with h.table(foo='foo'):
            for row in t:
                with h.tr:
                    for column in row:
                        with h.td:
                            h << column

        with h.form:
            h << h.input(type='url')

    print h.html(presentation.render(h.head, None, None, None), h.root).write_htmlstring(pretty_print=True)
Example #26
0
def test_head_render_render1():
    """ XHTML namespace unit test - HeadRender - Render - render only style tag """
    h = xhtml.HeadRenderer('/tmp/static_directory/')
    h << h.style()
    assert c14n(presentation.render(h, None, None, None)) == c14n('<head><style></style></head>')
Example #27
0
def test_head_render_render7():
    """ XHTML namespace unit test - HeadRender - Render - render only string js method """
    h = xhtml.HeadRenderer('/tmp/static_directory/')
    h << h.javascript('test.js', 'function test() { return True }')
    assert c14n(presentation.render(h, None, None, None)) == c14n('<head><script type="text/javascript">function test() { return True }</script></head>')
Example #28
0
def head_render_render_test2():
    """ XHTML namespace unit test - HeadRender - Render - render only css_url method """
    h = xhtml.HeadRenderer('/tmp/static_directory/')
    h << h.css_url('css')
    assert presentation.render(h, None, None, None).write_htmlstring().replace('\n', '') == '<head><link href="/tmp/static_directory/css" type="text/css" rel="stylesheet"></head>'
Example #29
0
def test_head_render_render9():
    """ XHTML namespace unit test - HeadRender - Render - render with head """
    h = xhtml.HeadRenderer('/tmp/static_directory/')
    h << h.head({'id': 'id'})
    assert c14n(presentation.render(h, None, None,
                                    None)) == c14n('<head id="id"></head>')
Example #30
0
    h.head << h.head.title('A test')
    h.head << h.head.javascript('__foo__', 'function() {}')
    h.head << h.head.meta(name='meta1', content='content1')

    with h.body(onload='javascript:alert()'):
        with h.ul:
            with h.li('Hello'):
                pass
            with h.li:
                h << 'world'
            h << h.li('yeah')

        with h.div(class_='foo'):
            with h.h1('moi'):
                h << h.i('foo')

        with h.div:
            h << 'yeah'
            for i in range(3):
                h << i

        with h.table(foo='foo'):
            for row in t:
                with h.tr:
                    for column in row:
                        with h.td:
                            h << column

    print h.html(presentation.render(h.head, None, None, None),
                 h.root).write_htmlstring(pretty_print=True)
Example #31
0
def test_head_render_render2():
    """ XHTML namespace unit test - HeadRender - Render - render only css_url method """
    h = xhtml.HeadRenderer('/tmp/static_directory/')
    h << h.css_url('css')
    assert c14n(presentation.render(h, None, None, None)) == c14n('<head><link href="/tmp/static_directory/css" type="text/css" rel="stylesheet"/></head>')
Example #32
0
def test_head_render_render1():
    """ XHTML namespace unit test - HeadRender - Render - render only style tag """
    h = xhtml.HeadRenderer('/tmp/static_directory/')
    h << h.style()
    assert c14n(presentation.render(
        h, None, None, None)) == c14n('<head><style></style></head>')
Example #33
0
    def render(self, renderer, model=0):
        """Rendering method of a component

        Forward the call to the generic method of the ``presentation`` service
        """
        return presentation.render(self, renderer, self, model)
Example #34
0
def head_render_render_test10():
    """ XHTML namespace unit test - HeadRender - Render - render with head & style """
    h = xhtml.HeadRenderer('/tmp/static_directory/')
    with h.head({'id':'id'}):
        h << h.style('test', {'id':'id'})
    assert presentation.render(h, None, None, None).write_htmlstring().replace('\n', '') == '<head id="id"><style id="id">test</style></head>'
Example #35
0
def test_head_render_render9():
    """ XHTML namespace unit test - HeadRender - Render - render with head """
    h = xhtml.HeadRenderer('/tmp/static_directory/')
    h << h.head({'id': 'id'})
    assert c14n(presentation.render(h, None, None, None)) == c14n('<head id="id"></head>')
Example #36
0
def head_render_render_test6():
    """ XHTML namespace unit test - HeadRender - Render - render only javascript_url method """
    h = xhtml.HeadRenderer('/tmp/static_directory/')
    h << h.javascript_url('test.js')
    assert presentation.render(h, None, None, None).write_htmlstring().replace('\n', '') == '<head><script src="/tmp/static_directory/test.js" type="text/javascript"></script></head>'
Example #37
0
def test_head_render_render10():
    """ XHTML namespace unit test - HeadRender - Render - render with head & style """
    h = xhtml.HeadRenderer('/tmp/static_directory/')
    with h.head({'id': 'id'}):
        h << h.style('test', {'id': 'id'})
    assert c14n(presentation.render(h, None, None, None)) == c14n('<head id="id"><style id="id">test</style></head>')
Example #38
0
def test_head_render_render5():
    """ XHTML namespace unit test - HeadRender - Render - render only css method """
    h = xhtml.HeadRenderer('/tmp/static_directory/')
    h << h.css('css_test', 'test')
    assert c14n(presentation.render(h, None, None, None)) == c14n('<head><style type="text/css">test</style></head>')
Example #39
0
    def render(self, renderer, model=0):
        """Rendering method of a component

        Forward the call to the generic method of the ``presentation`` service
        """
        return presentation.render(self, renderer, self, model)
Example #40
0
def test_head_render_render6():
    """ XHTML namespace unit test - HeadRender - Render - render only javascript_url method """
    h = xhtml.HeadRenderer('/tmp/static_directory/')
    h << h.javascript_url('test.js')
    assert c14n(presentation.render(h, None, None, None)) == c14n('<head><script src="/tmp/static_directory/test.js" type="text/javascript"></script></head>')
Example #41
0
def head_render_render_test1():
    """ XHTML namespace unit test - HeadRender - Render - render only style tag """
    h = xhtml.HeadRenderer('/tmp/static_directory/')
    h << h.style()
    assert presentation.render(h, None, None, None).write_htmlstring().replace('\n', '') == '<head><style></style></head>'