Commit Graph

148 Commits

Author SHA1 Message Date
Michael Bayne 8cddc839e3 Oops can't use reflection in shared tests. 2017-09-20 09:51:53 -07: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 49720df4ea Use shipped GWT 2.8.0 (yay).
Also made main source target 1.8 (from 1.6) and nixed some GWT test
cruft.
2016-11-20 11:34:25 -08:00
Michael Bayne 96d9ba5e24 Some test fiddling to make things work in GWT. 2016-08-08 09:12:04 -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 06347ba7eb Remind future me about submodules. 2016-04-29 10:04:34 -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 59c45a2da7 Demo/test custom collector that supports Optional. 2016-01-29 11:39:03 -08: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 f121c11e6f Added missing StringReader.close() method. 2015-09-21 16:13:27 -07: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 cbd80d1d08 Big test revamp to get tests running in GWT.
For some reason I sort of blocked from my mind the fact that none of the actual
tests were running in GWT. Really I was just testing that things compiled.

So now the tests actually run in GWT. This means I had to split the tests that
rely on method/field lookup via reflection into a separate file because that
stuff will never work with GWT. I also changed a bunch of the other tests not
to surreptitiously use reflection because they were ostensibly testing
something else, so no point in those tests being GWT-incompatible just for
kicks.

This also means we can't use JUnit 4 annotations (sigh, I wish GWT would step
out of the stone age, but that's a whole other fiasco that I don't even want to
think about). So some of the tests that were using @Test(expected=FooException)
had to be rewritten to manually catch the exception and fail if it was not
thrown.

Anyhow, now most of the tests are in fact running in GWT (when you do "mvn
integration-test") and the test that I expected should fail in GWT is in fact
failing. Yay!
2015-09-21 15:43:48 -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
Michael Bayne 4ee24a6b19 Add XML preamble. 2015-09-21 14:35:22 -07:00
Masaki Mori 4b713862c8 Support index access on primitive arrays 2015-09-14 13:45:08 +09:00
Michael Bayne 2efcfb69ed Formatting tweak. 2015-09-09 14:40:00 -07:00
Michael Bayne 8a6c32d9db Merge pull request #68 from monae/patch-timezone
Fix broken test which depends on local timezone
2015-09-09 14:39:36 -07:00
Masaki Mori b846605894 Catch exceptions caused by fetching with invalid indices 2015-09-09 11:17:19 +09:00
Masaki Mori b743e74aa2 Fix broken test which depends on local timezone 2015-09-09 11:12:24 +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 3337bf7dd8 We need this for GWT. 2015-03-06 12:27:05 -08: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 4b3f677fbf Avoid freakoutery on invalid delims.
The specs tests assumes an implementation will silently ignore invalid delims.
I think that's a bad idea, so I throw an exception on invalid delims. So I just
ignore those "tests".
2014-12-16 11:06:39 -08:00
Michael Bayne c4cf51cf65 Escaped \r\n in all test checks. 2014-12-16 11:06:14 -08:00
Michael Bayne 6e53f924ba Enable more tests, we pass many of them. Woo!
This also improves failure reporting for specs tests.
2014-12-16 09:45:48 -08:00
Michael Bayne 79c7fd2cb0 Re-escape \r and \n in failure reports. 2014-12-16 09:45:48 -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 4cb0d876ed Rename test helper to not look like a test. 2014-12-13 15:26:51 -08:00
Michael Bayne 453d3928e5 Factor the tests a bit. 2014-12-06 12:53:18 -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
Michael Bayne 2f267b7199 Make NO_FETCHER_FOUND available to external parties.
Closes #54.
2014-05-02 11:30:31 -07:00
Michael Bayne 20abde5b1a Expose the context to a lambda fragment.
This allows the lambda to take the context and turn around and render it using
a totally different template, if desired.
2014-04-16 14:26:22 -07: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 9861b54aa0 Formatting, and small javadoc improvement. 2014-03-18 09:26:38 -07:00
robbytx 75609b42df Add ability for lambda to change the context for fragment execution 2014-03-14 09:50:19 -05: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