private MustacheFactory createNewMustacheFactory(Class<? extends View> key) { return new DefaultMustacheFactory( fileRoot.isPresent() ? new FileSystemResolver(fileRoot.get()) : new PerClassMustacheResolver(key)); }
@Before public void setUp() { factory = new DefaultMustacheFactory(); mapModel = new HashMap<>(); Map<String, Object> container1 = new HashMap<>(); mapModel.put("container1", container1); objectModel = new HashMap<>(); objectModel.put("container1", new ModelObject()); }
public void testPropertyWithDot() throws IOException { DefaultMustacheFactory mustacheFactory = new DefaultMustacheFactory(); Reader reader = new StringReader("value=${some.value}"); Mustache mustache = mustacheFactory.compile(reader, "maven", "${", "}"); Map<String, String> properties = new HashMap<>(); properties.put("some.value", "some.value"); StringWriter writer = new StringWriter(); mustache.execute(writer, new Object[]{properties}).close(); Assert.assertEquals("value=some.value", writer.toString()); }
public void testImplicitIteratorWithScope() throws IOException { Mustache test = new DefaultMustacheFactory().compile(new StringReader("{{#test}}_{{.}}_{{/test}}"), "test"); StringWriter sw = new StringWriter(); test.execute(sw, new Object() { List<String> test = Arrays.asList("a", "b", "c"); }).close(); assertEquals("_a__b__c_", sw.toString()); }
@Before public void setUp() { MustacheFactory factory = new DefaultMustacheFactory(); Reader reader = new StringReader(TEMPLATE); mustache = factory.compile(reader, "template"); }
public void testCR() { Mustache m = new DefaultMustacheFactory().compile(new StringReader("{{test}}\r\n{{test}}\r\n"), "test"); StringWriter sw = new StringWriter(); m.execute(sw, new Object() { String test = "fred"; }); assertEquals("fred\r\nfred\r\n", sw.toString()); }
@Test public void testWithTemplateFunction2() throws IOException { DefaultMustacheFactory mf = new DefaultMustacheFactory(); Mustache maven = mf.compile(new StringReader("Hello, ${foo}."), "maven", "${", "}"); StringWriter sw = new StringWriter(); maven.execute(sw, new Object() { TemplateFunction foo = (s) -> "${name}"; String name = "Jason"; }).close(); assertEquals("Hello, ${name}.", sw.toString()); }
@Test public void testTemporarilyChangeDelimiters() throws IOException { DefaultMustacheFactory mf = new DefaultMustacheFactory(); Mustache maven = mf.compile(new StringReader("AND {{tfield}} = {{=$< >=}}#{$<={{ }}=>{{name}}.{{{jfield}}}}"), "maven"); StringWriter sw = new StringWriter(); maven.execute(sw, new Object() { String tfield = "someOtherId"; String name = "id"; String jfield = "1"; }).close(); assertEquals("AND someOtherId = #{id.1}", sw.toString()); }
public void testImplicitIteratorNoScope() throws IOException { Mustache test = new DefaultMustacheFactory().compile(new StringReader("{{.}}"), "test"); StringWriter sw = new StringWriter(); test.execute(sw, "").close(); assertEquals("", sw.toString()); StringWriter sw2 = new StringWriter(); test.execute(sw2, new Object[0]).close(); assertEquals("", sw2.toString()); }
@Test public void testClientMethod() throws MustacheException, IOException, ExecutionException, InterruptedException { MustacheFactory c = new DefaultMustacheFactory(root); Mustache m = c.compile("client.html"); StringWriter sw = new StringWriter(); Map scope = new HashMap(); scope.put("reply", "TestReply"); scope.put("commands", Arrays.asList("a", "b")); m.execute(sw, scope); assertEquals(getContents(root, "client.txt"), sw.toString()); }
@Test public void testSubInPartial() throws MustacheException, IOException, ExecutionException, InterruptedException { MustacheFactory c = new DefaultMustacheFactory(root); Mustache m = c.compile("partialsub.html"); StringWriter sw = new StringWriter(); Map scope = new HashMap(); scope.put("name", "Sam"); scope.put("randomid", "asdlkfj"); m.execute(sw, scope); assertEquals(getContents(root, "sub.txt"), sw.toString()); }
@Test public void testPreLabels() throws MustacheException, IOException, ExecutionException, InterruptedException { MustacheFactory c = new DefaultMustacheFactory(root); Mustache m = c.compile("bundles.html"); StringWriter sw = new StringWriter(); Map<String, Object> scope = new HashMap<>(); scope.put("trans", BundleFunctions.newPreTranslate(BUNDLE, Locale.US)); scope.put("replaceMe", "replaced"); m.execute(sw, scope); assertEquals(getContents(root, "bundles_pre_labels.txt"), sw.toString()); }
@Test public void testPostLabels() throws MustacheException, IOException, ExecutionException, InterruptedException { MustacheFactory c = new DefaultMustacheFactory(root); Mustache m = c.compile("bundles.html"); StringWriter sw = new StringWriter(); Map<String, Object> scope = new HashMap<>(); scope.put("trans", BundleFunctions.newPostTranslate(BUNDLE, Locale.US)); scope.put("replaceMe", "replaced"); m.execute(sw, scope); assertEquals(getContents(root, "bundles_post_labels.txt"), sw.toString()); }
@Test public void testPreNullLabels() throws MustacheException, IOException, ExecutionException, InterruptedException { MustacheFactory c = new DefaultMustacheFactory(root); Mustache m = c.compile("bundles.html"); StringWriter sw = new StringWriter(); Map<String, Object> scope = new HashMap<>(); scope.put("trans", BundleFunctions.newPreTranslateNullableLabel(BUNDLE, Locale.US)); scope.put("replaceMe", "replaced"); m.execute(sw, scope); assertEquals(getContents(root, "bundles_nulllabels.txt"), sw.toString()); }
@Test public void testMultipleExtensions() throws MustacheException, IOException, ExecutionException, InterruptedException { MustacheFactory c = new DefaultMustacheFactory(root); Mustache m = c.compile("multipleextensions.html"); StringWriter sw = new StringWriter(); m.execute(sw, new Object()); assertEquals(getContents(root, "multipleextensions.txt"), sw.toString()); }
public void render() { output.mkdirs(); copyStaticAssets(); generateCssFromLess(); writeResultJson(); MustacheFactory mustacheFactory = new DefaultMustacheFactory(); generateTvHtml(mustacheFactory); generateIndexHtml(mustacheFactory); generateDeviceHtml(mustacheFactory); generateTestHtml(mustacheFactory); generateLogHtml(mustacheFactory); saveRawLog(); }
@Test public void testParentReplace() throws MustacheException, IOException, ExecutionException, InterruptedException { MustacheFactory c = new DefaultMustacheFactory(root); Mustache m = c.compile("replace.html"); StringWriter sw = new StringWriter(); m.execute(sw, new Object() { String replace = "false"; }); assertEquals(getContents(root, "replace.txt"), sw.toString()); }
public void testMalformedTag() { try { String template = "\n{{$value}}\n{/value}}"; Mustache mustache = new DefaultMustacheFactory().compile(new StringReader(template), "test"); StringWriter sw = new StringWriter(); mustache.execute(sw, new Object[0]); fail("Should have failed to compile"); } catch (MustacheException e) { assertEquals("Failed to close 'value' tag @[test:2]", e.getMessage()); } }
@Test public void testNested() throws IOException { MustacheFactory c = new DefaultMustacheFactory(root); Mustache m = c.compile("nested_inheritance.html"); StringWriter sw = new StringWriter(); m.execute(sw, new Object() {}); assertEquals(getContents(root, "nested_inheritance.txt"), sw.toString()); }
@Test public void testSubSubCaching() throws MustacheException, IOException, ExecutionException, InterruptedException { MustacheFactory c = new DefaultMustacheFactory(root); Mustache m = c.compile("subsubchild1.html"); StringWriter sw = new StringWriter(); m.execute(sw, new Object() {}); assertEquals(getContents(root, "subsubchild1.txt"), sw.toString()); m = c.compile("subsubchild2.html"); sw = new StringWriter(); m.execute(sw, new Object() {}); assertEquals(getContents(root, "subsubchild2.txt"), sw.toString()); }