Package com.github.mustachejava

Examples of com.github.mustachejava.Mustache.execute()


    }
    fortunes.add(new Fortune(0, "Additional fortune added at request time."));
    Collections.sort(fortunes);
    Mustache mustache = mustacheFactory.compile("hello/fortunes.mustache");
    StringWriter writer = new StringWriter();
    mustache.execute(writer, fortunes);
    exchange.getResponseHeaders().put(
        Headers.CONTENT_TYPE, HTML_UTF8);
    exchange.getResponseSender().send(writer.toString());
  }
}
View Full Code Here


    }
    fortunes.add(new Fortune(0, "Additional fortune added at request time."));
    Collections.sort(fortunes);
    Mustache mustache = mustacheFactory.compile("hello/fortunes.mustache");
    StringWriter writer = new StringWriter();
    mustache.execute(writer, fortunes);
    exchange.getResponseHeaders().put(
        Headers.CONTENT_TYPE, HTML_UTF8);
    exchange.getResponseSender().send(writer.toString());
  }
}
View Full Code Here

         */
        Mustache mustache = mf.compile(mustacheName);
       
        try {
           
            mustache.execute(response.getWriter(), attributes);
           
        } catch (Exception e) {
            throw new RuntimeException("error processing mustache : " + mustacheName, e);
        }
    }
View Full Code Here

  public static void main(String[] args) throws IOException {
    DeferringMustacheFactory mf = new DeferringMustacheFactory();
    mf.setExecutorService(Executors.newCachedThreadPool());
    Mustache m = mf.compile("deferring.mustache");
    PrintWriter pw = new PrintWriter(System.out);
    m.execute(pw, new DeferredExample()).close();
  }
}
View Full Code Here

  }

  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

    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());
  }

  protected String getContents(File root, String file) throws IOException {
    BufferedReader br = new BufferedReader(new InputStreamReader(new FileInputStream(new File(root, file)),"UTF-8"));
View Full Code Here

  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();
    assertEquals("0: first: First\n1: Second\n2: Third\n3: last: Last\n", sw.toString());
  }
View Full Code Here

      }
    });
    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();
    assertEquals("0: first: First\n1: Second\n2: Third\n3: last: Last\n", sw.toString());
  }
}
View Full Code Here

    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());
  }

  protected String getContents(File root, String file) throws IOException {
    BufferedReader br = new BufferedReader(new InputStreamReader(new FileInputStream(new File(root, file)),"UTF-8"));
View Full Code Here

        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);
        assertEquals(getContents(root, "bundles_pre_labels.txt"), sw.toString());
    }

    @Test
    public void testPostLabels() throws MustacheException, IOException, ExecutionException, InterruptedException {
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.