Package com.github.mustachejava

Examples of com.github.mustachejava.Mustache


          ((Number) object.get("_id")).intValue(),
          (String) object.get("message")));
    }
    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


            resultSet.getString("message")));
      }
    }
    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

        MustacheFactory mf = (MustacheFactory)properties.getProperty(CONFIG_PROPERTY);
       
        /*
         * the DefaultMustacheFactory caches the template once compiled
         */
        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

    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();
    assertEquals("0: first: First\n1: Second\n2: Third\n3: last: Last\n", sw.toString());
  }
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();
    assertEquals("0: first: First\n1: Second\n2: Third\n3: last: Last\n", sw.toString());
  }
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);
        assertEquals(getContents(root, "bundles_pre_labels.txt"), sw.toString());
    }
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.