コード例 #1
0
def test_attr_has_attr():
    app = Flask(__name__)
    init_htmlbuilder(app)

    @app.route('/a')
    def view_a():
        g.attrs['description'] = 'A description'
        return render_template()

    @root_block()
    def site_root():
        return [
            html.doctype('html'),
            html.html(
                html.head(
                    html.has_attr('description')(
                        html.meta(content=Attr('description'))),
                    html.has_attr('author')(
                        html.meta(content=Attr('author')))), html.body())
        ]

    client = app.test_client()
    result = client.get('/a')

    assert result.data == """<!doctype html>
コード例 #2
0
def test_deep_inheritance():
    app = Flask(__name__)
    init_htmlbuilder(app)

    @app.route('/a')
    def view_a():
        return render_template()

    @root_block()
    def site_root():
        return [
            html.doctype('html'),
            html.html(
                html.head(),
                html.body(
                    g.blocks['body']
                )
            )
        ]

    @block('body', site_root)
    def site_body():
        return html.div(class_='container')(g.blocks['container'])

    @block('container', site_body)
    def container_body():
        return html.div('Container content.')

    client = app.test_client()
    result = client.get('/a')

    assert result.data.decode('utf-8') == """<!doctype html>
コード例 #3
0
def test_attr_has_attr():
    app = Flask(__name__)
    init_htmlbuilder(app)

    @app.route('/a')
    def view_a():
        g.attrs['description'] = 'A description'
        return render_template()

    @root_block()
    def site_root():
        return [
            html.doctype('html'),
            html.html(
                html.head(
                    html.has_attr('description')(
                        html.meta(content=Attr('description'))
                    ),
                    html.has_attr('author')(
                        html.meta(content=Attr('author'))
                    )
                ),
                html.body()
            )
        ]

    client = app.test_client()
    result = client.get('/a')

    assert result.data.decode('utf-8') == """<!doctype html>
コード例 #4
0
def test_default_block():
    app = Flask(__name__)
    init_htmlbuilder(app)

    @app.route('/a')
    def view_a():
        return render_template()

    @app.route('/b')
    def view_b():
        html.block('title')('New Title')
        return render_template()

    @root_block()
    def site_root():
        return html.title(html.block('title')('Default Title'))

    client = app.test_client()
    result = client.get('/a')
    assert result.data == """<title>
  Default Title
</title>
"""

    result = client.get('/b')
    assert result.data == """<title>
  New Title
</title>
"""

    result = client.get('/a')
    assert result.data == """<title>
コード例 #5
0
def test_html_block_has_block():
    app = Flask(__name__)
    init_htmlbuilder(app)

    @app.route('/a')
    def view_a():
        html.block('container')(html.div('Container content.'))
        return render_template()

    @root_block()
    def site_root():
        return [
            html.doctype('html'),
            html.html(html.head(), html.body(g.blocks['body']))
        ]

    @block('body', site_root)
    def site_body():
        return html.has_block('container')(html.div(class_='container')(
            html.block('container'), html.block('undefined'),
            html.has_block('noblock')(html.p())))

    client = app.test_client()
    result = client.get('/a')

    assert result.data == """<!doctype html>
コード例 #6
0
def test_multiple_contexts():
    app = Flask(__name__)
    init_htmlbuilder(app)

    @app.route('/a')
    def view_a():
        return render_template()

    @root_block()
    def site_root():
        return [
            html.doctype('html'),
            html.html(html.head(html.title(g.blocks['title'])),
                      html.body(g.blocks['body']))
        ]

    @block('body', site_root)
    def site_body():
        return html.p('This is the body.')

    @block('title', site_root)
    def site_title():
        return 'Title'

    client = app.test_client()
    result = client.get('/a')

    assert result.data == """<!doctype html>
