Commit Graph

81 Commits

Author SHA1 Message Date
Michael Bayne 326f04cb1e Brace fiddling. 2017-12-17 14:46:42 -08:00
Michael Bayne 172f35fb64 When nesting for non-list contexts, inherit list info.
This ensures that if you enter a conditional block while inside a list
block, the list "state" from the outer list will still be visible. For
example (somewhat contrived, but gets the point across):

{{#list}}
{{#name}}{{-index}}. {{.}}{{/name}}
{{^name}}{{-index}}. No name!{{/name}}
{{/list}}

Yields something like:

1. Bob
2. Mary
3. No name!
4. Jim

Fixes #90.
2017-09-20 09:43:14 -07:00
Michael Bayne 546f78318e Simple support for decompiling fragments.
There are limitations! See the javadoc for Template.Fragment.decompile.

Closes #75.
2016-04-14 08:32:07 -07:00
ui4j 5cf4e60d89 Removed unused variables 2015-05-06 23:42:10 +03:00
Michael Bayne 2b376d3189 Align "compact" Javadocs more sanely. 2015-03-06 12:24:13 -08:00
Michael Bayne 43a51b3235 Be more robust about closing template Reader.
Also some tidying: we don't like tabs or trailing whitespace.
2015-03-06 12:19:46 -08:00
Alexander Schrab 2ab053ce35 Close readers provided by TemplateLoader 2015-03-04 18:45:55 +01:00
Michael Bayne 8618f89f7e Added strictSections configuration.
Section behavior used to be somewhat hackily determined from nullValue and
defaultValue, but it was messy. Now it has its own configuration and things are
more explicit.

Previously missing/null sections were treated as false, but if you set
nullValue to something, then missing sections became an error, but null
sections remained false. If you set defaultValue to something, missing sections
went back to being omitted. Kooky.

Now missing sections are omitted, unless you set strictSections to true, in
which case they become an error. nullValue and defaultValue have no impact on
section behavior.

There is no way to make null sections an error, but I don't see any demand for
that, so I'm going to leave that as a TODO.

Closes #60.
2014-12-20 11:06:46 -08:00
Michael Bayne 09fee0f037 Enabled more tests, fixed more bugs.
Mainly we also needed to trim around comment tags, but also there were a bunch
of tricky edge cases that were only partially addressed. This is some edgy
business!
2014-12-16 14:47:31 -08:00
Michael Bayne 0e2a7d13d5 Properly trim whitespace around delims tag.
This includes consolidation of other whitespace trimming to avoid duplication
with the delims trimming code.
2014-12-16 11:07:24 -08:00
Michael Bayne ef4184404d Trim newlines from section tags with leading+trailing whitespace.
Other implementations apparently do it, and we have to keep up with the
Joneses.

Closes #59.
2014-12-16 09:45:37 -08:00
Michael Bayne b33bbda7d9 Label that bunch of mysterious ctor params. 2014-12-06 12:52:43 -08:00
Michael Bayne 614bb82b17 Handle CRLF in skipNewline mode. 2014-12-01 16:35:22 -08:00
Michael Bayne 199ebf1f84 Use a copy of delims in the parser.
I don't know what madness overcame me when I thought it was a good idea to
mutate the compiler's delims during parsing and then restore them.
2014-03-31 09:41:02 -07:00
Michael Bayne 3fe5e020d8 Factor exception wrapped read() into nextChar(). 2014-03-12 11:35:45 -07:00
Michael Bayne 8998b5f11e May as well report the bogus final char if we can. 2014-03-12 11:31:16 -07:00
Michael Bayne d1c8a665a9 Also, why add a brace and then remove it? 2014-03-12 11:23:16 -07:00
robbytx 5c3a93e079 Correct number of braces for error message 2014-03-12 11:21:17 -07:00
Michael Bayne 59e06b24c9 Invertable -> invertible. Other minor tidying. 2014-03-11 07:43:44 -07:00
robbytx 2251ac1ed2 Add support for lambdas in inverse blocks 2014-03-10 17:06:21 -05:00
Michael Bayne acc339ee13 Added mechanism to customize toString-ing of values. 2014-01-08 10:50:37 -08:00
Michael Bayne 5001469052 Updated docs for Compiler.nullValue(). 2013-10-08 12:21:54 -07:00
Michael Bayne 3af55c2660 Some javadoc improvements. 2013-08-01 16:04:46 -07:00
Michael Bayne d1384cd049 Reworked user-defined escaping to suit my tastes. 2013-08-01 16:01:31 -07:00
Nat Pryce 4ae290fdaa User-extensible escaping rules (not just HTML or no escaping) 2013-07-22 22:36:51 +01:00
Michael Bayne 9441d062a6 Moved falsey-ness detection into compiler.
Fixes #39.

This fixes a bug where falsey values were not properly triggering inverted
sections, and consolidates some logic.

Also did some renaming. Couldn't help myself.
2013-07-03 16:48:09 -07:00
Michael Bayne 6e3051c3ba Some tidying, added a negative test, method tests.
The latter was because the new feature was not actually conditional on its
compiler parameter. It was on all the time.
2013-05-13 13:22:45 -07:00
Mickael Jeanroy 4300b1213e Add option to treat zero as a falsy value
In javascript implementation, zero is a falsy value and is treated as a false boolean.
An option is added (false by default) to treat zero as a falsy value as in javascript implementation.

It means that section like:

{{#zeroValue}}foo{{/zeroValue}}

will not be rendered.
2013-05-08 22:24:40 +02:00
Michael Bayne 426faf92c5 Do our save/restore slightly differently. 2013-05-03 10:12:00 -07:00
David Loehr 751f671fd6 Reset compiler.delims after parsing a template 2013-05-03 11:57:53 -04:00
Michael Bayne 4b1af351ae A note to self and minor comment tweak. 2013-04-02 12:54:20 -07:00
Michael Bayne c268d41594 Handle CR when skipping newlines. 2013-04-02 12:54:20 -07:00
Michael Bayne 3a5da915e9 These days I always cuddle method braces. 2013-03-27 10:37:41 -07:00
Michael Bayne fe2664627f A few tweaks to default delims patch (and some tidying):
- triple-stache mode reverted to only work with {{{ }}} rather than working
  with whatever default delims you set; I think this is more in the spirit of
  the Mustache spec

- Compiler.withDelims takes a delims string rather than the internal Delims
  class which callers don't care about or have access to

- nixed Delims constructors, made updateDelims fluent

- nixed DelimsTest, it wasn't testing anything that wasn't also already tested
  by the functional tests in MustacheTest
2013-03-27 10:29:57 -07:00
hierynomus 80217949e3 Fixes #33: Provide custom delimiters to the compiler 2013-03-27 09:23:15 +01:00
Daniel Bruckner f92509a872 fixes #28 2013-03-06 12:46:36 -08:00
Michael Bayne 43db03a26a Changed MustacheContextException -> MustacheException.Context.
Also made data into final fields. I don't like unnecessary getters.
2013-03-05 20:55:01 -08:00
pmenhart c61650734d Added MustacheContextException
Solving need to distinguish context errors from environment errors.
  The exception has fields for the offending key and line number. This
  is a first step towards internationalization of messages.
2013-03-05 23:33:48 -05:00
Michael Bayne acbddd07a2 Added basic lambda support. 2013-02-15 16:38:36 -08:00
Michael Bayne 8f87bf374d Some tweaks to the 'substitute name into null value' patch. 2013-01-23 17:43:46 -08:00
pmenhart 8b0d063ffd Show the name of variable that is null or missing
If Compliler.nullValue contains a substring "{{name}}", then this substring
will be replaced with the name of variable.
For example, if nullValue="?{{name}}?" and variable is resolved to null,
then string "?foo?" will be used.
2013-01-23 15:59:52 -05:00
Michael Bayne 5ec24e947c Use ConcurrentHashMap to cache fetchers, on platforms that support it. 2012-10-01 09:27:36 -07: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
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 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