de.neuland.jade4j.JadeConfiguration Java Examples

The following examples show how to use de.neuland.jade4j.JadeConfiguration. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: JadeKrazoConfiguration.java    From krazo with Apache License 2.0 6 votes vote down vote up
@Produces
@ViewEngineConfig
JadeConfiguration produce() {
    loadConfig();
    JadeConfiguration jade = new JadeConfiguration();
    jade.setMode(Mode.valueOf(property(MODE).orElse("XHTML")));
    jade.setCaching(Boolean.valueOf(property(CACHING).orElse("true")));
    jade.setPrettyPrint(Boolean.valueOf(property(PRETTY_PRINT).orElse("false")));
    getExtensions(FILTER_QUALIFIER).entrySet().forEach(filter -> {
        jade.setFilter(filter.getKey(), (Filter) filter.getValue());
    });
    jade.setSharedVariables(getExtensions(HELPER_QUALIFIER));
    String encoding = property(ENCODING).orElse("UTF-8");
    jade.setTemplateLoader(new ServletContextTemplateLoader(servletContext, encoding));
    return jade;
}
 
Example #2
Source File: ViewJade.java    From baratine with GNU General Public License v2.0 6 votes vote down vote up
private void init()
{
  TemplateLoader templateLoader = null;

  String templatePath = _config.get("view.jade.templates",
                                    "classpath:/templates");

  if (templatePath.startsWith("classpath:")) {
    String root = templatePath.substring("classpath:".length());

    templateLoader = new ClasspathTemplateLoader(root);
  }
  else {
    templateLoader = new FileTemplateLoader(templatePath, "UTF-8");
  }

  _jadeConfig = new JadeConfiguration();
  _jadeConfig.setTemplateLoader(templateLoader);
}
 
Example #3
Source File: JadeOzarkConfiguration.java    From ozark with Apache License 2.0 6 votes vote down vote up
@Produces
@ViewEngineConfig
JadeConfiguration produce() {
    loadConfig();
    JadeConfiguration jade = new JadeConfiguration();
    jade.setMode(Mode.valueOf(property(MODE).orElse("XHTML")));
    jade.setCaching(Boolean.valueOf(property(CACHING).orElse("true")));
    jade.setPrettyPrint(Boolean.valueOf(property(PRETTY_PRINT).orElse("false")));
    getExtensions(FILTER_QUALIFIER).entrySet().forEach(filter -> {
        jade.setFilter(filter.getKey(), (Filter) filter.getValue());
    });
    jade.setSharedVariables(getExtensions(HELPER_QUALIFIER));
    String encoding = property(ENCODING).orElse("UTF-8");
    jade.setTemplateLoader(new ServletContextTemplateLoader(servletContext, encoding));
    return jade;
}
 
Example #4
Source File: JadeTemplateEngine.java    From pippo with Apache License 2.0 6 votes vote down vote up
@Override
public void init(Application application) {
    super.init(application);

    Router router = getRouter();
    PippoSettings pippoSettings = getPippoSettings();

    configuration = new JadeConfiguration();
    configuration.setTemplateLoader(new ClassTemplateLoader(JadeTemplateEngine.class, getTemplatePathPrefix()));
    configuration.setMode(Mode.HTML);
    if (pippoSettings.isDev()) {
        configuration.setPrettyPrint(true);
        configuration.setCaching(false); // disable cache
    }

    // set global template variables
    configuration.getSharedVariables().put("contextPath", router.getContextPath());
    configuration.getSharedVariables().put("appPath", router.getApplicationPath());

    // allow custom initialization
    init(application, configuration);
}
 
Example #5
Source File: Jade4jTemplateConfiguration.java    From apm-agent-java with Apache License 2.0 5 votes vote down vote up
@Bean
public JadeConfiguration jadeConfiguration() {
    JadeConfiguration configuration
        = new JadeConfiguration();
    configuration.setCaching(false);
    configuration.setTemplateLoader(templateLoader());
    return configuration;
}
 
