Plim icon indicating copy to clipboard operation
Plim copied to clipboard

use plim in flask, bottle etc.

Open hyao opened this issue 11 years ago • 6 comments

Hi,

I'm trying to get plim working with flask via flask-mako (http://pythonhosted.org//Flask-Mako/), but couldn't get it to work:

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

from flask.ext.mako import render_template
from mako.template import Template

app = Flask(__name__)
app.config['Mako_PREPROCESSOR'] = preprocessor 
mako = MakoTemplates(app)
app.template_folder = 'templates'


temp = Template('a.plim', preprocessor=preprocessor)

@app.route('/')
def hello():
    return temp.render()


if __name__ == '__main__':
    app.run()

Could you take a look when you have the time and maybe add some docs for flask, bottle as well; plim seems really nice to use :)

Thanks a lot,

hyao avatar Oct 05 '14 18:10 hyao

Hello! I apologise for a late response.

Unfortunatelly I've never used Flask and cannot provide you a working configuration example. I will get back to this ticket once I have spare time to answer it in full.

P.S. Contributions into documentation with regard to this subject are highly appreciated.

avanov avatar Oct 15 '14 00:10 avanov

Thanks

hyao avatar Oct 15 '14 08:10 hyao

I am currently toying around with this too and a basic working example is this app.py @hyao:

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)

and the template file templates/hello.html:

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

What is missing is some nice integration ala pyjade where you basically add a line and then you are able to render ".jade" files using the default render_template of flask. I have no idea if something like that would be feasible though due to the reliance on jinja for rendering.

rmoorman avatar Oct 21 '14 23:10 rmoorman

@rmoorman Thanks, your code snippet works.

Just added create a PR based on your code to the docs: https://github.com/avanov/Plim/pull/38

Btw, just found a tool emmet.io, it could save lots of typing for html writing.

Thanks,

hyao avatar Oct 22 '14 09:10 hyao

Being able to render .plim files like pyjade does would be super as well! :)

hyao avatar Oct 22 '14 09:10 hyao

Can be closed as #38 is merged.

kxxoling avatar Jul 26 '15 01:07 kxxoling