From fe53de1633f1663e5aaf7afbdd8e51d5781ba0c8 Mon Sep 17 00:00:00 2001 From: Alexis Lahouze Date: Sun, 16 Aug 2015 00:33:35 +0200 Subject: [PATCH] Using flask assets. --- accountant/__init__.py | 16 +++++++++++++--- accountant/frontend/__init__.py | 7 +++++++ 2 files changed, 20 insertions(+), 3 deletions(-) diff --git a/accountant/__init__.py b/accountant/__init__.py index 6bafa5c..c4500f2 100644 --- a/accountant/__init__.py +++ b/accountant/__init__.py @@ -18,9 +18,10 @@ from contextlib import contextmanager import logging -from flask import Flask +from flask import Flask, redirect, url_for from flask.ext.sqlalchemy import SQLAlchemy from flask.ext.bower import Bower +from flask.ext.assets import Environment, Bundle from . import config @@ -71,7 +72,7 @@ def session_aware(f): # Must be after db declaration because the blueprints may need it. from .api import api -from .frontend import frontend +from .frontend import frontend, frontend_js, frontend_css app.register_blueprint(frontend, url_prefix='/app') app.register_blueprint(api, url_prefix='/api') @@ -80,5 +81,14 @@ app.register_blueprint(api, url_prefix='/api') app.config['BOWER_COMPONENTS_ROOT'] = "../bower_components" app.config['BOWER_TRY_MINIFIED'] = not config.debug - bower = Bower(app) + +assets = Environment(app) + +assets.register('frontend_js', frontend_js) +assets.register('frontend_css', frontend_css) + + +@app.route('/') +def index(): + return redirect(url_for('frontend.index')) diff --git a/accountant/frontend/__init__.py b/accountant/frontend/__init__.py index ae78e2c..ed552fa 100644 --- a/accountant/frontend/__init__.py +++ b/accountant/frontend/__init__.py @@ -1,4 +1,5 @@ from flask import Blueprint, render_template +from flask.ext.assets import Environment, Bundle frontend = Blueprint( 'frontend', @@ -8,6 +9,12 @@ frontend = Blueprint( ) + +frontend_js = Bundle('frontend/js/app.js', 'frontend/js/accounts.js', + 'frontend/js/entries.js', 'frontend/js/scheduler.js') +frontend_css = Bundle('frontend/css/main.css') + + @frontend.route('/', defaults={'path': 'accounts'}) @frontend.route('/') def index(path):