Giter Club home page Giter Club logo

stempl's Introduction

stempl

Travis CI status

HTML templates with just Python.

Should I use this?

No. No security concerns were taken into account, this is simply a small pet project.

Installing

Use pip to install the package:

pip install stempl

Example

For more examples checkout the tests file.

from flask import Flask
from stempl import *


app = Flask(__name__)


def render_head():
    with Head() as t:
        t << meta(charset='utf-8')
        t << meta(name='viewport', content='width=device-width, initial-scale=1, shrink-to-fit=no')
        t << title('Hello World')
        t << link(href='https://stackpath.bootstrapcdn.com/bootstrap/4.1.1/css/bootstrap.min.css', rel='stylesheet')
        t << script(src='https://code.jquery.com/jquery-3.3.1.slim.min.js')
        t << script(src='https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.14.3/umd/popper.min.js')
        t << script(src='https://stackpath.bootstrapcdn.com/bootstrap/4.1.1/js/bootstrap.min.js')

    return t()


def render_navbar():
    with Ul(_class='navbar-nav') as u:
        u << li(a('Home', _class='nav-link', href='#'), _class='nav-item active')
        u << li(a('Features', _class='nav-link', href='#'), _class='nav-item active')
        u << li(a('Pricing', _class='nav-link', href='#'), _class='nav-item active')
        u << li(a('Disabled', _class='nav-link disabled', href='#'), _class='nav-item active')

    with Nav(_class='navbar navbar-expand-lg navbar-light bg-light') as n:
        n << a('Navbar', _class='navbar-brand', href='#')
        with Button(_class='navbar-toggler', type='button', data_toggle='collapse', data_target='#navbarNav') as b:
            b << span(_class='navbar-toggler-icon')
        n << b()
        n << div(u(), _class='collapse navbar-collapse', id='navbarNav')

    return n()


def layout(content):
    with Html() as h:
        h << render_head()
        with Body() as b:
            b << render_navbar()
            b << div(content, _class='container', id='main')
        h << b()

    return doctype() + h()


def index_template():
    with Div(id='index-page') as d:
        d << h1('Hello World')

    return layout(d)


@app.route('/', methods=['GET'])
def index():
    return index_template()


if __name__ == '__main__':
    app.run(host='0.0.0.0', port=3000, debug=True)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.