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
two questions actually #2
Comments
Two questions, one (longish) answer. First off, yes, that example is broken, and I suppose I don't need to wait for the inevitable big-docs-push to just fix the README. :) Now, for the actual answer: Ashes eliminates the global state that Dust depended on by introducing an AshesEnv, which keeps track of loaded templates and active helpers/escapes, etc. Technically there is a default env named Still, I couldn't really come up with a very-excellent default loading behavior that would work with all frameworks, so currently the default environment doesn't have any loaders attached, and I may remove this default environment, instead prescribing the following usage: from ashes import AshesEnv
ashes = AshesEnv(['/path/to/templates', '/other/template/path'])
# also supports preserved whitespace in output:
# AshesEnv(['/path/to/templates'], keep_whitespace=True)
ashes.render('core_pages/home.html'. {}) or from ashes import ashes, FlatteningPathLoader
ashes.loaders.append(FlatteningPathLoader('./templates', keep_ext=False))
ashes.render('home', {}) Those both work, but I think the cleanest (if slightly verbose at 4-5 lines) and most powerful, is to create a new environment, create new loaders, optionally calling All that sounds kind of involved, but it's really just a few lines, and the focus should be on control and state management, since all of this is going to get wrapped up in a tiny integration layer for bottle/web.py/django/clastic/whichever. Options like paths and preserving/culling whitespace would be exposed through the framework's config, and template error presentation could be controlled by the framework, too. A web developer using a framework shouldn't have to see much of ashes directly. And we can all look forward to fewer long answers. :) |
Got it. In my opinion the environment route is a fine way to go. "A web developer using a framework shouldn't have to see much of ashes directly.", so that's me, "a web developer" and yeah, I prefer to spend my time writing dust templates and dig the magic rendering my templates. Thanks again! BTW: >>> from ashes import AshesEnv
>>> ashes = AshesEnv(['.'])
>>> ashes.render('app.dust', {"name": "marc"})
u'hi marc!' |
Awesome! Keep me posted if you run into anything else. I'll be sure to let you know as I get around to writing integration wrappers for various frameworks. |
Your comment: "A quick example (which will work again soon):", are you referring to ashes.load throwing this error "TypeError: load() takes exactly 2 arguments (3 given)"? At least that is the behavior I am seeing. "ashes.load('app.dust', 'tmpl')" triggers the error.
Have you integrated ashes into any simple web frameworks such as bottle.py, web.py, etc? I started down the path of writing an adaptor for bottle.py extending the BaseTemplate API. No success so far but so I wanted to check with you on the question above.
FYI, bottle.py template API info: https://bottle.readthedocs.org/en/latest/api.html#templates
Thanks man!
~marc
The text was updated successfully, but these errors were encountered: