rancorm / hip-flask

Lightweight Flask extension to simplify the integration of CSS and JavaScript files into your applications

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

hip-flask

Hip flask

Lightweight Flask extension to simplify the integration of CSS and JavaScript files into your applications.

Start here

Install the extension:

pip install hip-flask

Considering the minimal flask application factory below in hipapp.py as an example:

from flask import Flask
from hip_flask import HipExtension

def create_app():
    app = Flask(__name__)

    hip = HipExtension(app)

    # Meta tags
    hip.meta(charset=hip.Meta.CHARSET)
    hip.meta(name="description", content="Timeline event tracker")
    hip.meta(name="keywords", content=["HTML", "CSS", "JavaScript"])
    
    # Stylesheets
    hip.static_link("css/hipapp.css")

    # Scripts
    hip.static_script("js/hipapp.js")

    @app.route('/hello')
    def hello():
        return 'Hello, World!'

    return app

In the template use macros hip_links, hip_scripts, or hip_metas to retrieve link, script, and meta tags respectively for use in the template.

Stylesheets

{% block stylesheets %}
{% for css in macros.hip_links() %}{{ css.as_tag() }}{% endfor %}
{% endblock %}

Meta tags

{% block metas %}
{% for meta in macros.hip_metas() %}{{ meta.as_tag() }}{% endfor %}
{% endblock %}

Contributing

You know the drill. Fork and get to work.

About

Lightweight Flask extension to simplify the integration of CSS and JavaScript files into your applications

License:BSD 3-Clause "New" or "Revised" License


Languages

Language:Python 100.0%