Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

use plim in flask, bottle etc. #37

Open
hyao opened this issue Oct 5, 2014 · 6 comments
Open

use plim in flask, bottle etc. #37

hyao opened this issue Oct 5, 2014 · 6 comments

Comments

@hyao
Copy link
Contributor

hyao commented Oct 5, 2014

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,

@avanov
Copy link
Owner

avanov commented Oct 15, 2014

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.

@hyao
Copy link
Contributor Author

hyao commented Oct 15, 2014

Thanks

@rmoorman
Copy link

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.

@hyao
Copy link
Contributor Author

hyao commented Oct 22, 2014

@rmoorman Thanks, your code snippet works.

Just added create a PR based on your code to the docs:
#38

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

Thanks,

@hyao
Copy link
Contributor Author

hyao commented Oct 22, 2014

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

@kxxoling
Copy link
Contributor

Can be closed as #38 is merged.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants