All Downloads are FREE. Search and download functionalities are using the official Maven repository.

net.dreamlu.ext.render.JadeRenderFactory Maven / Gradle / Ivy

The newest version!
package net.dreamlu.ext.render;

import com.jfinal.core.JFinal;
import com.jfinal.kit.PathKit;
import com.jfinal.render.IMainRenderFactory;
import com.jfinal.render.Render;

import de.neuland.jade4j.JadeConfiguration;
import de.neuland.jade4j.template.FileTemplateLoader;
import de.neuland.jade4j.template.TemplateLoader;

/**
 * JFinal-jade-extension
 * 
 * @author L.cm
 */
public class JadeRenderFactory implements IMainRenderFactory {

	private static String encoding = "UTF-8";
	public static String viewExtension = ".jade";
	public static JadeConfiguration config = null;
	
	public JadeRenderFactory() {
		init(PathKit.getWebRootPath());
	}

	private void init(String root) {
		if (config == null) {
			config = new JadeConfiguration();
		}

		TemplateLoader loader = new FileTemplateLoader(root, encoding);
		config.setTemplateLoader(loader);
		boolean devMode = JFinal.me().getConstants().getDevMode();
		if (devMode) {
			config.setCaching(false);
			config.setPrettyPrint(true);
		}
	}

	public Render getRender(String view) {
		return new JadeRender(config, view);
	}

	public String getViewExtension() {
		return viewExtension;
	}
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy