Commit Graph

36 Commits

Author SHA1 Message Date
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
Michael Bayne 00113a5a36 Added -index special variable. 2010-10-22 05:29:31 +00:00
Michael Bayne 0b9b01dab6 Fixed some bugs with newline skipping. Improved error handling when a tag is
not closed properly and another tag follows it on the same line. Added support
for -first and -last special variables. Fixed problem with resolving outermost
component of a compound key in parent contexts.
2010-10-22 05:02:09 +00:00
Michael Bayne 5932123d79 Added support for nesting contexts, which allows us to resolve variables in
parent contexts if they're not available in our current context.
2010-10-22 01:06:06 +00:00
Michael Bayne eb225b0b48 Added skipping of newlines immediately following section open and close tags. 2010-10-21 23:19:10 +00:00
Michael Bayne 0bef6a06e5 Added support for composite keys, e.g. foo.bar.baz, which extracts foo from the
context, then extracts bar from that object, then extracts baz from that.
2010-10-21 23:06:15 +00:00
Michael Bayne 134a22bcfd Added support for "this" variable which refers to the context itself rather
than a member of the context.
2010-10-21 21:28:06 +00:00
Michael Bayne 3bad793de9 Fixed dropped character on partial delimiter match. 2010-10-21 21:13:09 +00:00
Michael Bayne 5042cc69fa Let's escape HTML by default so as to avoid confusion. 2010-10-21 21:03:52 +00:00
Michael Bayne 5a5dd17296 Javadoc improvements. 2010-10-21 20:57:38 +00:00
Michael Bayne 89c1590ec1 No escaping of HTML by default. Added Compiler builder mechanism to specify
default HTML escaping behavior. Possibly pattern overkill, but if we add any
other options later, this will scale nicely.
2010-10-21 20:49:53 +00:00
Michael Bayne a7984b1594 Javadoc fixes, properly skip void methods. 2010-10-21 19:42:38 +00:00
Michael Bayne 1e89b87cb0 Added support for obtaining variable values from fields and methods. Added a
template-local variable fetching cache that avoids reresolving the source of a
variable when it remains monomorphic (e.g. it's always a field of class
Foo.class or always a method named getFoo(), etc.).
2010-10-21 19:26:40 +00:00
Michael Bayne 3eea40d1d4 Basic implementation and some tests. 2010-10-21 18:08:07 +00:00
Michael Bayne 5640791b4b Earnest beginnings. 2010-10-21 06:32:37 +00:00