コード例 #7
0
def test_alternative_definition():
    app = Flask(__name__)
    init_htmlbuilder(app)

    @app.route('/a')
    def view_a():
        return render_template()

    @app.route('/b')
    def view_b():
        return render_template()

    def site_root():
        return [
            html.doctype('html'),
            html.html(
                html.head(),
                html.body(
                    g.blocks['body']
                )
            )
        ]

    def default_body():
        return html.p('Default body.')

    def view_a_body():
        return html.div(class_='container')(g.blocks['container'])

    def view_a_container():
        return html.div('Container content.')

    RootBlock(site_root)(
        Context('body')(
            Block(default_body),
            Block(view_a_body, view_a)(
                Context('container')(
                    Block(view_a_container)
                )
            )
        )
    )

    client = app.test_client()

    result = client.get('/a')
    assert result.data.decode('utf-8') == """<!doctype html>
<html>
  <head></head>
  <body>
    <div class="container">
      <div>Container content.</div>
    </div>
  </body>
</html>
"""

    result = client.get('/b')
    assert result.data.decode('utf-8') == """<!doctype html>
コード例 #8
0
def test_alternative_definition():
    app = Flask(__name__)
    init_htmlbuilder(app)

    @app.route('/a')
    def view_a():
        return render_template()

    @app.route('/b')
    def view_b():
        return render_template()

    def site_root():
        return [
            html.doctype('html'),
            html.html(html.head(), html.body(g.blocks['body']))
        ]

    def default_body():
        return html.p('Default body.')

    def view_a_body():
        return html.div(class_='container')(g.blocks['container'])

    def view_a_container():
        return html.div('Container content.')

    RootBlock(site_root)(Context('body')(Block(default_body),
                                         Block(view_a_body,
                                               view_a)(Context('container')(
                                                   Block(view_a_container)))))

    client = app.test_client()

    result = client.get('/a')
    assert result.data == """<!doctype html>
<html>
  <head></head>
  <body>
    <div class="container">
      <div>Container content.</div>
    </div>
  </body>
</html>
"""

    result = client.get('/b')
    assert result.data == """<!doctype html>
コード例 #9
0
def test_root_block_decorator():
    app = Flask(__name__)
    init_htmlbuilder(app)

    @app.route('/')
    def return_root():
        g.blocks['body'] = 'Hello, World!'
        return render_template()

    @root_block()
    def site_root():
        return [html.doctype('html'), html.html(html.head(), html.body(g.blocks['body']))]

    client = app.test_client()
    result = client.get('/')
    assert result.mimetype == 'text/html'
    assert result.data.decode('utf-8') == """<!doctype html>
コード例 #10
0
def test_block_decorator():
    app = Flask(__name__)
    init_htmlbuilder(app)
    
    @app.route('/')
    def return_root():
        return render_template()
    
    @root_block()
    def site_root():
        return [html.doctype('html'), html.html(html.head(), html.body(g.blocks['body']))]
    
    @block('body', site_root)
    def site_body():
        return html.p('Hello, World!')
    
    client = app.test_client()
    result = client.get('/')
    assert result.data == """<!doctype html>
コード例 #11
0
def test_root_block_decorator():
    app = Flask(__name__)
    init_htmlbuilder(app)

    @app.route('/')
    def return_root():
        g.blocks['body'] = 'Hello, World!'
        return render_template()

    @root_block()
    def site_root():
        return [
            html.doctype('html'),
            html.html(html.head(), html.body(g.blocks['body']))
        ]

    client = app.test_client()
    result = client.get('/')
    assert result.mimetype == 'text/html'
    assert result.data == """<!doctype html>
コード例 #12
0
def test_default_block():
    app = Flask(__name__)
    init_htmlbuilder(app)

    @app.route('/a')
    def view_a():
        return render_template()

    @app.route('/b')
    def view_b():
        return render_template()

    @root_block()
    def site_root():
        return [
            html.doctype('html'),
            html.html(html.head(), html.body(g.blocks['body']))
        ]

    @block('body', site_root, view_a)
    def view_a_body():
        return html.p('Hello, View A!')

    @block('body', site_root)
    def default_body():
        return html.p('Hello, Default Block!')

    client = app.test_client()

    result = client.get('/a')
    assert result.data == """<!doctype html>
<html>
  <head></head>
  <body>
    <p>Hello, View A!</p>
  </body>
</html>
"""
    result = client.get('/b')
    assert result.data == """<!doctype html>
