Package com.github.mustachejava

Examples of com.github.mustachejava.Mustache


        try {
            final ClassLoader loader = FirstClassCompiler.class.getClassLoader();
            thread.setContextClassLoader(loader);

            final MustacheFactory factory = new DefaultMustacheFactory();
            final Mustache mustache = factory.compile("templates/template.mustache");

            try {
                final Filer filer = processingEnv.getFiler();
                final JavaFileObject file = filer.createSourceFile(type.getName().getQualified());

                try (Writer writer = file.openWriter()) {
                    mustache.execute(writer, type).flush();
                }
            } catch (IOException e) {
                throw new IllegalArgumentException(e);
            }
        } finally {
View Full Code Here


        try {
            final ClassLoader loader = FunctorCompiler.class.getClassLoader();
            thread.setContextClassLoader(loader);

            final MustacheFactory factory = new DefaultMustacheFactory();
            final Mustache mustache = factory.compile("templates/template.mustache");

            try {
                final Filer filer = processingEnv.getFiler();
                final JavaFileObject file = filer.createSourceFile(type.getName().getQualified());

                try (Writer writer = file.openWriter()) {
                    mustache.execute(writer, type).flush();
                }
            } catch (IOException e) {
                throw new IllegalArgumentException(e);
            }
        } finally {
View Full Code Here

  }

  private String render(Class<?> templateClass, Context context) {
    try {

      Mustache mustache = mustaches.compile(templateClass);

      StringWriter writer = new StringWriter();
      Map<?, ?> scope = toMustacheScope(context);

      Writer execute = mustache.execute(writer, scope);
      execute.flush();

      return writer.toString();

    } catch (IOException e) {
View Full Code Here

        this.scopes = scopes;
        this.scopes.put("static", new TemplateFunctions());

        final MustacheFactory mf = new DefaultMustacheFactory();
        final Mustache mustache = mf.compile(new StringReader(template.getText()), template.getName());

        final Map<String, Object> mappers = getCompiledMapFromMappers(template.getMappersAsMap());
        this.scopes.putAll(mappers);

        final StringWriter stringWriter = new StringWriter();
        mustache.execute(stringWriter, this.scopes);

        return stringWriter.toString();
    }
View Full Code Here

        final MustacheFactory mf = new DefaultMustacheFactory();

        if (data != null) {
            for (final Map.Entry<String, String> entry : data.entrySet()) {

                final Mustache mappersMustache = mf.compile(new StringReader(entry.getValue()), "");
                final StringWriter stringWriter = new StringWriter();

                mappersMustache.execute(stringWriter, this.scopes);
                String url = stringWriter.toString();
                if (!url.startsWith("http")) {
                    url = this.scopes.get("BASE_URI") + url;
                }
                try {
View Full Code Here

        String subject = jsonTemplate.getString("subject");
        String body = jsonTemplate.getString("body");
       
        MustacheFactory mf = new DefaultMustacheFactory();
       
        Mustache titleTemplate = mf.compile(new StringReader(subject), "subject");
        Mustache bodyTemplate = mf.compile(new StringReader(body), "body");
       
        // Subject
        {
          StringWriter sw = new StringWriter();
          titleTemplate.execute(sw, parameters);
          String formatted = sw.toString();
          message.setSubject(formatted);
        }
   
        // Body
        {
          StringWriter sw = new StringWriter();
          bodyTemplate.execute(sw, parameters);
          String formatted = sw.toString();
          message.setHtmlContent(formatted);
        }
      } catch(Exception e) {
        logger.error("Unable load CouchDb e-mail template",e);
View Full Code Here

  /** */
  public static void external_template_with_HelloMustache_object() throws IOException {
    MustacheFactory mf = new DefaultMustacheFactory();

    Mustache mustache = mf.compile("template.mustache");

    Writer stdout = new OutputStreamWriter(System.out);
    mustache.execute( stdout, new HelloMustache() );
    stdout.flush();
  }
View Full Code Here

    HashMap<String, Object> scopes = new HashMap<String, Object>();
    scopes.put("name", "Mustache");
    scopes.put("feature", new Feature("Perfect!"));

    Mustache mustache = mf.compile(new StringReader("{{name}}, {{feature.description}}!"), "example");

    Writer stdout = new OutputStreamWriter(System.out);
    mustache.execute(stdout, scopes);
    stdout.flush();
  }
View Full Code Here

     * @throws IOException
     *             if an error occurred during write
     */
    public void generate(Writer writer) throws IOException {
        MustacheFactory mf = new DefaultMustacheFactory();
        Mustache mustache = mf.compile("data/t2flow/workflow.mustache");
        mustache.execute(writer, workflow).flush();
    }
View Full Code Here

        try {
            final ClassLoader loader = HammockCompiler.class.getClassLoader();
            thread.setContextClassLoader(loader);

            final MustacheFactory factory = new DefaultMustacheFactory();
            final Mustache mustache = factory.compile("templates/template.mustache");

            try {
                final Filer filer = processingEnv.getFiler();
                final JavaFileObject file = filer.createSourceFile(type.getName().getQualified());

                try (Writer writer = file.openWriter()) {
                    mustache.execute(writer, type).flush();
                }
            } catch (IOException e) {
                throw new IllegalArgumentException(e);
            }
        } finally {
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.