Flask-assets を使用して webassets を整理し、mako をテンプレート化したいと考えています。Flask-assets は通常、次のように jinja を使用します。
{% assets "js_all" %}
<script type="text/javascript" src="{{ ASSET_URL }}"></script>
{% endassets %}
Mako に相当するもの (私の知る限り) は次のようになります。
% assets 'coffee':
<script type="text/javascript" src="{{ ASSET_URL }}"></script>
% endassets
ただし、これによりコンパイル エラーが発生します。
mako.exceptions.CompileException
CompileException: Unsupported control keyword: 'assets' in file '/index.html' at line: 8 char: 1
Mako でカスタム コントロール キーワード (「アセット」など) を使用する方法はありますか?
これが記録用の私の app.py です。
import os
from flask import Flask, render_template
from flask.ext import assets
from flask import config
from flask.ext.mako import MakoTemplates
from flask.ext.mako import render_template
app = Flask(__name__)
app.config['ASSETS_DEBUG'] = True
mako = MakoTemplates(app)
env = assets.Environment(app)
# Tell flask-assets where to look for our coffeescript and sass files.
env.load_path = [
os.path.join(os.path.dirname(__file__), 'js'),
os.path.join(os.path.dirname(__file__), 'styles'),
]
coffee = assets.Bundle('**/*.coffee', filters='coffeescript', output="app.js")
env.register('coffee', coffee)
@app.route("/")
def index():
return render_template('index.html', name='mako')
if __name__ == "__main__":
app.run(debug=True)