use of act.view.VarDef in project actframework by actframework.
the class RythmView method createEngine.
private RythmEngine createEngine(App app) {
AppConfig config = app.config();
Properties p = new Properties();
p.put(ENGINE_MODE.getKey(), Act.mode().isDev() ? Rythm.Mode.dev : Rythm.Mode.prod);
p.put(ENGINE_PLUGIN_VERSION.getKey(), Act.VERSION.getVersion());
p.put(ENGINE_CLASS_LOADER_PARENT_IMPL.getKey(), app.classLoader());
p.put(HOME_TMP.getKey(), createTempHome(app));
Map map = config.rawConfiguration();
for (Object k : map.keySet()) {
String key = k.toString();
if (key.startsWith("rythm.")) {
p.put(key, map.get(key));
}
}
String appRestricted = p.getProperty("rythm.sandbox.restricted_classes", "");
appRestricted += ";act.*";
p.put(SANDBOX_RESTRICTED_CLASS.getKey(), appRestricted);
p.put(HOME_TEMPLATE.getKey(), templateRootDir());
p.put(CODEGEN_SOURCE_CODE_ENHANCER.getKey(), new ISourceCodeEnhancer() {
@Override
public List<String> imports() {
return C.list();
}
@Override
public String sourceCode() {
return "";
}
@Override
public Map<String, ?> getRenderArgDescriptions() {
Map<String, String> map = new HashMap<>();
for (VarDef var : Act.viewManager().implicitActionViewVariables()) {
map.put(var.name(), var.type());
}
return map;
}
@Override
public void setRenderArgs(ITemplate iTemplate) {
// no need to set render args here as
// it's all done at TemplateBase#exposeImplicitVariables
}
});
RythmEngine engine = new RythmEngine(p);
engine.resourceManager().prependResourceLoader(new ClasspathResourceLoader(engine, ID));
if (config.defaultView() == this) {
String home = config.templateHome();
if (S.neq("default", home) && S.neq(ID, home)) {
engine.resourceManager().prependResourceLoader(new ClasspathResourceLoader(engine, home));
}
}
Tags tags = app.getInstance(Tags.class);
tags.register(engine);
return engine;
}
Aggregations