Commit Graph

148 Commits

Author SHA1 Message Date
Adam Gent f861f55f34 Remove unused method 2023-11-30 12:39:42 -05:00
Adam Gent a065543327 Inheritance support #120
Turn on inheritance tests. Some whitespace issues.

Recursion working but multi standalone broken

Make inheritance pass spec tests
2023-11-30 12:11:52 -05:00
Michael Bayne 92c1222d80 Minor formatting tweaks made while reading diffs. 2023-11-29 08:35:28 -08:00
Adam Gent ab4bcb749f Make partial loading threadsafe across platforms 2023-11-29 09:04:01 -05:00
Adam Gent 388406eab5 Fix identation with section segments 2023-11-27 13:27:58 -05:00
Adam Gent 8a85c64522 Fix nested partial indentation 2023-11-21 13:11:57 -05:00
Adam Gent afbf37e028 Partial indentation support for v1.3 mustache 2023-11-17 16:48:38 -05:00
Michael Bayne 3a6cd57e00 Whitespace tweaks. 2023-11-15 09:57:27 -08:00
Michael Bayne 940af397c4 Merge pull request #140 from ralfs-gutmanis/master
Add ability to pass CharSequence instead of forcing String for contex…
2023-11-15 09:52:14 -08:00
Michael Bayne 10df38d9a3 Couple of whitespace tweaks. 2023-11-15 09:13:10 -08:00
Peer Schönhusen 979b3b887c Add indentation to partials 2023-11-15 11:24:40 +01:00
Ralfs Gūtmanis d1d72031f2 Add ability to pass CharSequence instead of forcing String for context variable.
java.lang.String is immutable and cannot be overwritten by user.
When passing sensitive data as context variable String remains in memory until GC removes it.
CharSequence allows user to provide his own implementation and overwrite data as needed.
2023-09-18 14:05:37 +03:00
Michael Bayne da7970e993 Allow access coercion to be disabled.
I'm not disabling it by default because that would change behavior for anyone
who was using reflection, which seems like annoying breakage. People who are
using JMustache with Java 9 can configure a non-coercing DefaultCollector to
eliminate the illegal access warnings.
2019-12-17 13:39:22 -08:00
Michael Bayne 5d34f5bf52 Our module name is com.samskivert.jmustache. 2019-07-10 08:39:09 -07:00
Michael Bayne 6691b3b687 Formatting tweak. 2019-07-02 08:15:30 -07:00
Greg Simon e01c1b7522 emptyStringIsFalse flag now works with any Object.
Previously, only String types were checked for being empty. Now
the Formatter is used to format the Object before checking for
being empty.
2019-06-27 11:23:19 +10:00
Michael Bayne 241fbb723b Add a module config, twiddle build to support it.
We now have to build with JDK9 or above, but I believe that the built jar files
continue to be compatible with JDK 1.7 or above. If this turns out not to be
the case, please let me know.
2019-02-08 10:39:48 -08:00
Michael Bayne b3c54669cc Make MustacheCustomContext a Mustache inner interface.
This matches the style of all the other extension points.
2018-08-21 17:20:33 -07:00
Devin Smith 433e9677d4 added MustacheCustomContext 2018-08-21 17:32:18 -05:00
Michael Bayne 4533567303 Fix bugs relating to . and this.
First, I missed some reference checks when I stopped interning names. Fixed
those.

Second, when iterating over an array which contained null elements, the wrong
thing was happening.
2018-06-04 16:10:35 -07:00
Michael Bayne b823ed87c5 Remove use of String.intern().
Me, on the blackboard:

