Search in sources :

Example 1 with JSONLiteral

use of org.apache.tapestry5.json.JSONLiteral in project tapestry-5 by apache.

the class ModuleManagerImpl method addModuleToConfig.

private void addModuleToConfig(JSONObject config, String name, JavaScriptModuleConfiguration module) {
    JSONObject shimConfig = config.in("shim");
    boolean nestDependencies = false;
    String exports = module.getExports();
    if (exports != null) {
        shimConfig.in(name).put("exports", exports);
        nestDependencies = true;
    }
    String initExpression = module.getInitExpression();
    if (initExpression != null) {
        String function = String.format("function() { return %s; }", initExpression);
        shimConfig.in(name).put("init", new JSONLiteral(function));
        nestDependencies = true;
    }
    List<String> dependencies = module.getDependencies();
    if (dependencies != null) {
        JSONObject container = nestDependencies ? shimConfig.in(name) : shimConfig;
        String key = nestDependencies ? "deps" : name;
        for (String dep : dependencies) {
            container.append(key, dep);
        }
    }
}
Also used : JSONObject(org.apache.tapestry5.json.JSONObject) JSONLiteral(org.apache.tapestry5.json.JSONLiteral)

Aggregations

JSONLiteral (org.apache.tapestry5.json.JSONLiteral)1 JSONObject (org.apache.tapestry5.json.JSONObject)1