r9697 - in helma-ng/trunk/modules: . helma
[email protected] Mon, 4 May 2009 11:07:23 +0200 (CEST)
| Newsgroups | gmane.comp.java.helma.cvs |
|---|---|
| Message-ID | <20090504090723.231DD3D0D6@mia> |
Author: hannes
Date: 2009-05-04 11:07:23 +0200 (Mon, 04 May 2009)
New Revision: 9697
Modified:
helma-ng/trunk/modules/helma/skin.js
helma-ng/trunk/modules/helmaglobal.js
Log:
Remove global parseSkin() function and fold it into helma/skin.createSkin(). Move webapp macro code from render() to Skin.render(), the final solution might be to have a skin proxy in one of the webapp sub-modules.
Details at http://dev.helma.org/trac/helma/changeset/9697
Modified: helma-ng/trunk/modules/helma/skin.js
===================================================================
--- helma-ng/trunk/modules/helma/skin.js 2009-05-04 09:07:21 UTC (rev 9696)
+++ helma-ng/trunk/modules/helma/skin.js 2009-05-04 09:07:23 UTC (rev 9697)
@@ -3,6 +3,7 @@
require('core/string');
require('core/object');
import('helma/logging', 'logging');
+import('helma/system', 'system');
export('render', 'createSkin', 'Skin');
@@ -38,14 +39,6 @@
} else {
throw Error("Unknown skin object: " + skinOrResource);
}
- // extend context by globally provided macros and filters.
- // user-provided context overrides globally defined stuff
- var config = require('helma/webapp/env').config;
- if (config && config.macros instanceof Array) {
- for each (var module in config.macros) {
- context = Object.merge(context, require(module));
- }
- }
return skin.render(context);
}
@@ -63,26 +56,34 @@
var subSkins = {};
var currentSkin = mainSkin;
var parentSkin = null;
- parseSkin(resourceOrString, function(part) {
- if (part.name === 'extends') {
- var skinPath = part.getParameter(0);
- var skinResource;
- if (resourceOrString.parentRepository) {
- skinResource = resourceOrString.parentRepository.getResource(skinPath);
+ var engine = system.getRhinoEngine();
+ var parser = new org.helma.template.SkinParser({
+ renderText: function(text) {
+ currentSkin[currentSkin.length] = text;
+ },
+ renderMacro: function(macro) {
+ engine.wrapArgument(macro, global);
+ if (macro.name === 'extends') {
+ var skinPath = macro.getParameter(0);
+ var skinResource;
+ if (resourceOrString.parentRepository) {
+ skinResource = resourceOrString.parentRepository.getResource(skinPath);
+ }
+ if (!skinResource || !skinResource.exists()) {
+ skinResource = scope.getResource(skinPath);
+ }
+ parentSkin = createSkin(skinResource);
+ } else if (macro.name === 'subskin') {
+ var skinName = macro.getParameter('name', 0);
+ currentSkin = [];
+ currentSkin.subskinFilter = macro.filter;
+ subSkins[skinName] = currentSkin;
+ } else {
+ currentSkin[currentSkin.length] = macro;
}
- if (!skinResource || !skinResource.exists()) {
- skinResource = scope.getResource(skinPath);
- }
- parentSkin = createSkin(skinResource);
- } else if (part.name === 'subskin') {
- var skinName = part.getParameter('name', 0);
- currentSkin = [];
- currentSkin.subskinFilter = part.filter;
- subSkins[skinName] = currentSkin;
- } else {
- currentSkin[currentSkin.length] = part;
}
});
+ parser.parse(resourceOrString);
// normalization: cut trailing whitespace so it's
// easier to tell if main skin should be inherited
var lastPart = mainSkin[mainSkin.length - 1];
@@ -106,6 +107,14 @@
var self = this;
this.render = function render(context) {
+ // extend context by globally provided macros and filters.
+ // user-provided context overrides globally defined stuff
+ var config = require('helma/webapp/env').config;
+ if (config && config.macros instanceof Array) {
+ for each (var module in config.macros) {
+ context = Object.merge(context, require(module));
+ }
+ }
if (mainSkin.length === 0 && parentSkin) {
return renderInternal(parentSkin.getSkinParts(), context);
} else {
Modified: helma-ng/trunk/modules/helmaglobal.js
===================================================================
--- helma-ng/trunk/modules/helmaglobal.js 2009-05-04 09:07:21 UTC (rev 9696)
+++ helma-ng/trunk/modules/helmaglobal.js 2009-05-04 09:07:23 UTC (rev 9697)
@@ -111,26 +111,6 @@
});
/**
- * Parse a skin resource and pass its tokens to the supplied function.
- * @param resourceOrString a skin resource or string
- * @param fn a function to consume the skin tokens
- */
- Object.defineProperty(this, "parseSkin", {
- value: function(resourceOrString, fn) {
- var engine = getRhinoEngine();
- var parser = new org.helma.template.SkinParser({
- renderText: function(text) {
- fn(text);
- },
- renderMacro: function(macro) {
- fn(engine.wrapArgument(macro, {}));
- }
- });
- parser.parse(resourceOrString);
- }
- });
-
- /**
* Basic print function compatible with other JavaScript implementations.
*/
Object.defineProperty(this, "print", {