コード例 #13
0
def test_html_block_has_block():
    app = Flask(__name__)
    init_htmlbuilder(app)
    
    @app.route('/a')
    def view_a():
        html.block('container')(
            html.div('Container content.')
        )
        return render_template()
    
    @root_block()
    def site_root():
        return [
            html.doctype('html'),
            html.html(
                html.head(),
                html.body(
                    g.blocks['body']
                )
            )
        ]
    
    @block('body', site_root)
    def site_body():
        return html.has_block('container')(
            html.div(class_='container')(
                html.block('container'),
                html.block('undefined'),
                html.has_block('noblock')(
                    html.p()
                )
            )
        )
    
    client = app.test_client()
    result = client.get('/a')
    
    assert result.data == """<!doctype html>
コード例 #14
0
def test_default_block():
    app = Flask(__name__)
    init_htmlbuilder(app)

    @app.route('/a')
    def view_a():
        return render_template()

    @app.route('/b')
    def view_b():
        return render_template()

    @root_block()
    def site_root():
        return [html.doctype('html'), html.html(html.head(), html.body(g.blocks['body']))]

    @block('body', site_root, view_a)
    def view_a_body():
        return html.p('Hello, View A!')

    @block('body', site_root)
    def default_body():
        return html.p('Hello, Default Block!')

    client = app.test_client()

    result = client.get('/a')
    assert result.data == """<!doctype html>
<html>
  <head></head>
  <body>
    <p>Hello, View A!</p>
  </body>
</html>
"""
    result = client.get('/b')
    assert result.data == """<!doctype html>
コード例 #15
0
def test_multiple_contexts():
    app = Flask(__name__)
    init_htmlbuilder(app)

    @app.route('/a')
    def view_a():
        return render_template()

    @root_block()
    def site_root():
        return [
            html.doctype('html'),
            html.html(
                html.head(
                    html.title(
                        g.blocks['title']
                    )
                ),
                html.body(
                    g.blocks['body']
                )
            )
        ]

    @block('body', site_root)
    def site_body():
        return html.p('This is the body.')

    @block('title', site_root)
    def site_title():
        return 'Title'

    client = app.test_client()
    result = client.get('/a')

    assert result.data.decode('utf-8') == """<!doctype html>
コード例 #16
0
def test_default_block():
    app = Flask(__name__)
    init_htmlbuilder(app)

    @app.route('/a')
    def view_a():
        return render_template()

    @app.route('/b')
    def view_b():
        html.block('title')('New Title')
        return render_template()

    @root_block()
    def site_root():
        return html.title(
            html.block('title')(
                'Default Title'
            )
        )

    client = app.test_client()
    result = client.get('/a')
    assert result.data.decode('utf-8') == """<title>
  Default Title
</title>
"""

    result = client.get('/b')
    assert result.data.decode('utf-8') == """<title>
  New Title
</title>
"""

    result = client.get('/a')
    assert result.data.decode('utf-8') == """<title>
コード例 #17
0
from flask import Flask

from flaskext.htmlbuilder import init_htmlbuilder, html, render_template, \
     render, Attr, root_block, block

from html5boilerplate import html5_boilerplate

app = Flask(__name__)
init_htmlbuilder(app)


@app.route('/')
def index():
    html.block('title')('Element Consistency Tests')
    return render_template()


@root_block()
def html5_root():
    return html5_boilerplate()


@block('main', html5_root)
def body_main():
    return [
        html.comment("""
            demo content lovingly lifted from the azbuka project 
            http://code.google.com/p/azbuka/ 
                 
            and the bluetrip project
            http://bluetrip.org/  
コード例 #18
0
from flask import Flask

from flaskext.htmlbuilder import init_htmlbuilder, html, render_template, \
     render, Attr, root_block, block

from html5boilerplate import html5_boilerplate


app = Flask(__name__)
init_htmlbuilder(app)


@app.route('/')
def index():
    html.block('title')(
        'Element Consistency Tests'
    )
    return render_template()


@root_block()
def html5_root():
    return html5_boilerplate()


@block('main', html5_root)
def body_main():
    return [
        html.comment("""
            demo content lovingly lifted from the azbuka project 
            http://code.google.com/p/azbuka/