Package com.github.mustachejava

Examples of com.github.mustachejava.Mustache


    }

    @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);
        assertEquals(getContents(root, "bundles_post_labels.txt"), sw.toString());
    }
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);
        assertEquals(getContents(root, "bundles_nulllabels.txt"), sw.toString());
    }
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);
        assertEquals(getContents(root, "bundles_nulllabels.txt"), sw.toString());
    }
View Full Code Here

    }
  }

  public void testSingleThreaded() throws MustacheException, IOException, InterruptedException {
    if (skip()) return;
    final Mustache parse = getMustache();
    final Object parent = getScope();

    singlethreaded(parse, parent);
  }
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

    return new DefaultMustacheFactory(root);
  }

  public void testMultithreaded() throws IOException, InterruptedException {
    if (skip()) return;
    final Mustache parse = getMustache();
    final Object parent = getScope();

    final AtomicInteger runs = new AtomicInteger(0);
    ExecutorService es = Executors.newCachedThreadPool();
    int range = (int) Math.round(Runtime.getRuntime().availableProcessors() * 1.5 + 1);
    for (int threads = 1; threads < range; threads++) {
      final Semaphore semaphore = new Semaphore(threads);
      {
        long start = System.currentTimeMillis();
        while (true) {
          semaphore.acquire();
          es.submit(new Runnable() {
            @Override
            public void run() {
              parse.execute(new NullWriter(), new Object[] { parent });
              runs.incrementAndGet();
              semaphore.release();
            }
          });
          if (System.currentTimeMillis() - start > TIME * 1000) {
View Full Code Here

  @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

    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 class InverterTest extends InvertUtils {

  @Test
  public void testParser() throws IOException {
    DefaultMustacheFactory dmf = new DefaultMustacheFactory();
    Mustache compile = dmf.compile("fdbcli.mustache");
    Path file = getPath("src/test/resources/fdbcli.txt");
    String txt = new String(Files.readAllBytes(file), "UTF-8");
    Node invert = compile.invert(txt);
    System.out.println(invert);
  }
View Full Code Here

  }

  @Test
  public void testSimple() throws IOException {
    DefaultMustacheFactory dmf = new DefaultMustacheFactory();
    Mustache test = dmf.compile(new StringReader("test {{value}} test"), "test");
    Node invert = test.invert("test value test");
    Node node = new Node();
    node.put("value", value("value"));
    assertEquals(node, invert);
  }
View Full Code Here

TOP

Related Classes of com.github.mustachejava.Mustache

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.