Example #6
Source File: WebMvcConfig.java    From spring-comparing-template-engines with Apache License 2.0 5 votes vote down vote up
@Bean
public ViewResolver jadeViewResolver() {
	JadeViewResolver viewResolver = new JadeViewResolver();
	viewResolver.setPrefix("/WEB-INF/jade/");
	viewResolver.setSuffix(".jade");
	viewResolver.setViewNames("*-jade");
	viewResolver.setRenderExceptions(true);
	viewResolver.setCache(false);
	viewResolver.setConfiguration(applicationContext.getBean(JadeConfiguration.class));

	return viewResolver;
}
 
Example #7
Source File: WebMvcConfig.java    From spring-comparing-template-engines with Apache License 2.0 5 votes vote down vote up
@Bean
public JadeConfiguration jadeConfiguration() {
	JadeConfiguration config = new JadeConfiguration();
	config.setPrettyPrint(true);
	config.setCaching(false);
	config.setTemplateLoader(applicationContext.getBean(SpringTemplateLoader.class));

	return config;
}
 
Example #8
Source File: JadeTemplateConfiguration.java    From tutorials with MIT License 5 votes vote down vote up
@Bean
public JadeConfiguration jadeConfiguration() {
    JadeConfiguration configuration = new JadeConfiguration();
    configuration.setCaching(false);
    configuration.setTemplateLoader(templateLoader());
    return configuration;
}
 
Example #9
Source File: JadeTemplateEngine.java    From pippo with Apache License 2.0 5 votes vote down vote up
@Override
public void renderString(String templateContent, Map<String, Object> model, Writer writer) {
    // prepare the locale-aware i18n method
    String language = (String) model.get(PippoConstants.REQUEST_PARAMETER_LANG);
    if (StringUtils.isNullOrEmpty(language)) {
        language = getLanguageOrDefault(language);
    }

    // prepare the locale-aware prettyTime method
    Locale locale = (Locale) model.get(PippoConstants.REQUEST_PARAMETER_LOCALE);
    if (locale == null) {
        locale = getLocaleOrDefault(language);
    }

    model.put("pippo", new PippoHelper(getMessages(), language, locale, getRouter()));
    try (StringReader reader = new StringReader(templateContent)) {
        ReaderTemplateLoader stringTemplateLoader = new ReaderTemplateLoader(reader, "StringTemplate");

        JadeConfiguration stringTemplateConfiguration = new JadeConfiguration();
        stringTemplateConfiguration.setCaching(false);
        stringTemplateConfiguration.setTemplateLoader(stringTemplateLoader);
        stringTemplateConfiguration.setMode(configuration.getMode());
        stringTemplateConfiguration.setPrettyPrint(configuration.isPrettyPrint());

        JadeTemplate stringTemplate = configuration.getTemplate("StringTemplate");
        configuration.renderTemplate(stringTemplate, model, writer);
        writer.flush();
    } catch (Exception e) {
        throw new PippoRuntimeException(e);
    }
}
 
Example #10
Source File: JadeTemplateEngineImpl.java    From vertx-web with Apache License 2.0 4 votes vote down vote up
@Override
public JadeConfiguration getJadeConfiguration() {
  return config;
}
 
Example #11
Source File: SingularityMainModule.java    From Singularity with Apache License 2.0 4 votes vote down vote up
private JadeTemplate getJadeTemplate(String name) throws IOException {
  JadeConfiguration config = new JadeConfiguration();
  config.setTemplateLoader(new ClasspathTemplateLoader());
  return config.getTemplate("templates/" + name);
}
 
Example #12
Source File: JadeOzarkConfiguration.java    From ozark with Apache License 2.0 4 votes vote down vote up
void dispose(@Disposes @ViewEngineConfig JadeConfiguration jade) {
    jade.clearCache();
}
 
