File tree Expand file tree Collapse file tree
main/java/com/github/jknack/handlebars/internal
test/java/com/github/jknack/handlebars Expand file tree Collapse file tree Original file line number Diff line number Diff line change 2424import java .util .LinkedHashMap ;
2525import java .util .List ;
2626import java .util .Map ;
27+ import java .util .HashMap ;
2728import java .util .Map .Entry ;
2829
2930import com .github .jknack .handlebars .Context ;
@@ -81,7 +82,7 @@ public HelperResolver(final Handlebars handlebars) {
8182 */
8283 protected Map <String , Object > hash (final Context context ) throws IOException {
8384 if (hashSize == 0 ) {
84- return Collections . emptyMap ();
85+ return new HashMap <> ();
8586 }
8687 Map <String , Object > result = new LinkedHashMap <String , Object >();
8788 for (Entry <String , Param > entry : hash .entrySet ()) {
Original file line number Diff line number Diff line change 1+ package com .github .jknack .handlebars ;
2+
3+ import org .junit .Test ;
4+
5+ import java .io .IOException ;
6+
7+ public class WriteIntoContextTest extends AbstractTest {
8+ protected void configure (final Handlebars handlebars ) {
9+ handlebars .registerHelpers (new WriteIntoContextTest .SetHelperClass ());
10+ }
11+
12+ @ Test
13+ public void shouldBeAbleToWriteIntoContext () throws IOException {
14+ shouldCompileTo ("{{set \" foo\" this}}{{foo}}" , "bar" , "bar" );
15+ }
16+
17+ @ Test
18+ public void shouldBeAbleToWriteIntoContextWhenInBlockHelper () throws IOException {
19+ shouldCompileTo ("{{#with data}}{{set \" foo\" field}}{{foo}}{{/with}}" , "{\" data\" : {\" field\" : \" bar\" }}" , "bar" );
20+ }
21+
22+ @ Test
23+ public void shouldBeAbleToWriteIntoContextWhenInPartial () throws IOException {
24+ shouldCompileToWithPartials ("{{> partial}}" , "bar" ,
25+ constructPartials ("partial" , "{{set \" foo\" this}}{{foo}}" ),
26+ "bar" );
27+ }
28+
29+ private Hash constructPartials (String name , String content ) throws IOException {
30+ return new Hash ().$ (name , content );
31+ }
32+
33+ public static class SetHelperClass {
34+ public String set (String key , Object value , Options options ) throws NoSuchFieldException {
35+ options .context .combine (key , value );
36+ return "" ;
37+ }
38+ }
39+ }
You can’t perform that action at this time.
0 commit comments