コード例 #1
0
def nav_links_new():
    nav_groups = (
        ('Basics', (
            ('/docs/basics/installation', 'Installation'),
            ('/docs/basics/syntax', 'Syntax'),
            ('/docs/basics/templating', 'Templating'),
            ('/docs/basics/utilities', 'Utilities'),
        )),
        ('Common Patterns', (
            ('/docs/patterns/abstraction', 'Abstractions'),
            ('/docs/patterns/composition', 'Composition'),
            ('/docs/patterns/reusability', 'Reusability'),
        )),
        ('Integrations', (('/docs/integrations/flask', 'Flask'), )),
    )

    tmpl = Template()
    nav = tmpl.ul(_class='list-unstyled')
    nav.li.a(href=url('/')) + 'Funky Bomb'

    for name, links in nav_groups:
        nav.li.p(_class='mt-3 mb-1') + name
        for u, text in links:
            nav.li.a(href=url(u)) + text

    nav.li.p(_class='mt-3 mb-1') + 'Other'
    nav.li.a(href='https://github.com/glennyonemitsu/funkybomb') + 'GitHub'

    return tmpl
コード例 #2
0
def nav_links(current_url, links):
    tmpl = Template()
    nav = tmpl.ul(_class='list-unstyled')
    for href, text, children in links:
        nav_item = nav.li()
        _class = ''
        if url == current_url:
            _class += 'active'
        nav_item.a(_class=_class, href=url(href)) + text
        if children:
            nav_item = nav.li()
            nav_item + nav_links(current_url, children)
    return nav
コード例 #3
0
ファイル: general.py プロジェクト: glennyonemitsu/funkybomb
async def docs_home(req):
    tmpl = Template()
    tmpl.p + 'Coming soon'

    return {
        'content': tmpl,
        'headline': Text('Docs')
    }
コード例 #4
0
async def docs_patterns_home(req):
    tmpl = Template()
    tmpl.p + 'Coming soon.'

    return {
        'content': tmpl,
        'headline': Text('Common Patterns')
    }
コード例 #5
0
async def docs_patterns_abstraction(req):
    tmpl = Template()
    tmpl.p + 'Coming soon.'

    return {
        'content': tmpl,
        'headline': Text('Abstraction')
    }
コード例 #6
0
async def docs_patterns_reusability(req):
    tmpl = Template()
    tmpl.p + 'Coming soon.'

    return {
        'content': tmpl,
        'headline': Text('Reusability')
    }
コード例 #7
0
async def docs_integrations_home(req):
    tmpl = Template()
    tmpl.p + 'Coming soon.'

    return {'content': tmpl, 'headline': Text('Integrations')}
コード例 #8
0
async def docs_integrations_flask(req):
    tmpl = Template()
    tmpl.p + 'Coming soon.'

    return {'content': tmpl, 'headline': Text('Integrating with Flask')}
コード例 #9
0
from copy import deepcopy

from funkybomb import freeze, Template

from templates import base
from templates.util import row_cols

tmpl = deepcopy(base.tmpl)

content = Template()
sidebar, main = row_cols(content, 2, 10)

# components - header nav
nav = sidebar.div(_class='mt-3 nav-links')
nav + Template('nav links')

# components - content
main.h1(_class='mt-2 mb-5') + Template('headline')
main.div + Template('content')

tmpl['base main'] = content
freeze(tmpl)
コード例 #10
0
ファイル: base.py プロジェクト: glennyonemitsu/funkybomb
from funkybomb import Template
from pygments.formatters import HtmlFormatter

from templates.util import row_cols

tmpl = Template()
tmpl + '<!DOCTYPE html>'
html = tmpl.html

# head
head = html.head
head.meta(charset='utf-8')

styles = ("https://maxcdn.bootstrapcdn.com/bootstrap/"
          "4.0.0-alpha.6/css/bootstrap.min.css", )

for style in styles:
    head.link(rel="stylesheet", href=style, crossorigin="anonymous")
head.style + HtmlFormatter(style='colorful').get_style_defs('.highlight')
head.style + '''
.nav-links ul { margin-left: 0;}
.nav-links ul ul { margin-left: 1.2rem;}
.highlight { padding: 1.4rem; background-color: #f2f2f2; }
.highlight pre { margin: 0 }
'''

scripts = (
    "https://code.jquery.com/jquery-3.1.1.slim.min.js",
    "https://cdnjs.cloudflare.com/ajax/libs/tether/1.4.0/js/tether.min.js",
    "https://maxcdn.bootstrapcdn.com/bootstrap/"
    "4.0.0-alpha.6/js/bootstrap.min.js",
コード例 #11
0
ファイル: general.py プロジェクト: glennyonemitsu/funkybomb
async def home(req):
    followups = []
    followups.append({
        'header': 'It is easy to use',
        'content': (
            'Funky Bomb has a small set of rules to build out DOM-like '
            'structures and reusable templates with native Python.'
        ),
        'links': (
            ('Learn more:',),
            ('Syntax', '/docs/basics/syntax'),
            ('Templating', '/docs/basics/templating'),
            ('Utilities', '/docs/basics/utilities'),
        )
    })

    followups.append({
        'header': 'Use Python syntax and patterns',
        'content': (
            'Use normal programming patterns to build abstractions and '
            'construct more advanced HTML with the power of Python.'
        ),
        'links': (
            ('Common patterns:',),
            ('Abstraction', '/docs/patterns/abstraction'),
            ('Composition', '/docs/patterns/composition'),
            ('Reusability', '/docs/patterns/reusability'),
        )
    })

    followups.append({
        'header': 'Easy integration',
        'content': (
            'Any web framework that uses strings for serving HTML can have '
            'Funky Bomb integrated, since Funky Bomb outputs HTML strings '
            'itself.'
        ),
        'links': (
            ('Examples:',),
            ('Flask', '/docs/integrations/flask'),
        )
    })

    example_funky = show_python('''
    from funkybomb import render, Template
    from models import user_model

    tmpl = Template()
    table = tmpl.table

    for user in user_model.get_all():
        row = table.tr
        row.td + user.first_name
        row.td + user.last_name

    print(render(tmpl))
    ''')

    example_html = show_html('''
    <table>
        <tr>
            <td>John</td>
            <td>Doe</td>
        </tr>
        <tr>
            <td>Jane</td>
            <td>Doe</td>
        </tr>
    </table>
    ''')

    content = Template()

    pitch_python, pitch_html = row_cols(content, 6, 6)

    pitch_python.p(_class='h5') + 'Use Native Python'
    pitch_python + example_funky

    pitch_html.p(_class='h5') + 'Create HTML Pages'
    pitch_html + example_html

    fu = row_cols(content)

    fu.p(_class='lead mt-5 mb-5') + \
        'That is it! No other HTML template or code involved.'

    for item in followups:
        fu.p(_class='h4 mt-5') + item['header']
        fu.p + item['content']
        fu_links = fu.p

        for i, link in enumerate(item['links']):
            if i == 0:
                fu_links + (link[0] + ' ')
            else:
                fu_links.a(href=url(link[1])) + link[0]
                if i < (len(item['links']) - 1):
                    fu_links + ', '

    return {
        'content': content,
        'headline': Text('Funky Bomb')
    }
コード例 #12
0
def p(*texts):
    tmpl = Template()
    for p in texts:
        tmpl.p + html.escape(p)
    return tmpl
コード例 #13
0
ファイル: home.py プロジェクト: glennyonemitsu/funkybomb
from funkybomb import Template

tmpl = Template()

intro = tmpl.p(_class='lead')
intro + 'This is a thing'