Example #13
Source File: JadeKrazoConfiguration.java    From krazo with Apache License 2.0 4 votes vote down vote up
void dispose(@Disposes @ViewEngineConfig JadeConfiguration jade) {
    jade.clearCache();
}
 
Example #14
Source File: SparkApplicationHelper.java    From uyuni with GNU General Public License v2.0 4 votes vote down vote up
/**
 * Sets up this application and the Jade engine.
 * @return the jade template engine
 */
public static JadeTemplateEngine setup() {
    // set up shared variables
    Map<String, Object> sharedVariables = new HashMap<>();

    // this filter is evaluated before every request
    Spark.before((request, response) -> {
        // add the current request to shared variables
        sharedVariables.put("request", request);
        // default for text/html or OpenSynphony will complain
        response.type("text/html");
        // init the flash scope
        FlashScopeHelper.handleFlashData(request, response);
    });

    // set up template engine
    JadeTemplateEngine jade = new JadeTemplateEngine(TEMPLATE_ROOT);

    // set up i10n engine and other default template variables
    sharedVariables.put("l", Languages.getInstance());
    sharedVariables.put("h", ViewHelper.getInstance());
    sharedVariables.put("isDevMode",
            Config.get().getBoolean("java.development_environment"));
    sharedVariables.put("isUyuni", ConfigDefaults.get().isUyuni());
    sharedVariables.put("webVersion", ConfigDefaults.get().getProductVersion());
    sharedVariables.put("webBuildtimestamp", Config.get().getString("web.buildtimestamp"));
    JadeConfiguration config = jade.configuration();
    config.setSharedVariables(sharedVariables);

    // capture json endpoint exceptions, let others pass (resulting in status code 500)
    Spark.exception(RuntimeException.class, (e, request, response) -> {
        if (request.headers("accept").contains("json")) {
            Map<String, Object> exc = new HashMap<>();
            exc.put("message", e.getMessage());
            response.type("application/json");
            response.body(GSON.toJson(exc));
            response.status(HttpStatus.SC_INTERNAL_SERVER_ERROR);
        }
        else {
            throw (RuntimeException) e;
        }
    });

    return jade;
}
 
Example #15
Source File: JadeTemplateEngine.java    From spark-template-engines with Apache License 2.0 2 votes vote down vote up
/**
 * Access to the internal JadeConfiguration
 *
 * @return The JadeConfiguration used by this engine
 */
public JadeConfiguration configuration() {
    return configuration;
}
 
Example #16
Source File: JadeTemplateEngine.java    From vertx-web with Apache License 2.0 2 votes vote down vote up
/**
 * Get a reference to the internal JadeConfiguration object so it
 * can be configured.
 *
 * @return a reference to the internal JadeConfiguration instance.
 */
@GenIgnore
JadeConfiguration getJadeConfiguration();
 
Example #17
Source File: JadeTemplateEngine.java    From spark-template-engines with Apache License 2.0 2 votes vote down vote up
/**
 * Construct a jade template engine from a raw JadeConfiguration
 *
 * @param configuration the raw JadeConfiguration to use
 */
public JadeTemplateEngine(JadeConfiguration configuration) {
    this.configuration = configuration;
}
 
Example #18
Source File: JadeTemplateEngine.java    From spark-template-engines with Apache License 2.0 2 votes vote down vote up
/**
 * Construct a jade template engine with specified root.
 *
 * @param templateRoot the template root directory to use
 */
public JadeTemplateEngine(String templateRoot) {
    configuration = new JadeConfiguration();
    configuration.setTemplateLoader(new SparkClasspathTemplateLoader(templateRoot));
}
 
Example #19
Source File: JadeTemplateEngine.java    From pippo with Apache License 2.0 2 votes vote down vote up
/**
 * Override this method if you want to modify the template configuration.
 *
 * @param application
 * @param configuration
 */
protected void init(Application application, JadeConfiguration configuration) {
}