Package com.github.mustachejava

Examples of com.github.mustachejava.DefaultMustacheFactory


    public String compile(final Template template, final Map<String, Object> scopes) throws MalformedURLException, IOException {

        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();
View Full Code Here


        return stringWriter.toString();
    }

    private Map<String, Object> getCompiledMapFromMappers(final Map<String, String> data) {

        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")) {
View Full Code Here

  static MustacheFactory resourcesMf() {
    try {
      File tempDir = Files.createTempDir();
      return newMustacheFactoryAt(tempDir);
    } catch (IOException e) {
      return new DefaultMustacheFactory();
    }
  }
View Full Code Here

  private static MustacheFactory newMustacheFactoryAt(File dir) throws IOException {
    copyMustache("duplicata.mustache", dir);
    copyMustache("duplicata-page.mustache", dir);

    return new DefaultMustacheFactory(dir);
  }
View Full Code Here

   
        JSONObject jsonTemplate = doc.getJSONObject("nunaliit_email_template");
        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);
View Full Code Here

  public static MustacheFactory newMustacheFactoryAt(File dir) throws IOException {
    copyMustache("boleto.mustache", dir);
    copyMustache("boleto-inline-css.mustache", dir);
    copyMustache("boleto-page.mustache", dir);

    return new DefaultMustacheFactory(dir);
  }
View Full Code Here

  static MustacheFactory resourcesMf() {
    try {
      File tempDir = Files.createTempDir();
      return newMustacheFactoryAt(tempDir);
    } catch (IOException e) {
      return new DefaultMustacheFactory();
    }
  }
View Full Code Here

    String description;
  }

  /** */
  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

    stdout.flush();
  }

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

    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

  @Override
  public void process(final ProcessContext context, final TemplateModel<MustacheContext> mustacheTemplateModel) {
    // Nothing to do for now

    // Visit the mustache
    MustacheFactory factory = new DefaultMustacheFactory() {

      @Override
      public Reader getReader(String resourceName) {
        Path.Relative partialPath = (Path.Relative)Path.parse(resourceName);
        Timestamped<Resource> partial = context.resolveResource(partialPath);
        if (partial != null) {
          return new StringReader(partial.getObject().getCharSequence().toString());
        } else {
          return null;
        }
      }

      public MustacheVisitor createMustacheVisitor() {
        return new DefaultMustacheVisitor(this) {
          @Override
          public void pragma(TemplateContext templateContext, String pragma, String args) {
            if ("param".equals(pragma)) {
              mustacheTemplateModel.addParameter(args);
            } else {
              super.pragma(templateContext, pragma, args);
            }
          }
        };
      }
    };

    // Does the name count ?
    factory.compile(new StringReader(mustacheTemplateModel.getModel().source), mustacheTemplateModel.getPath().getSimpleName());
  }
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.