コード例 #1
0
 public CompiledMustacheTemplates() {
   mf = new DefaultMustacheFactory();
   processesMustache = mf.compile("templates/processes.mustache");
   productFiltersMustache = mf.compile("templates/productfilters.mustache");
   compactProductsMustache = mf.compile("templates/compactproducts.mustache");
   productMustache = mf.compile("templates/product.mustache");
 }
コード例 #2
0
 /**
  * Generates html page containing the NGL canvas.
  *
  * @param directory path to the job directory
  * @param inputName the input: either a PDB id or the file name as input by user
  * @param strucFile the file with the AU structure (can be cif or pdb and gzipped or not)
  * @param strucURI URL to reach auCifFile within the browser
  * @param title Page title [default: structure name]
  * @param size the canvas size
  * @param jsonURI path to the json dataURL
  * @param interfaces List of all interfaces to build the latticegraph
  * @param requestedIfaces subset of the interfaces to display
  * @param out Stream to output the HTML page
  * @param urlMolViewer path to the libURL
  * @throws StructureException For errors parsing the input structure
  * @throws IOException For errors reading or writing files
  */
 public static void generateHTMLPage(
     File directory,
     String inputName,
     File strucFile,
     String strucURI,
     String title,
     String size,
     String jsonURL,
     List<Interface> interfaces,
     Collection<Integer> requestedIfaces,
     PrintWriter out,
     String urlMolViewer)
     throws IOException, StructureException {
   logger.info("JSON URL for {}: {}", inputName, jsonURL);
   logger.info("Structure URL for {}: {}", inputName, strucURI);
   MustacheFactory mf = new DefaultMustacheFactory();
   String template = LatticeGUIMustache.expandTemplatePath(TEMPLATE_LATTICE_GUI_NGL_LAZY);
   Mustache mustache = mf.compile(template);
   LazyLatticeGUIMustache3D page = new LazyLatticeGUIMustache3D();
   page.setSize(size);
   page.setTitle(title);
   page.setDataURL(jsonURL);
   page.setLibURL(urlMolViewer);
   page.setStrucURL(strucURI);
   try {
     mustache.execute(out, page).flush();
   } catch (IOException e) {
     logger.error("Error generating output from template " + template, e);
   }
 }
コード例 #3
0
  public void renderAndWrite() throws IOException, ConfigurationException {
    readConfig();
    removeOld();

    InputStreamReader reader;
    BufferedReader bufferedReader;
    File template = new File(templatePath);
    if (!template.isFile() || !template.exists()) {
      LOGGER.error("template for logstash config doesn't exist! ");
      throw new IOException("template for logstash config doesn't exist! ");
    }
    reader = new InputStreamReader(new FileInputStream(template));
    bufferedReader = new BufferedReader(reader);

    File newConf = new File(logstashConfPath);
    Writer writer = new OutputStreamWriter(new FileOutputStream(newConf));
    HashMap<String, Object> m = new HashMap<String, Object>();

    // Add redis host
    m.put("redisHost", redisHost);
    m.put("elasticSearchHost", elasticSearchHost);
    m.put("elasticSearchHttpPort", elasticSearchHttpPort);

    MustacheFactory mf = new DefaultMustacheFactory();
    // TODO: what's the meaning of this tag in mustache's compile
    Mustache mustache = mf.compile(bufferedReader, "example");
    mustache.execute(writer, m);
    writer.flush();

    bufferedReader.close();
    reader.close();
  }
コード例 #4
0
 public String render(Review review) throws IOException {
   MustacheFactory mf = new DefaultMustacheFactory();
   Mustache mustache = mf.compile(TEMPLATE_MUSTACHE);
   Writer sink = new StringWriter();
   mustache.execute(sink, review).flush();
   return sink.toString();
 }
コード例 #5
0
  private String getDefaultTemplate(BinaryResource binaryResource, String uuid) throws IOException {

    MustacheFactory mf = new DefaultMustacheFactory();
    Mustache mustache = mf.compile("com/docdoku/server/viewers/default_viewer.mustache");
    Map<Object, Object> scopes = new HashMap<>();
    scopes.put("uriResource", ViewerUtils.getURI(binaryResource, uuid));
    scopes.put("fileName", binaryResource.getName());
    StringWriter templateWriter = new StringWriter();
    mustache.execute(templateWriter, scopes).flush();

    return ViewerUtils.getViewerTemplate(
        dataManager, binaryResource, uuid, templateWriter.toString());
  }
コード例 #6
0
ファイル: TemplateProviderImpl.java プロジェクト: benjp/juzu
  @Override
  public void process(
      final ProcessContext context, final Template<MustacheContext> mustacheTemplate) {
    // 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);
            Template<MustacheContext> partial =
                (Template<MustacheContext>)
                    context.resolveTemplate(mustacheTemplate.getOrigin(), partialPath);
            if (partial != null) {
              return new StringReader(partial.getModel().source);
            } else {
              return null;
            }
          }

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

    // Does the name count ?
    factory.compile(
        new StringReader(mustacheTemplate.getModel().source),
        mustacheTemplate.getRelativePath().getSimpleName());
  }