Package com.github.mustachejava

Examples of com.github.mustachejava.DefaultMustacheFactory


    private static File root;
    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


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

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

        assertEquals(getContents(root, "bundles_nulllabels.txt"), sw.toString());
    }

    @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

    for (int i = 0; i < 3; i++) {
      {
        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

      }
    }
  }

  protected DefaultMustacheFactory createMustacheFactory() {
    return new DefaultMustacheFactory(root);
  }
View Full Code Here

      }};
    };
  }

  private Mustache getMustache() {
    DefaultMustacheFactory mb = createMustacheFactory();
    return mb.compile("timeline.mustache");
  }
View Full Code Here

  private static File root;

  @Test
  public void testComplex() throws IOException {
    Object context = makeComplex();
    DefaultMustacheFactory mf = new DefaultMustacheFactory(root);
    mf.setObjectHandler(new JRubyObjectHandler());
    Mustache m = mf.compile("complex.html");
    Writer writer = complextest(m, context);
    assertEquals(getContents(root, "complex.txt"), writer.toString());
  }
View Full Code Here

  public void testComplexBench() throws MustacheException, IOException {
    if (skip()) return;
    System.out.println("complex.html evaluations per millisecond:");
    for (int i = 0; i < 3; i++) {
      {
        DefaultMustacheFactory cf = new DefaultMustacheFactory();
        cf.setObjectHandler(new JRubyObjectHandler());
        Mustache m = cf.compile("complex.html");
        Object context = makeComplex();
        assertEquals(getContents(root, "complex.txt"), complextest(m, context).toString());
        long start = System.currentTimeMillis();
        int total = 0;
        while (true) {
          complextest(m, context);
          total++;
          if (System.currentTimeMillis() - start > TIME) break;
        }
        System.out.println("Ruby: " + total / TIME);
      }
      {
        DefaultMustacheFactory cf = new DefaultMustacheFactory();
        Mustache m = cf.compile("complex.html");
        Object context = new ComplexObject();
        assertEquals(getContents(root, "complex.txt"), complextest(m, context).toString());
        long start = System.currentTimeMillis();
        int total = 0;
        while (true) {
View Full Code Here

  public void testCompiler() {
  }

  @Override
  protected DefaultMustacheFactory createMustacheFactory() {
    DefaultMustacheFactory mf = new DefaultMustacheFactory();
    mf.setObjectHandler(new SimpleObjectHandler());
    return mf;
  }
View Full Code Here

TOP

Related Classes of com.github.mustachejava.DefaultMustacheFactory

Copyright © 2018 www.massapicom. 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.