与 Web 框架集成

Pyramid

plim.adapters.pyramid_renderer 添加至项目 .ini 配置文件的 pyram`id.includes 列表中:

[app:main]
pyramid.includes =
    # ... (other packages)
    plim.adapters.pyramid_renderer

The adapter will add the .plim renderer for use in Pyramid. This can be overridden and more may be added via the config.add_plim_renderer() directive:

config.add_plim_renderer('.plm', mako_settings_prefix='mako.')

The renderer will load its configuration from a provided mako prefix in the Pyramid settings dictionary. The default prefix is ‘mako.’.

Flask

想要在 Flask 中使用 plim 只需要在项目中添加下面的代码:

from flask import Flask
from flask.ext.mako import MakoTemplates, render_template
from plim import preprocessor

app = Flask(__name__)
mako = MakoTemplates(app)
app.config['MAKO_PREPROCESSOR'] = preprocessor

@app.route('/')
def hello():
    return render_template('hello.html', name='mako')

if __name__ == "__main__":
    app.run(debug=True)

templates 目录中的 hello.html 需要写成这样:

doctype html
html
  head
    title hello ${name}
  body
    p hello ${name}

代码高亮

现在还没有专门的 plim 语法高亮工具。

不过,由于 Plim 和 Slim 的语法很相似,你可以使用 Slim 的语法高亮工具 作为替代。

编辑器支持