Package com.github.mustachejava

Examples of com.github.mustachejava.DefaultMustacheFactory.compile()


    String description;
  }

  public static void main(String[] args) throws IOException {
    MustacheFactory mf = new DefaultMustacheFactory();
    Mustache mustache = mf.compile("template.mustache");
    mustache.execute(new PrintWriter(System.out), new Example()).flush();
  }
}
View Full Code Here


  private static final String BUNDLE = "com.github.mustachejava.functions.translatebundle";

  @Test
  public void testTranslation() throws MustacheException, IOException, ExecutionException, InterruptedException {
    MustacheFactory c = new DefaultMustacheFactory(root);
    Mustache m = c.compile("translatebundle.html");
    StringWriter sw = new StringWriter();
    Map<String, Object> scope = new HashMap<String, Object>();
    scope.put("trans", new TranslateBundleFunction(BUNDLE, Locale.US));
    m.execute(sw, scope);
    assertEquals(getContents(root, "translatebundle.txt"), sw.toString());
View Full Code Here

public class DecoratedCollectionTest {
  @Test
  public void testIndexLastFirst() throws IOException {
    MustacheFactory mf = new DefaultMustacheFactory();
    Mustache test = mf.compile(new StringReader(
            "{{#test}}{{index}}: {{#first}}first: {{/first}}{{#last}}last: {{/last}}{{value}}\n{{/test}}"), "test");
    StringWriter sw = new StringWriter();
    test.execute(sw, new Object() {
      Collection test = new DecoratedCollection(Arrays.asList("First", "Second", "Third", "Last"));
    }).flush();
View Full Code Here

          return new DecoratedCollection((Collection) object);
        }
        return super.coerce(object);
      }
    });
    Mustache test = mf.compile(new StringReader(
            "{{#test}}{{index}}: {{#first}}first: {{/first}}{{#last}}last: {{/last}}{{value}}\n{{/test}}"), "test");
    StringWriter sw = new StringWriter();
    test.execute(sw, new Object() {
      Collection test = Arrays.asList("First", "Second", "Third", "Last");
    }).flush();
View Full Code Here

  private static File root;

  @Test
  public void testCommentBlock() throws MustacheException, IOException, ExecutionException, InterruptedException {
    MustacheFactory c = new DefaultMustacheFactory(root);
    Mustache m = c.compile("comment.html");
    StringWriter sw = new StringWriter();
    Map scope = new HashMap();
    scope.put("ignored", "ignored");
    m.execute(sw, scope);
    assertEquals(getContents(root, "comment.txt"), sw.toString());
View Full Code Here

    private static final String BUNDLE = "com.github.mustachejava.functions.translatebundle";

    @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<String, Object>();
        scope.put("trans", BundleFunctions.newPreTranslate(BUNDLE, Locale.US));
        scope.put("replaceMe", "replaced");
        m.execute(sw, scope);
View Full Code Here

    }

    @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<String, Object>();
        scope.put("trans", BundleFunctions.newPostTranslate(BUNDLE, Locale.US));
        scope.put("replaceMe", "replaced");
        m.execute(sw, scope);
View Full Code Here

    }

    @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<String, Object>();
        scope.put("trans", BundleFunctions.newPreTranslateNullableLabel(BUNDLE, Locale.US));
        scope.put("replaceMe", "replaced");
        m.execute(sw, scope);
View Full Code Here

    }

    @Test
    public void testPostNullLabels() 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<String, Object>();
        scope.put("trans", BundleFunctions.newPostTranslateNullableLabel(BUNDLE, Locale.US));
        // Intentionally leave off the replacement value
        m.execute(sw, scope);
View Full Code Here

      {
        long start = System.currentTimeMillis();
        int total = 0;
        while (true) {
          DefaultMustacheFactory mb = createMustacheFactory();
          final Mustache parse = mb.compile("timeline.mustache");
          total++;
          if (System.currentTimeMillis() - start > TIME * 1000) break;
        }
        System.out.println("Compilations: " + total / TIME + "/s");
      }
View Full Code Here

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.