Commit Graph

64 Commits

Author SHA1 Message Date
Michael Bayne e588f2edf0 Clarify null-shadowing test a bit further with Object context version. 2012-12-04 16:45:32 -08:00
Michael Bayne 65f8d12d62 Merge pull request #22 from tominsam/master
allow inner null values to mask parent context values
2012-12-04 16:38:13 -08:00
Michael Bayne 31190d3cb5 Made createFetcherCache abstract.
GWT doesn't provide Collections.synchronizedMap so we can't default to that.
Because we don't want someone to extend BasicCollector on a multi-threaded
platform and get an unsynchronized HashMap, which would cause things to fail,
we instead make creatFetcherCache abstract and document that if you extend
BasicCollector, you need to return a synchronized map (if the platform you're
targeting is multithreaded).
2012-10-03 09:51:26 -07:00
Michael Bayne 4926b326b9 Preserve Java 5 compatibility. Yay! 2012-10-01 14:14:23 -07:00
Michael Bayne 5ec24e947c Use ConcurrentHashMap to cache fetchers, on platforms that support it. 2012-10-01 09:27:36 -07:00
Tom Insam 2b337b8770 null values can shadow parent context now. Improve test a little. 2012-08-22 15:19:00 +01:00
Tom Insam 718218098f test for masking parent contexts with false keys. 2012-08-22 14:20:58 +01:00
Michael Bayne 69a772ab98 Preserve nesting with non-empty strings; tidying. 2012-08-13 14:36:17 -07:00
Mickael Jeanroy af91e58024 Add option to treat empty string as falsy value 2012-08-13 20:57:29 +02:00
Martin Ellis 1578aa0920 Escape apostrophe's using entity number (') rather than name (').
The ' entity is an XML entity, rather than an HTML entity, and is not
supported by Internet Explorer. The numeric form is supported in both XML
and HTML.
2012-06-12 17:12:54 +01:00
Serkan Kaba ffe46f5865 Make the code Java5 compatible. 2012-04-10 14:26:57 +02:00
Michael Bayne 75da7d3e76 Only compile a lazily loaded template once. Also fixed styles. 2012-04-09 11:15:56 -07:00
serkan 4d9a664214 Fix infinite recursion. 2012-04-06 16:33:21 +02:00
Michael Bayne 718639127e Added comments and squeezed into 100 columns. 2011-11-22 11:40:09 -08:00
Jacob Lewallen 1a06a0233a Add a Template.execute that takes a parent context. 2011-11-22 11:20:59 -08:00
Michael Bayne d51cd7e08a Reader and Writer are abstract classes. GWT tests work now. Yay! 2011-10-29 15:50:41 -07:00
Michael Bayne 407d999836 Further work on making JMustache work in GWT.
I've ironed out most of the kinks, but the GWT unit test still fails because
we're forced to do some sneaky things with java.io.Reader/Writer. I think it
will all work when compiled to JavaScript, so I need to check it in a real
project.
2011-10-29 15:31:27 -07:00
Michael Bayne f9319ce911 Added a header. 2011-10-29 15:31:03 -07:00
Michael Bayne f6c6f4916c Pass the context instance itself instead of its class.
In GWT we can't use Class.isAssignableFrom. We need the original instance so
that we can do (ctx instanceof Map<?,?>).
2011-10-29 15:29:18 -07:00
Michael Bayne 69826a707e Nixed limitations list. One was obsolete and the other is in the README. 2011-10-29 14:45:24 -07:00
Michael Bayne a5e7c2ebb8 Switch CompoundSegment to BlockSegment. Avoids overloading use of the term
compound, which I use for compound variables.
2011-10-29 14:41:27 -07:00
Michael Bayne adf116992c Modified compound variables to honor null/default configuration. Closes #10.
Kali/Bertrand convinced me that being consistent with other Mustache
implementations is more important than whatever wacky reasons I was harboring
for keeping compound variables different than singleton sections.
2011-10-29 14:38:56 -07:00
Michael Bayne c67f6aeac5 Oh yeah, we need a way to plug in a custom collector. 2011-10-13 20:39:39 -07:00
Michael Bayne 76e9d54683 Extracted the iteration over collections and creation of variable fetchers into
a pluggable component.

This allows scaling down to the GWT environment by hiding the reflection code
via GWT's super source mechanism.

And it allows scaling up to non-Java languages (like Scala) by allowing the
library client to extend the DefaultCollector and teach it about Scala
Iterators, Iterables and Maps.

I also just realized that GWT has no facilities for Reader and Writer, which is
going to complicate making things work in GWT even further. But for now, I'll
just leave things as is.
2011-10-13 20:35:46 -07:00
Michael Bayne 4367ff6784 Only skip newlines if a tag is the only thing on the line.
Otherwise you get undesirable newline skipping if you do things like, for
example:

{{#foos}}
{{bar}}{{^-last}}, {{/-last}}
{{/foos}}

where you want the newline after {{/-last}}, but it was getting skipped.
2011-08-29 14:44:17 -07:00
Michael Bayne a3eb9e22e1 Fixed bug where -last was not correctly handled on lists of a single element,
where said element is both -first and -last.
2011-08-29 13:51:11 -07:00
Michael Bayne 28978548c5 Wrapped some long lines. 2011-08-29 13:42:11 -07:00
Michael Bayne 7255cb7c09 We keep the @Override on the same line round these parts. 2011-07-17 08:38:20 -07:00
David Hoover b0737e3f2b Add missing @Overrides 2011-07-01 11:25:52 -07:00
Michael Bayne 753546a63c More stray tag character tests. 2011-06-21 22:00:37 -07:00
Michael Bayne 67d325624f Parser reorganization, parsing lenience++.
Reorganized the parser as a proper class so that I could easily reenter it to
deal with things like optional second open and close tag characters. In the
process, made the parser simply pass through certain kinds of malformed input
as text.

I hope to go further in this regard, avoiding parse exceptions in favor of
simply showing the user the malformed output unsubstituted. It's just as easy
to see "{{broken blah blah" in ones result template as it is to read exception
messages, and apps that wish to use JMustache for things like end-user
templates will find this much more agreeable.
2011-06-21 21:54:59 -07:00
Michael Bayne 9fae13e008 Added Compiler.nullValue() for situations where one wants to provide a value
for use when variables resolve to null, but still wishes for exceptions to be
thrown when values are not resolvable (i.e. are typos). Pre-existing behavior
is preserved if one uses defaultValue() or does not change the default
configuration.

Nota bene: there are complexities, so be sure to read the documentation.
2011-05-28 10:42:45 -07:00
Michael Bayne ef971015bd Resolves issue 7 regarding proper handling of nested contexts when processing a
nested context.
2011-05-26 14:52:45 -07:00
Michael Bayne 1be9c52589 Let's add a test illustrating that default values are used for variables which
resolve to null.
2011-04-15 12:39:16 -07:00
Michael Bayne 15ff48eabb Some tidying up, name changes and clarifications. I went with "defaultValue"
rather than "missingVariableValue" because the value is used any time a
variable resolves to null, not necessarily just when it is missing. If you
have a context like:

new Object() {
   String foo = null;
}

and reference {{foo}} in your template, foo is not missing, per se, but the
default value will still be used for it.
2011-04-15 12:35:33 -07:00
John Montgomery 5d59eada29 Added compiler option to provide defaults for missing values
Call missingVariableValue(value) on a Compiler object to get a new
version that will insert "value" for missing values (rather than
throwing an exception).  Useful when you have templates you would
rather generated *something* instead of erroring or for when objects may
have null values themselves.
2011-04-15 10:01:40 +01:00
Michael Bayne 6b1551a1c9 Actually implemented delimiter change. Tidied things upalong the way. 2011-04-13 15:42:28 -07:00
Michael Bayne a0bc4dc3b6 Test that names are being processed in partials; fixed exception on attempt to
use partials when unconfigured; moved partials tests down into a more sensible
location among the tests.
2011-04-13 14:42:30 -07:00
Michael Bayne 419a8b887c Fixed typo; restrict exception handling to just the loading of a partial
template; pass runtime exceptions through unwrapped.
2011-04-13 14:41:49 -07:00
Michael Bayne 0959ccd0d9 More tidying. 2011-04-13 14:25:41 -07:00
Michael Bayne ce389bd293 Cleaned up contributed template loading support. Moved MustacheTemplateLoader
into inner interface Mustache.TemplateLoader, eliminated top-level
UnsupportedTemplateLoader. Eliminated static configuration of active template
loader in favor of per-Compiler configured template loader, which is how all
other configuration is handled.More complex tests are needed, but will have to
wait until I'm less sleep deprived.
2011-04-13 11:49:59 -07:00
Michael Bayne e8641ba4fa We have interned strings here, so we can use reference equality to determine
whether we're seeing {{.}} or not. Also reinstated treatment of ".foo" as a
compound key. I'm not 100% sure that makes more sense than treating ".foo" as a
simple key, but I'd rather change less behavior than more when making the {{.}}
fix.
2011-04-13 11:38:26 -07:00
Sean Scanlon b3f5e1e960 tighten up fix for {{.}}
realizing previous commit would treat {{.foo}} the same as {{.}}
2011-03-27 16:18:17 -07:00
Sean Scanlon 095c6f9a59 fix for using {{.}} in non-standards mode
in non-standards mode (which is the default), {{.}} would be treated as a compound key, resulting in key not found exceptions.
2011-03-27 16:07:20 -07:00
Sean Scanlon 5fc751219e Add template loader hook for partials {{>template}} support.
This is implemented so that by default, the library does not support template loading (which it already does not)
but instead of treating partial calls as a context lookup for a ">key", an exception is thrown.
2011-03-27 15:53:04 -07:00
Michael Bayne cd4db4293e Added support for the triple mustache! {{{foo}}} which means "don't escape HTML
in the replacement for this tag." This is already supported via {{&foo}} as
well, but we like to be thorough.

Also generate MustacheParseException when parsing (a subclass of
MustacheException) mostly for convenience in testing.
2011-02-28 20:15:45 -08:00
Michael Bayne f4cfa40c2b Added a "standards mode" based on patches from mrdon. In standards mode, we do
not search parent contexts for name bindings, nor do we support compound keys.
Also added support for {{.}} which has the same semantics as {{this}}. I must
have missed this when reading the Mustache spec.
2011-02-28 11:52:40 -08:00
Michael Bayne 773e1c5c6e Bah, let's just have the copyright in the LICENSE file. If that doesn't hold up
in a court of law, oh well. My sense of aesthetics trumps all!
2010-11-02 14:19:33 -07:00
Michael Bayne 84691b7ac3 Let's have a license and a proper source header. (Thanks Dave!) 2010-11-02 14:18:16 -07:00
Michael Bayne 7ec57412fa A patch from Charlie to provide line numbers when reporting variable related
errors during execution.
2010-10-23 16:35:38 +00:00