"I will not optimize code without using a profiler."
"I will not optimize code without using a profiler."
"I will not optimize code without using a profiler."
"I will not optimize code without using a profiler."
"I will not optimize code without using a profiler."
...
2018-04-30 08:58:01 -07:00
Michael Bayne 2c53104cf3 Extract Compiler.loadTemplate helper.
If a lambda wanted to load a template via its own template loader, this makes
it a lot easier to do so.
2018-03-05 09:27:18 -08:00
Michael Bayne bf288c8810 Better wording. 2017-12-17 15:20:13 -08:00
Michael Bayne 37e31cbeac Add mechism to visit template tags.
This is useful when you want to inspect the structure of the template without
executing it.
2017-12-17 15:16:09 -08:00
Michael Bayne 326f04cb1e Brace fiddling. 2017-12-17 14:46:42 -08:00
Michael Bayne 02f917e2f7 Add Fragment.executeTemplate().
Allows a lambda to execute a template in the lambda's own context. This enables
'late bound' template inclusion where the lambda can select a template based on
dynamic data in the context at the time it is executed.

Closes #92.
2017-12-03 18:29:15 -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 9bb842ed20 Special case 'entrySet' on Map fetcher.
You can't normally reflectively access methods on Map because it has a
special fetcher, but being able to reflectively access 'entrySet' is
super useful when you want to iterate over the keys+values of a map, so
we're going to hack it in there. Ha!
2016-06-15 11:51:44 -07:00
Michael Bayne 1170d4500e Some toString impls to make debugging easier. 2016-06-15 11:51:44 -07:00
Michael Bayne 115f496947 Add means to obtain parent context(s) in Fragment.
Closes #77.
2016-05-15 11:07:22 -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
Michael Bayne 9eda17f85b Escape ` and = when escaping HTML.
They can be used for nefarious purposes on old IEs.

Refs wycats/handlebars.js@83b8e84
2015-12-24 13:48:07 -08:00
Michael Bayne ec7ea6a660 Revamped iterating over arrays to be GWT-compatible.
We no longer use reflection for any of that; we have a suite of primitive array
helpers that do what is needed.
2015-09-21 16:03:28 -07:00
Michael Bayne c49426db85 Redo primitive array support in GWT-compatible way.
There's unfortunately no sane way to do the same reflection-like array access
in GWT, so we just have to enumerate all of the primitive types.

I could have just left this only in the Java backend, but I would prefer to
avoid differences between behavior on the JVM and behavior in GWT whenever
possible.
2015-09-21 14:47:25 -07:00
Masaki Mori 4b713862c8 Support index access on primitive arrays 2015-09-14 13:45:08 +09:00
Masaki Mori b846605894 Catch exceptions caused by fetching with invalid indices 2015-09-09 11:17:19 +09:00
Michael Bayne 461b108663 Support getters from default methods in interfaces.
Fortunately this did not require using any JDK 1.8-specific APIs, just
searching (via reflection) through the set of interfaces implemented by a class
in addition to its super-classes.

One downside is that the transitive set of all implemented interfaces could be
much larger than the super-class chain, but this is the last thing we search,
so in theory we only even get here if we were about to fail to find the getter
entirely.

This also means that our tests have to be compiled and run with Java 8, because
I was not in the mood to figure out how to do all the complex Maven jockeying
to have a special JDK8 profile and disable JDK8 tests in the normal profile and
re-enable them in the JDK8 profile and blah blah blah, just shoot me now.
2015-08-22 15:07:05 -07:00
Waldinar Oliveira Neto ee4178f549 Support isFoo for boolean properties.
This is addition to the existing getFoo support.
2015-06-20 18:21:47 -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 692adc47f4 Move our GWT stuff around.
This avoids having it look like normal Java source and then confusing tools
because there are two copies of DefaultCollector.
2014-12-01 16:46:51 -08:00
Michael Bayne 614bb82b17 Handle CRLF in skipNewline mode. 2014-12-01 16:35:22 -08:00
Michael Bayne f838c91f99 Attempt to resolve compound keys "whole" first.
This allows one to have a map with keys like "foo.bar.baz" even when not in
standards mode. If a whole key is missing, then we attempt to decompose it and
look it up piecewise.

Closes #55.
2014-05-08 09:49:33 -07:00