@Override public long getLastModified(final String name) throws IOException { return loader.getLastModified(name); }
@Override public String getExtension() { return loader.getExtension(); }
@Override public Reader getReader(final String name) throws IOException { try { return loader.getReader(name); } catch (NullPointerException ex) { throw new FileNotFoundException(name); } }
private JadeTemplate createTemplate(String name) throws JadeException, IOException { JadeTemplate template = new JadeTemplate(); Parser parser = new Parser(name, basePath, templateLoader, expressionHandler); Node root = parser.parse(); template.setTemplateLoader(templateLoader); template.setExpressionHandler(expressionHandler); template.setRootNode(root); template.setPrettyPrint(prettyPrint); template.setMode(getMode()); return template; }
private static JadeTemplate createTemplate(String filename, String basePath, TemplateLoader loader, ExpressionHandler expressionHandler) throws IOException { Parser parser = new Parser(filename, basePath, loader, expressionHandler); Node root = parser.parse(); JadeTemplate template = new JadeTemplate(); template.setExpressionHandler(expressionHandler); template.setTemplateLoader(loader); template.setRootNode(root); return template; }
private JadeTemplate getJadeTemplate(String name) throws IOException { Parser parser = new Parser("templates/" + name, JadeTemplateLoader.JADE_LOADER); Node root = parser.parse(); final JadeTemplate jadeTemplate = new JadeTemplate(); jadeTemplate.setTemplateLoader(JadeTemplateLoader.JADE_LOADER); jadeTemplate.setRootNode(root); return jadeTemplate; }
public static void render(JadeTemplate template, Map<String, Object> model, Writer writer, boolean pretty) throws JadeCompilerException { template.setPrettyPrint(pretty); template.process(new JadeModel(model), writer); }
private static String templateToString(JadeTemplate template, Map<String, Object> model) throws JadeCompilerException { JadeModel jadeModel = new JadeModel(model); StringWriter writer = new StringWriter(); template.process(jadeModel, writer); return writer.toString(); }
public static String render(JadeTemplate template, Map<String, Object> model, boolean pretty) throws JadeCompilerException { template.setPrettyPrint(pretty); return templateToString(template, model); }
private String getInterpolatedAttributeValue(String name, Object attribute, boolean escaped, JadeModel model, JadeTemplate template) throws JadeCompilerException { // if (!preparedAttributeValues.containsKey(name)) { // preparedAttributeValues.put(name, Utils.prepareInterpolate((String) attribute, escaped)); // } List<Object> prepared = Utils.prepareInterpolate((String) attribute, escaped); try { return Utils.interpolate(prepared, model,template.getExpressionHandler()); } catch (ExpressionException e) { throw new JadeCompilerException(this, template.getTemplateLoader(), e); } }
@Override public long getLastModified(String name) throws IOException { checkName(name); return -1; }
@Override public void configure(final Env env, final Config conf, final Binder binder) { JadeConfiguration jadeconf = new JadeConfiguration(); boolean dev = env.name().equals("dev"); boolean caching = conf.hasPath("jade.caching") ? conf.getBoolean("jade.caching") : !dev; boolean prettyPrint = conf.hasPath("jade.prettyprint") ? conf.getBoolean("jade.prettyprint") : dev; jadeconf.setCaching(caching); jadeconf.setPrettyPrint(prettyPrint); Map<String, Object> sharedVariables = new HashMap<>(2); sharedVariables.put("env", env); sharedVariables.put("xss", new XssHelper(env)); jadeconf.setSharedVariables(sharedVariables); String ext = suffix.startsWith(".") ? suffix.substring(1) : suffix; jadeconf.setTemplateLoader(new ClasspathTemplateLoader("UTF-8", ext)); if (callback != null) { callback.accept(jadeconf, conf); } // rewrite template loader avoid NPE jadeconf.setTemplateLoader(new IOTemplateLoader(jadeconf.getTemplateLoader())); binder.bind(JadeConfiguration.class) .toInstance(jadeconf); Multibinder.newSetBinder(binder, Renderer.class).addBinding() .toInstance(new Engine(jadeconf, suffix)); }
public long getLastModified(String name) { File templateSource = getFile(name); return templateSource.lastModified(); }
public boolean isSelfClosing(JadeTemplate template) { return !template.isXml() && ArrayUtils.contains(selfClosingTags, name); } }
public boolean isTerse(JadeTemplate template) { return isSelfClosing(template) && template.isTerse(); }
public void renderTemplate(JadeTemplate template, Map<String, Object> model, Writer writer) throws JadeCompilerException { JadeModel jadeModel = new JadeModel(sharedVariables); for (String filterName : filters.keySet()) { jadeModel.addFilter(filterName, filters.get(filterName)); } jadeModel.putAll(model); template.process(jadeModel, writer); }
private String ensureJadeExtension(String templateName) { if (!templateLoader.getExtension().equals(FilenameUtils.getExtension(templateName))) { return templateName + "."+templateLoader.getExtension(); } return templateName; }
public boolean templateExists(String url) { try { return templateLoader.getReader(url) != null; } catch (IOException e) { return false; } }
public static String render(String filename, Map<String, Object> model, boolean pretty) throws IOException, JadeCompilerException { JadeTemplate template = getTemplate(filename); template.setPrettyPrint(pretty); return templateToString(template, model); }
@Override public Reader getReader(String name) throws IOException { checkName(name); return reader; }