def setup_compilers(app): _compilers = { '.styl': StylusCompiler.as_handler(), '.coffee': CoffeeScriptCompiler.as_handler() } def gears_environment(app): return app.extensions['gears']['environment'] env = gears_environment(app) for extension, compiler in _compilers.iteritems(): env.compilers.register(extension, compiler)
import os from gears.environment import Environment from gears.finders import FileSystemFinder from gears_stylus import StylusCompiler env = Environment('static') env.register_defaults() env.finders.register(FileSystemFinder(directories=[os.path.abspath('assets')])) env.compilers.register('.styl', StylusCompiler.as_handler()) if __name__ == '__main__': env.save()
app = Flask(__name__) app.config.from_object( os.environ.get('FLASK_SETTINGS_MODULE', 'app.settings.production')) class RegexConverter(BaseConverter): def __init__(self, url_map, *items): super(RegexConverter, self).__init__(url_map) self.regex = items[0] app.url_map.converters['regex'] = RegexConverter gears = Gears( compilers={ '.styl': StylusCompiler.as_handler(), '.less': LESSCompiler.as_handler(), '.coffee': CoffeeScriptCompiler.as_handler(), '.sass': SASSCompiler.as_handler(), '.scss': SASSCompiler.as_handler() }, compressors={ 'text/css': CleanCSSCompressor.as_handler(), 'text/javascript': UglifyJSCompressor.as_handler() }, ) gears.init_app(app) db = SQLAlchemy(app) login_manager = LoginManager() login_manager.init_app(app) login_manager.login_view = 'login'
from flask import Flask, render_template from flask_gears import Gears from gears_stylus import StylusCompiler from gears_clean_css import CleanCSSCompressor app = Flask(__name__) gears = Gears( compilers={'.styl': StylusCompiler.as_handler()}, compressors={'text/css': CleanCSSCompressor.as_handler()}, ) gears.init_app(app) @app.route('/') def index(): return render_template('index.html') if __name__ == '__main__': app.run(debug=True)
from flask.ext.gears import Gears from gears.compressors import SlimItCompressor from gears_stylus import StylusCompiler from gears_clean_css import CleanCSSCompressor from gears_coffeescript import CoffeeScriptCompiler gears = Gears() _compilers = { '.styl': StylusCompiler.as_handler(), '.coffee': CoffeeScriptCompiler.as_handler() } _compressors = { "text/css": CleanCSSCompressor.as_handler(), "application/javascript": SlimItCompressor.as_handler() } def setup_gears(app): gears.init_app(app) setup_gears_environment(app) setup_compressors(app) setup_compilers(app) def gears_environment(app): return app.extensions['gears']['environment']