Closed bennoleslie closed 12 years ago
Hi @bennoleslie, thanks a lot for the report. The main reason I put the defaults in one place was for maintainability reasons (DRY and discoverability, etc). Runtime configuration was secondary, so I didn't take the time to make sure it worked that way initially. But it should (even if module monkey-patching is discouraged).
Do you want to put together a pull request? Otherwise, I could do it. There should also be unit tests to make sure runtime configuration of each setting works.
Also, just so you know, one reason runtime configuration was secondary was that IIRC, most of those settings can be configured through the Renderer class, so I didn't think it would be necessary in most cases. I also didn't want to encourage the use of monkey patching (e.g. by documenting this possibility) as opposed to using the class-based API.
By the way, I recently started a project to use Mustache templates for source code projects (i.e. directories of template files with templatized file names, etc). It's called Molt. I'd be curious to know if it helps your use case at all.
Thanks @cjerdonek I've just submitted a pull request, which includes code and tests. Not sure what your policy is, I've put them in a single commit, but you could split them easily if preferred.
Currently I've written tests for the 3 defaults I've been using. I wasn't 100% familiar with the way in which the others were used, so didn't test them. Hopefully the code I've put in test_defaults.py makes it simple to add additional tests.
Agree that monkey-patching should probably not be "the way" to do this, but it is very convenient for certain approaches.
Re: molt. That looks pretty neat, but not a different kind of use case to what I'm doing.
Committed to the development branch (after merging pull request #136). Thanks again, @bennoleslie!
I'm currently using pystache to generate templated C code (rather than say HTML code), and have done the following:
pystache.defaults.MISSING_TAGS = 'strict' pystache.defaults.TAG_ESCAPE = lambda u: u
I'm wondering if that is an intended way of doing things?
I tried to also do this:
pystache.defaults.DELIMITERS = ('[[', ']]')
However, that doesn't work as parser.py does "from pystache.defaults import DELIMITERS", so any changes don't get picked up.
When I change the code to "from pystache import defaults" and "defaults.DELIMITERS" rather than just "DELIMITERS", everything is fine.
Anyway, just wondering if it was your intention that the user can configure things through defaults (if so, I'll send a pull request), or if in this case I should be manually constructing Parser and Renderer objects.