mirror of
https://github.com/marko-js/marko.git
synced 2025-12-08 19:26:05 +00:00
Template parser is now based off of file ext (rhtml or rxml)
This commit is contained in:
parent
5559a9c0dd
commit
77e151512d
@ -43,13 +43,16 @@ function ParseTreeBuilderHtml(taglibs) {
|
||||
|
||||
ParseTreeBuilderHtml.prototype = {
|
||||
getPos: function() {
|
||||
return this.createPos(this.parser.startIndex);
|
||||
return this.parser ? this.createPos(this.parser.startIndex) : null;
|
||||
},
|
||||
|
||||
doParse: function (src, filePath) {
|
||||
|
||||
var _this = this;
|
||||
|
||||
// Create a pseudo root node
|
||||
this.handleStartElement(splitName('c:template'), []);
|
||||
|
||||
var parser = this.parser = new htmlparser.Parser({
|
||||
onopentag: function(name, attribs){
|
||||
var el = splitName(name);
|
||||
@ -78,6 +81,9 @@ ParseTreeBuilderHtml.prototype = {
|
||||
}, parserOptions);
|
||||
parser.write(src);
|
||||
parser.end();
|
||||
|
||||
// End the pseudo root node:
|
||||
_this.handleEndElement();
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
@ -1,7 +1,14 @@
|
||||
require('raptor-ecma/es6');
|
||||
var ParseTreeBuilderHtml = require('./ParseTreeBuilderHtml');
|
||||
var ParseTreeBuilderXml = require('./ParseTreeBuilderXml');
|
||||
|
||||
function parse(src, filePath, taglibs) {
|
||||
var parseTreeBuilder = new ParseTreeBuilderHtml(taglibs);
|
||||
var ParseTreeBuilder = filePath.endsWith('.rxml') ?
|
||||
ParseTreeBuilderXml :
|
||||
ParseTreeBuilderHtml;
|
||||
|
||||
var parseTreeBuilder = new ParseTreeBuilder(taglibs);
|
||||
|
||||
return parseTreeBuilder.parse(src, filePath);
|
||||
}
|
||||
|
||||
|
||||
@ -1 +1 @@
|
||||
node_modules/.bin/mocha --ui bdd --reporter spec ./test/render-tests.js
|
||||
node_modules/.bin/mocha --ui bdd --reporter spec ./test/render-rhtml-tests.js
|
||||
@ -56,7 +56,7 @@ function testRender(path, data, done, options) {
|
||||
|
||||
}
|
||||
|
||||
describe('raptor-templates' , function() {
|
||||
describe('raptor-templates/rhtml' , function() {
|
||||
|
||||
beforeEach(function(done) {
|
||||
// for (var k in require.cache) {
|
||||
@ -81,7 +81,7 @@ describe('raptor-templates' , function() {
|
||||
});
|
||||
|
||||
it("should allow for text replacement", function(done) {
|
||||
testRender("test-project/html-templates/text-replacement.rhtml", {
|
||||
testRender("test-project/rhtml-templates/text-replacement.rhtml", {
|
||||
person: {
|
||||
name: "John",
|
||||
address: {
|
||||
@ -94,8 +94,8 @@ describe('raptor-templates' , function() {
|
||||
}, done);
|
||||
});
|
||||
|
||||
it.only("should render simple template with logic", function(done) {
|
||||
testRender("test-project/html-templates/simple.rhtml", {
|
||||
it("should render simple template with logic", function(done) {
|
||||
testRender("test-project/rhtml-templates/simple.rhtml", {
|
||||
message: "Hello World!",
|
||||
rootClass: "title",
|
||||
colors: ["red", "green", "blue"]
|
||||
@ -103,63 +103,63 @@ describe('raptor-templates' , function() {
|
||||
});
|
||||
|
||||
it("should allow for simple template handlers", function(done) {
|
||||
testRender("test-project/html-templates/simple-handlers.rhtml", {dynamic: "universe"}, done);
|
||||
testRender("test-project/rhtml-templates/simple-handlers.rhtml", {dynamic: "universe"}, done);
|
||||
});
|
||||
|
||||
it("should allow for template handlers with nested body content", function(done) {
|
||||
testRender("test-project/html-templates/nested-handlers.rhtml", {showConditionalTab: false}, done);
|
||||
testRender("test-project/rhtml-templates/nested-handlers.rhtml", {showConditionalTab: false}, done);
|
||||
});
|
||||
|
||||
it("should allow entity expressions", function(done) {
|
||||
testRender("test-project/html-templates/entities.rhtml", {}, done);
|
||||
testRender("test-project/rhtml-templates/entities.rhtml", {}, done);
|
||||
});
|
||||
|
||||
it("should allow escaped expressions", function(done) {
|
||||
testRender("test-project/html-templates/escaped.rhtml", {}, done);
|
||||
testRender("test-project/rhtml-templates/escaped.rhtml", {}, done);
|
||||
});
|
||||
|
||||
it("should allow complex expressions", function(done) {
|
||||
testRender("test-project/html-templates/expressions.rhtml", {}, done);
|
||||
testRender("test-project/rhtml-templates/expressions.rhtml", {}, done);
|
||||
});
|
||||
|
||||
it("should allow whitespace to be removed", function(done) {
|
||||
testRender("test-project/html-templates/whitespace.rhtml", {}, done);
|
||||
testRender("test-project/rhtml-templates/whitespace.rhtml", {}, done);
|
||||
});
|
||||
|
||||
it("should handle whitespace when using expressions", function(done) {
|
||||
testRender("test-project/html-templates/whitespace2.rhtml", {}, done);
|
||||
testRender("test-project/rhtml-templates/whitespace2.rhtml", {}, done);
|
||||
});
|
||||
|
||||
it("should handle whitespace when using expressions", function(done) {
|
||||
testRender("test-project/html-templates/whitespace2.rhtml", {}, done);
|
||||
testRender("test-project/rhtml-templates/whitespace2.rhtml", {}, done);
|
||||
});
|
||||
|
||||
it("should normalize whitespace", function(done) {
|
||||
testRender("test-project/html-templates/whitespace3.rhtml", {}, done);
|
||||
testRender("test-project/rhtml-templates/whitespace3.rhtml", {}, done);
|
||||
});
|
||||
|
||||
it("should handle whitespace correctly for mixed text and element children", function(done) {
|
||||
testRender("test-project/html-templates/whitespace-inline-elements.rhtml", {}, done);
|
||||
testRender("test-project/rhtml-templates/whitespace-inline-elements.rhtml", {}, done);
|
||||
});
|
||||
|
||||
it("should allow HTML output that is not well-formed XML", function(done) {
|
||||
testRender("test-project/html-templates/html.rhtml", {}, done);
|
||||
testRender("test-project/rhtml-templates/html.rhtml", {}, done);
|
||||
});
|
||||
|
||||
it("should allow for looping", function(done) {
|
||||
testRender("test-project/html-templates/looping.rhtml", {}, done);
|
||||
testRender("test-project/rhtml-templates/looping.rhtml", {}, done);
|
||||
});
|
||||
|
||||
it("should allow for looping over properties", function(done) {
|
||||
testRender("test-project/html-templates/looping-props.rhtml", {}, done);
|
||||
testRender("test-project/rhtml-templates/looping-props.rhtml", {}, done);
|
||||
});
|
||||
|
||||
it("should allow for dynamic attributes", function(done) {
|
||||
testRender("test-project/html-templates/attrs.rhtml", {"myAttrs": {style: "background-color: #FF0000; <test>", "class": "my-div"}}, done);
|
||||
testRender("test-project/rhtml-templates/attrs.rhtml", {"myAttrs": {style: "background-color: #FF0000; <test>", "class": "my-div"}}, done);
|
||||
});
|
||||
|
||||
it("should allow for choose...when statements", function(done) {
|
||||
testRender("test-project/html-templates/choose-when.rhtml", {}, done);
|
||||
testRender("test-project/rhtml-templates/choose-when.rhtml", {}, done);
|
||||
});
|
||||
|
||||
it("should not allow <c:otherwise> to be before a <c:when> tag", function(done) {
|
||||
@ -171,7 +171,7 @@ describe('raptor-templates' , function() {
|
||||
}
|
||||
|
||||
try {
|
||||
testRender("test-project/html-templates/choose-when-invalid-otherwise-not-last.rhtml", {}, fakeDone);
|
||||
testRender("test-project/rhtml-templates/choose-when-invalid-otherwise-not-last.rhtml", {}, fakeDone);
|
||||
}
|
||||
catch(_e) {
|
||||
e = _e;
|
||||
@ -182,43 +182,43 @@ describe('raptor-templates' , function() {
|
||||
});
|
||||
|
||||
it("should allow for <c:def> functions", function(done) {
|
||||
testRender("test-project/html-templates/def.rhtml", {}, done);
|
||||
testRender("test-project/rhtml-templates/def.rhtml", {}, done);
|
||||
});
|
||||
|
||||
it("should allow for <c:with> functions", function(done) {
|
||||
testRender("test-project/html-templates/with.rhtml", {}, done);
|
||||
testRender("test-project/rhtml-templates/with.rhtml", {}, done);
|
||||
});
|
||||
|
||||
it("should allow for scriptlets", function(done) {
|
||||
testRender("test-project/html-templates/scriptlet.rhtml", {}, done);
|
||||
testRender("test-project/rhtml-templates/scriptlet.rhtml", {}, done);
|
||||
});
|
||||
|
||||
it("should allow for when and otherwise as attributes", function(done) {
|
||||
testRender("test-project/html-templates/choose-when-attributes.rhtml", {}, done);
|
||||
testRender("test-project/rhtml-templates/choose-when-attributes.rhtml", {}, done);
|
||||
});
|
||||
|
||||
it("should allow for elements to be stripped out at compile time", function(done) {
|
||||
testRender("test-project/html-templates/strip.rhtml", {}, done);
|
||||
testRender("test-project/rhtml-templates/strip.rhtml", {}, done);
|
||||
});
|
||||
|
||||
it("should allow for body content to be replaced with the result of an expression", function(done) {
|
||||
testRender("test-project/html-templates/content.rhtml", {}, done);
|
||||
testRender("test-project/rhtml-templates/content.rhtml", {}, done);
|
||||
});
|
||||
|
||||
it("should allow for an element to be replaced with the result of an expression", function(done) {
|
||||
testRender("test-project/html-templates/replace.rhtml", {message: "Hello World!"}, done);
|
||||
testRender("test-project/rhtml-templates/replace.rhtml", {message: "Hello World!"}, done);
|
||||
});
|
||||
|
||||
it("should allow for includes", function(done) {
|
||||
testRender("test-project/html-templates/include.rhtml", {}, done);
|
||||
testRender("test-project/rhtml-templates/include.rhtml", {}, done);
|
||||
});
|
||||
|
||||
it("should allow for <c:invoke function... />", function(done) {
|
||||
testRender("test-project/html-templates/invoke.rhtml", {}, done);
|
||||
testRender("test-project/rhtml-templates/invoke.rhtml", {}, done);
|
||||
});
|
||||
|
||||
it("should allow for require", function(done) {
|
||||
testRender("test-project/html-templates/require.rhtml", {}, done);
|
||||
testRender("test-project/rhtml-templates/require.rhtml", {}, done);
|
||||
});
|
||||
|
||||
|
||||
@ -244,7 +244,7 @@ describe('raptor-templates' , function() {
|
||||
// }
|
||||
// };
|
||||
|
||||
// tryTemplate("test-project/html-templates/errors.rhtml", function(message, errors) {
|
||||
// tryTemplate("test-project/rhtml-templates/errors.rhtml", function(message, errors) {
|
||||
// var len = errors ? errors.length : -1;
|
||||
// expect(len).toEqual(25);
|
||||
|
||||
@ -255,15 +255,15 @@ describe('raptor-templates' , function() {
|
||||
// });
|
||||
|
||||
it("should allow static file includes", function(done) {
|
||||
testRender("test-project/html-templates/include-resource-static.rhtml", {}, done);
|
||||
testRender("test-project/rhtml-templates/include-resource-static.rhtml", {}, done);
|
||||
});
|
||||
|
||||
it("should allow HTML pages with inline script", function(done) {
|
||||
testRender("test-project/html-templates/inline-script.rhtml", {name: "World"}, done);
|
||||
testRender("test-project/rhtml-templates/inline-script.rhtml", {name: "World"}, done);
|
||||
});
|
||||
|
||||
it("should allow CDATA inside templates", function(done) {
|
||||
testRender("test-project/html-templates/cdata.rhtml", {name: "World"}, done);
|
||||
testRender("test-project/rhtml-templates/cdata.rhtml", {name: "World"}, done);
|
||||
});
|
||||
|
||||
// it("should allow type conversion", function(done) {
|
||||
@ -272,31 +272,31 @@ describe('raptor-templates' , function() {
|
||||
// });
|
||||
|
||||
it("should allow for if...else", function(done) {
|
||||
testRender("test-project/html-templates/if-else.rhtml", {}, done);
|
||||
testRender("test-project/rhtml-templates/if-else.rhtml", {}, done);
|
||||
});
|
||||
|
||||
it("should allow for expressions and variables inside JavaScript strings", function(done) {
|
||||
testRender("test-project/html-templates/string-expressions.rhtml", {name: "John", count: 10}, done);
|
||||
testRender("test-project/rhtml-templates/string-expressions.rhtml", {name: "John", count: 10}, done);
|
||||
});
|
||||
|
||||
it("should allow for simple conditionals", function(done) {
|
||||
testRender("test-project/html-templates/simple-conditionals.rhtml", {name: "John", count: 51}, done);
|
||||
testRender("test-project/rhtml-templates/simple-conditionals.rhtml", {name: "John", count: 51}, done);
|
||||
});
|
||||
|
||||
it("should allow for conditional attributes", function(done) {
|
||||
testRender("test-project/html-templates/conditional-attributes.rhtml", {}, done);
|
||||
testRender("test-project/rhtml-templates/conditional-attributes.rhtml", {}, done);
|
||||
});
|
||||
|
||||
it("should allow for dynamic attributes to be passed to tag renderer using a custom property name", function(done) {
|
||||
testRender("test-project/html-templates/dynamic-attributes.rhtml", {}, done);
|
||||
testRender("test-project/rhtml-templates/dynamic-attributes.rhtml", {}, done);
|
||||
});
|
||||
|
||||
it("should allow for dynamic attributes to be passed to tag renderer", function(done) {
|
||||
testRender("test-project/html-templates/dynamic-attributes2.rhtml", {}, done);
|
||||
testRender("test-project/rhtml-templates/dynamic-attributes2.rhtml", {}, done);
|
||||
});
|
||||
|
||||
it("should allow for dynamic attributes to be passed to tag renderer as part of input object", function(done) {
|
||||
testRender("test-project/html-templates/dynamic-attributes3.rhtml", {}, done);
|
||||
testRender("test-project/rhtml-templates/dynamic-attributes3.rhtml", {}, done);
|
||||
});
|
||||
|
||||
// it("should allow for nodes to be converted to expressions", function(done) {
|
||||
@ -325,48 +325,48 @@ describe('raptor-templates' , function() {
|
||||
// });
|
||||
|
||||
it("should allow for nested attributes", function(done) {
|
||||
testRender("test-project/html-templates/nested-attrs.rhtml", {active: true}, done);
|
||||
testRender("test-project/rhtml-templates/nested-attrs.rhtml", {active: true}, done);
|
||||
});
|
||||
|
||||
it("should allow for new variables to be created and assigned values", function(done) {
|
||||
testRender("test-project/html-templates/var.rhtml", {active: true}, done);
|
||||
testRender("test-project/rhtml-templates/var.rhtml", {active: true}, done);
|
||||
});
|
||||
|
||||
|
||||
it("should handle XML escaping correctly", function(done) {
|
||||
testRender("test-project/html-templates/xml-escaping.rhtml", {name: "<Patrick>", welcome: '<span>Welcome</span>'}, done);
|
||||
testRender("test-project/rhtml-templates/xml-escaping.rhtml", {name: "<Patrick>", welcome: '<span>Welcome</span>'}, done);
|
||||
});
|
||||
|
||||
it("should allow for a doctype tag and a doctype attribute", function(done) {
|
||||
testRender("test-project/html-templates/doctype.rhtml", {}, done);
|
||||
testRender("test-project/rhtml-templates/doctype.rhtml", {}, done);
|
||||
});
|
||||
|
||||
it("should allow for using templates to render custom tags", function(done) {
|
||||
testRender("test-project/html-templates/template-as-tag.rhtml", {title: "My Page Title"}, done);
|
||||
testRender("test-project/rhtml-templates/template-as-tag.rhtml", {title: "My Page Title"}, done);
|
||||
});
|
||||
|
||||
it("should allow for caching HTML fragments", function(done) {
|
||||
testRender("test-project/html-templates/caching.rhtml", {}, done);
|
||||
testRender("test-project/rhtml-templates/caching.rhtml", {}, done);
|
||||
});
|
||||
|
||||
it("should escape XML in text node when enabled", function(done) {
|
||||
testRender("test-project/html-templates/escape-xml-enabled.rhtml", {}, done);
|
||||
testRender("test-project/rhtml-templates/escape-xml-enabled.rhtml", {}, done);
|
||||
});
|
||||
|
||||
it("should not escape XML in text node when disabled", function(done) {
|
||||
testRender("test-project/html-templates/escape-xml-disabled.rhtml", {}, done);
|
||||
testRender("test-project/rhtml-templates/escape-xml-disabled.rhtml", {}, done);
|
||||
});
|
||||
|
||||
it("should allow for attributes with default values", function(done) {
|
||||
testRender("test-project/html-templates/default-attributes.rhtml", {}, done);
|
||||
testRender("test-project/rhtml-templates/default-attributes.rhtml", {}, done);
|
||||
});
|
||||
|
||||
it("should allow for input expressions to be provided to tag handler nodes", function(done) {
|
||||
testRender("test-project/html-templates/tag-input-expressions.rhtml", {name: "Frank", adult: true}, done);
|
||||
testRender("test-project/rhtml-templates/tag-input-expressions.rhtml", {name: "Frank", adult: true}, done);
|
||||
});
|
||||
|
||||
it("should allow for using layouts", function(done) {
|
||||
testRender("test-project/html-templates/layout-use.rhtml", {}, done);
|
||||
testRender("test-project/rhtml-templates/layout-use.rhtml", {}, done);
|
||||
});
|
||||
|
||||
});
|
||||
366
test/render-rxml-tests.js
Normal file
366
test/render-rxml-tests.js
Normal file
@ -0,0 +1,366 @@
|
||||
'use strict';
|
||||
var chai = require('chai');
|
||||
chai.Assertion.includeStack = true;
|
||||
require('chai').should();
|
||||
var expect = require('chai').expect;
|
||||
var nodePath = require('path');
|
||||
var fs = require('fs');
|
||||
|
||||
var StringBuilder = require('raptor-strings/StringBuilder');
|
||||
|
||||
function testRender(path, data, done, options) {
|
||||
var inputPath = nodePath.join(__dirname, path);
|
||||
var expectedPath = nodePath.join(__dirname, path + '.expected.html');
|
||||
var actualPath = nodePath.join(__dirname, path + '.actual.html');
|
||||
options = options || {};
|
||||
var compiledPath = nodePath.join(__dirname, path + '.actual.js');
|
||||
|
||||
var compiler = require('../compiler').createCompiler(inputPath);
|
||||
var src = fs.readFileSync(inputPath, {encoding: 'utf8'});
|
||||
|
||||
var compiledSrc = compiler.compile(src);
|
||||
fs.writeFileSync(compiledPath, compiledSrc, {encoding: 'utf8'});
|
||||
|
||||
|
||||
// console.log('\nCompiled (' + inputPath + '):\n---------\n' + compiledSrc);
|
||||
|
||||
|
||||
|
||||
var raptorTemplates = require('../');
|
||||
var Context = raptorTemplates.Context;
|
||||
var context = options.context || new Context(new StringBuilder());
|
||||
|
||||
raptorTemplates.render(inputPath, data, context)
|
||||
.on('end', function() {
|
||||
var output = context.getOutput();
|
||||
|
||||
fs.writeFileSync(actualPath, output, {encoding: 'utf8'});
|
||||
|
||||
var expected;
|
||||
try {
|
||||
expected = options.expected || fs.readFileSync(expectedPath, {encoding: 'utf8'});
|
||||
}
|
||||
catch(e) {
|
||||
expected = 'TBD';
|
||||
fs.writeFileSync(expectedPath, expected, {encoding: 'utf8'});
|
||||
}
|
||||
|
||||
if (output !== expected) {
|
||||
throw new Error('Unexpected output for "' + inputPath + '":\nEXPECTED (' + expectedPath + '):\n---------\n' + expected +
|
||||
'\n---------\nACTUAL (' + actualPath + '):\n---------\n' + output + '\n---------');
|
||||
}
|
||||
|
||||
done();
|
||||
})
|
||||
.on('error', done);
|
||||
|
||||
}
|
||||
|
||||
describe('raptor-templates/rxml' , function() {
|
||||
|
||||
beforeEach(function(done) {
|
||||
// for (var k in require.cache) {
|
||||
// if (require.cache.hasOwnProperty(k)) {
|
||||
// delete require.cache[k];
|
||||
// }
|
||||
// }
|
||||
|
||||
// require('raptor-logging').configureLoggers({
|
||||
// 'raptor-templates': 'INFO'
|
||||
// });
|
||||
|
||||
done();
|
||||
});
|
||||
|
||||
|
||||
it("should allow for text replacement", function(done) {
|
||||
testRender("test-project/rxml-templates/text-replacement.rxml", {
|
||||
person: {
|
||||
name: "John",
|
||||
address: {
|
||||
city: "San Jose",
|
||||
state: "CA",
|
||||
line1: "2065 E. Hamilton Ave.",
|
||||
zip: "95125"
|
||||
}
|
||||
}
|
||||
}, done);
|
||||
});
|
||||
|
||||
it("should render simple template with logic", function(done) {
|
||||
testRender("test-project/rxml-templates/simple.rxml", {
|
||||
message: "Hello World!",
|
||||
rootClass: "title",
|
||||
colors: ["red", "green", "blue"]
|
||||
}, done);
|
||||
});
|
||||
|
||||
it("should allow for simple template handlers", function(done) {
|
||||
testRender("test-project/rxml-templates/simple-handlers.rxml", {dynamic: "universe"}, done);
|
||||
});
|
||||
|
||||
it("should allow for template handlers with nested body content", function(done) {
|
||||
testRender("test-project/rxml-templates/nested-handlers.rxml", {showConditionalTab: false}, done);
|
||||
});
|
||||
|
||||
it("should allow entity expressions", function(done) {
|
||||
testRender("test-project/rxml-templates/entities.rxml", {}, done);
|
||||
});
|
||||
|
||||
it("should allow escaped expressions", function(done) {
|
||||
testRender("test-project/rxml-templates/escaped.rxml", {}, done);
|
||||
});
|
||||
|
||||
it("should allow complex expressions", function(done) {
|
||||
testRender("test-project/rxml-templates/expressions.rxml", {}, done);
|
||||
});
|
||||
|
||||
it("should allow whitespace to be removed", function(done) {
|
||||
testRender("test-project/rxml-templates/whitespace.rxml", {}, done);
|
||||
});
|
||||
|
||||
it("should handle whitespace when using expressions", function(done) {
|
||||
testRender("test-project/rxml-templates/whitespace2.rxml", {}, done);
|
||||
});
|
||||
|
||||
it("should handle whitespace when using expressions", function(done) {
|
||||
testRender("test-project/rxml-templates/whitespace2.rxml", {}, done);
|
||||
});
|
||||
|
||||
it("should normalize whitespace", function(done) {
|
||||
testRender("test-project/rxml-templates/whitespace3.rxml", {}, done);
|
||||
});
|
||||
|
||||
it("should handle whitespace correctly for mixed text and element children", function(done) {
|
||||
testRender("test-project/rxml-templates/whitespace-inline-elements.rxml", {}, done);
|
||||
});
|
||||
|
||||
it("should allow HTML output that is not well-formed XML", function(done) {
|
||||
testRender("test-project/rxml-templates/html.rxml", {}, done);
|
||||
});
|
||||
|
||||
it("should allow for looping", function(done) {
|
||||
testRender("test-project/rxml-templates/looping.rxml", {}, done);
|
||||
});
|
||||
|
||||
it("should allow for looping over properties", function(done) {
|
||||
testRender("test-project/rxml-templates/looping-props.rxml", {}, done);
|
||||
});
|
||||
|
||||
it("should allow for dynamic attributes", function(done) {
|
||||
testRender("test-project/rxml-templates/attrs.rxml", {"myAttrs": {style: "background-color: #FF0000; <test>", "class": "my-div"}}, done);
|
||||
});
|
||||
|
||||
it("should allow for choose...when statements", function(done) {
|
||||
testRender("test-project/rxml-templates/choose-when.rxml", {}, done);
|
||||
});
|
||||
|
||||
it("should not allow <c:otherwise> to be before a <c:when> tag", function(done) {
|
||||
|
||||
var e;
|
||||
|
||||
function fakeDone() {
|
||||
done('Error expected');
|
||||
}
|
||||
|
||||
try {
|
||||
testRender("test-project/rxml-templates/choose-when-invalid-otherwise-not-last.rxml", {}, fakeDone);
|
||||
}
|
||||
catch(_e) {
|
||||
e = _e;
|
||||
}
|
||||
|
||||
expect(e != null).to.equal(true);
|
||||
done();
|
||||
});
|
||||
|
||||
it("should allow for <c:def> functions", function(done) {
|
||||
testRender("test-project/rxml-templates/def.rxml", {}, done);
|
||||
});
|
||||
|
||||
it("should allow for <c:with> functions", function(done) {
|
||||
testRender("test-project/rxml-templates/with.rxml", {}, done);
|
||||
});
|
||||
|
||||
it("should allow for scriptlets", function(done) {
|
||||
testRender("test-project/rxml-templates/scriptlet.rxml", {}, done);
|
||||
});
|
||||
|
||||
it("should allow for when and otherwise as attributes", function(done) {
|
||||
testRender("test-project/rxml-templates/choose-when-attributes.rxml", {}, done);
|
||||
});
|
||||
|
||||
it("should allow for elements to be stripped out at compile time", function(done) {
|
||||
testRender("test-project/rxml-templates/strip.rxml", {}, done);
|
||||
});
|
||||
|
||||
it("should allow for body content to be replaced with the result of an expression", function(done) {
|
||||
testRender("test-project/rxml-templates/content.rxml", {}, done);
|
||||
});
|
||||
|
||||
it("should allow for an element to be replaced with the result of an expression", function(done) {
|
||||
testRender("test-project/rxml-templates/replace.rxml", {message: "Hello World!"}, done);
|
||||
});
|
||||
|
||||
it("should allow for includes", function(done) {
|
||||
testRender("test-project/rxml-templates/include.rxml", {}, done);
|
||||
});
|
||||
|
||||
it("should allow for <c:invoke function... />", function(done) {
|
||||
testRender("test-project/rxml-templates/invoke.rxml", {}, done);
|
||||
});
|
||||
|
||||
it("should allow for require", function(done) {
|
||||
testRender("test-project/rxml-templates/require.rxml", {}, done);
|
||||
});
|
||||
|
||||
|
||||
// it("should handle errors correctly", function(done) {
|
||||
|
||||
|
||||
|
||||
// var tryTemplate = function(path, callback) {
|
||||
// try
|
||||
// {
|
||||
// compileAndRender(path, {}, null, true /* invalid */);
|
||||
// callback("", []);
|
||||
// }
|
||||
// catch(e) {
|
||||
|
||||
// if (!e.errors) {
|
||||
// logger.error('Error message for template at path "' + path + '": ' + e, e);
|
||||
// }
|
||||
// else {
|
||||
// console.log('Error message for template at path "' + path + '": ' + e)
|
||||
// }
|
||||
// callback(e.toString(), e.errors);
|
||||
// }
|
||||
// };
|
||||
|
||||
// tryTemplate("test-project/rxml-templates/errors.rxml", function(message, errors) {
|
||||
// var len = errors ? errors.length : -1;
|
||||
// expect(len).toEqual(25);
|
||||
|
||||
|
||||
// });
|
||||
|
||||
|
||||
// });
|
||||
|
||||
it("should allow static file includes", function(done) {
|
||||
testRender("test-project/rxml-templates/include-resource-static.rxml", {}, done);
|
||||
});
|
||||
|
||||
it("should allow HTML pages with inline script", function(done) {
|
||||
testRender("test-project/rxml-templates/inline-script.rxml", {name: "World"}, done);
|
||||
});
|
||||
|
||||
it("should allow CDATA inside templates", function(done) {
|
||||
testRender("test-project/rxml-templates/cdata.rxml", {name: "World"}, done);
|
||||
});
|
||||
|
||||
// it("should allow type conversion", function(done) {
|
||||
// var TypeConverter = require('raptor/templating/compiler/TypeConverter');
|
||||
// expect(TypeConverter.convert('${entity:special}', "string", true).toString()).toEqual('"&special;"');
|
||||
// });
|
||||
|
||||
it("should allow for if...else", function(done) {
|
||||
testRender("test-project/rxml-templates/if-else.rxml", {}, done);
|
||||
});
|
||||
|
||||
it("should allow for expressions and variables inside JavaScript strings", function(done) {
|
||||
testRender("test-project/rxml-templates/string-expressions.rxml", {name: "John", count: 10}, done);
|
||||
});
|
||||
|
||||
it("should allow for simple conditionals", function(done) {
|
||||
testRender("test-project/rxml-templates/simple-conditionals.rxml", {name: "John", count: 51}, done);
|
||||
});
|
||||
|
||||
it("should allow for conditional attributes", function(done) {
|
||||
testRender("test-project/rxml-templates/conditional-attributes.rxml", {}, done);
|
||||
});
|
||||
|
||||
it("should allow for dynamic attributes to be passed to tag renderer using a custom property name", function(done) {
|
||||
testRender("test-project/rxml-templates/dynamic-attributes.rxml", {}, done);
|
||||
});
|
||||
|
||||
it("should allow for dynamic attributes to be passed to tag renderer", function(done) {
|
||||
testRender("test-project/rxml-templates/dynamic-attributes2.rxml", {}, done);
|
||||
});
|
||||
|
||||
it("should allow for dynamic attributes to be passed to tag renderer as part of input object", function(done) {
|
||||
testRender("test-project/rxml-templates/dynamic-attributes3.rxml", {}, done);
|
||||
});
|
||||
|
||||
// it("should allow for nodes to be converted to expressions", function(done) {
|
||||
// var ElementNode = require('raptor/templating/compiler/ElementNode');
|
||||
// var TextNode = require('raptor/templating/compiler/TextNode');
|
||||
// var TemplateBuilder = require('raptor/templating/compiler/TemplateBuilder');
|
||||
|
||||
// var compiler = require('raptor/templating/compiler').createCompiler();
|
||||
// var template = new TemplateBuilder(compiler);
|
||||
|
||||
// var div = new ElementNode("div");
|
||||
// var text = new TextNode("Hello World!");
|
||||
// div.appendChild(text);
|
||||
|
||||
// var expression = div.getExpression(template).toString();
|
||||
// var bodyContentExpression = div.getBodyContentExpression(template).toString();
|
||||
|
||||
// var sb = require('raptor/strings').createStringBuilder();
|
||||
// var context = require('raptor/templating').createContext(sb);
|
||||
// var output = eval(expression);
|
||||
// expect(output.toString()).toEqual('<div>Hello World!</div>');
|
||||
|
||||
// output = eval(bodyContentExpression);
|
||||
// expect(output.toString()).toEqual('Hello World!');
|
||||
|
||||
// });
|
||||
|
||||
it("should allow for nested attributes", function(done) {
|
||||
testRender("test-project/rxml-templates/nested-attrs.rxml", {active: true}, done);
|
||||
});
|
||||
|
||||
it("should allow for new variables to be created and assigned values", function(done) {
|
||||
testRender("test-project/rxml-templates/var.rxml", {active: true}, done);
|
||||
});
|
||||
|
||||
|
||||
it("should handle XML escaping correctly", function(done) {
|
||||
testRender("test-project/rxml-templates/xml-escaping.rxml", {name: "<Patrick>", welcome: '<span>Welcome</span>'}, done);
|
||||
});
|
||||
|
||||
it("should allow for a doctype tag and a doctype attribute", function(done) {
|
||||
testRender("test-project/rxml-templates/doctype.rxml", {}, done);
|
||||
});
|
||||
|
||||
it("should allow for using templates to render custom tags", function(done) {
|
||||
testRender("test-project/rxml-templates/template-as-tag.rxml", {title: "My Page Title"}, done);
|
||||
});
|
||||
|
||||
it("should allow for caching HTML fragments", function(done) {
|
||||
testRender("test-project/rxml-templates/caching.rxml", {}, done);
|
||||
});
|
||||
|
||||
it("should escape XML in text node when enabled", function(done) {
|
||||
testRender("test-project/rxml-templates/escape-xml-enabled.rxml", {}, done);
|
||||
});
|
||||
|
||||
it("should not escape XML in text node when disabled", function(done) {
|
||||
testRender("test-project/rxml-templates/escape-xml-disabled.rxml", {}, done);
|
||||
});
|
||||
|
||||
it("should allow for attributes with default values", function(done) {
|
||||
testRender("test-project/rxml-templates/default-attributes.rxml", {}, done);
|
||||
});
|
||||
|
||||
it("should allow for input expressions to be provided to tag handler nodes", function(done) {
|
||||
testRender("test-project/rxml-templates/tag-input-expressions.rxml", {name: "Frank", adult: true}, done);
|
||||
});
|
||||
|
||||
it("should allow for using layouts", function(done) {
|
||||
testRender("test-project/rxml-templates/layout-use.rxml", {}, done);
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
@ -1,3 +1 @@
|
||||
<c:template xmlns:test="test">
|
||||
<test:hello name="World"/>
|
||||
</c:template>
|
||||
<test:hello name="World"/>
|
||||
@ -1,7 +1,7 @@
|
||||
<template
|
||||
<c:template
|
||||
xmlns:c="http://raptorjs.org/templates/core">
|
||||
|
||||
<div class="{?false;some-class}"></div>
|
||||
<div class="{?true;some-class}"></div>
|
||||
<div class="${data.name}"></div>
|
||||
</template>
|
||||
</c:template>
|
||||
@ -1,6 +1,6 @@
|
||||
<template
|
||||
<c:template
|
||||
xmlns:c="http://raptorjs.org/templates/core"
|
||||
xmlns:test="http://raptorjs.org/templates/test">
|
||||
|
||||
<test:dynamic-attributes test="Hello" class="my-class" id="myId"/>
|
||||
</template>
|
||||
</c:template>
|
||||
@ -1,6 +1,6 @@
|
||||
<template
|
||||
<c:template
|
||||
xmlns:c="http://raptorjs.org/templates/core"
|
||||
xmlns:test="http://raptorjs.org/templates/test">
|
||||
|
||||
<test:dynamic-attributes2 test="World" class="my-class" id="myId"/>
|
||||
</template>
|
||||
</c:template>
|
||||
@ -1,6 +1,6 @@
|
||||
<template
|
||||
<c:template
|
||||
xmlns:c="http://raptorjs.org/templates/core"
|
||||
xmlns:test="http://raptorjs.org/templates/test">
|
||||
|
||||
<test:dynamic-attributes3 test="World" class="my-class" id="myId"/>
|
||||
</template>
|
||||
</c:template>
|
||||
@ -1,4 +1,4 @@
|
||||
<template
|
||||
<c:template
|
||||
xmlns:c="http://raptorjs.org/templates/core"
|
||||
params="name,count">
|
||||
<div class="{?count>50;over-50}"></div>
|
||||
@ -12,4 +12,4 @@
|
||||
|
||||
{?count>50;{?name;Hello $name! }Over 50;{?name;Hello $name! }50 or less}
|
||||
|
||||
</template>
|
||||
</c:template>
|
||||
@ -1,9 +1,6 @@
|
||||
<template
|
||||
<c:template
|
||||
xmlns:c="http://raptorjs.org/templates/core"
|
||||
params="rootClass,colors,message">
|
||||
|
||||
|
||||
<test:hello name="World"/>
|
||||
|
||||
<div class="hello-world ${rootClass}">${message}</div>
|
||||
|
||||
@ -15,4 +12,4 @@
|
||||
No colors!
|
||||
</div>
|
||||
|
||||
</template>
|
||||
</c:template>
|
||||
@ -1,7 +1,7 @@
|
||||
<template
|
||||
<c:template
|
||||
xmlns:c="http://raptorjs.org/templates/core"
|
||||
params="name,count">
|
||||
|
||||
${name != null ? "Hello ${name.toUpperCase()}! You have $count new messages." : null}
|
||||
|
||||
</template>
|
||||
</c:template>
|
||||
@ -1,8 +1,8 @@
|
||||
<template
|
||||
<c:template
|
||||
xmlns:c="core"
|
||||
xmlns:test="test"
|
||||
params="">
|
||||
|
||||
<test:simpleHello c:input="data"/>
|
||||
|
||||
</template>
|
||||
</c:template>
|
||||
@ -1,8 +1,8 @@
|
||||
<template
|
||||
<c:template
|
||||
xmlns:c="http://raptorjs.org/templates/core"
|
||||
params="person">
|
||||
|
||||
|
||||
Hello $person.name. You are from ${person.address.city}, $person.address.state
|
||||
|
||||
</template>
|
||||
</c:template>
|
||||
@ -2,10 +2,10 @@
|
||||
xmlns:c="http://raptorjs.org/templates/core"
|
||||
params="">
|
||||
|
||||
<c:include template="./include-target.rhtml" name="${'Frank'}" count="20"/>
|
||||
<c:include template="./include-target.rhtml" name="Frank" count="${20}"/>
|
||||
<c:include template="./include-target.rhtml" template-data="{name: 'Frank', count: 20}"/>
|
||||
<c:include template="./include-nested-content.rhtml" name="Frank" count="${20}">
|
||||
<c:include template="./include-target.rxml" name="${'Frank'}" count="20"/>
|
||||
<c:include template="./include-target.rxml" name="Frank" count="${20}"/>
|
||||
<c:include template="./include-target.rxml" template-data="{name: 'Frank', count: 20}"/>
|
||||
<c:include template="./include-nested-content.rxml" name="Frank" count="${20}">
|
||||
Have a
|
||||
<b>
|
||||
wonderful
|
||||
|
||||
@ -1,19 +1,19 @@
|
||||
<c:template xmlns:c="core" xmlns:layout="layout">
|
||||
<layout:use template="./layout-default.rhtml" show-header="$false">
|
||||
<layout:use template="./layout-default.rxml" show-header="$false">
|
||||
<layout:put into="body">BODY CONTENT</layout:put>
|
||||
<layout:put into="footer">FOOTER CONTENT</layout:put>
|
||||
</layout:use>
|
||||
<layout:use template="./layout-default.rhtml" show-header="$true">
|
||||
<layout:use template="./layout-default.rxml" show-header="$true">
|
||||
<layout:put into="header">HEADER CONTENT</layout:put>
|
||||
<layout:put into="body">BODY CONTENT</layout:put>
|
||||
<layout:put into="footer">FOOTER CONTENT</layout:put>
|
||||
</layout:use>
|
||||
<layout:use template="./layout-default.rhtml" show-header="$true">
|
||||
<layout:use template="./layout-default.rxml" show-header="$true">
|
||||
<layout:put into="header" value="VALUE HEADER"/>
|
||||
<layout:put into="body">BODY CONTENT</layout:put>
|
||||
<layout:put into="footer">FOOTER CONTENT</layout:put>
|
||||
</layout:use>
|
||||
<layout:use template="${require.resolve('./layout-default.rhtml')}" show-header="$true">
|
||||
<layout:use template="${require.resolve('./layout-default.rxml')}" show-header="$true">
|
||||
<layout:put into="body">BODY CONTENT</layout:put>
|
||||
<layout:put into="footer">FOOTER CONTENT</layout:put>
|
||||
</layout:use>
|
||||
|
||||
@ -1,8 +1,8 @@
|
||||
<template
|
||||
xmlns:c="http://raptorjs.org/templates/core"
|
||||
xmlns:test="test"
|
||||
params="rootClass,colors,message">
|
||||
|
||||
|
||||
|
||||
<test:hello name="World"/>
|
||||
|
||||
<div class="hello-world ${rootClass}">${message}</div>
|
||||
|
||||
@ -1 +1 @@
|
||||
<div class="hello-world title">Hello World!</div><ul><li class="color">red</li><li class="color">green</li><li class="color">blue</li></ul>
|
||||
Hello World!<div class="hello-world title">Hello World!</div><ul><li class="color">red</li><li class="color">green</li><li class="color">blue</li></ul>
|
||||
@ -1,3 +1 @@
|
||||
<c:template xmlns:c="core">
|
||||
Hello John
|
||||
</c:template>
|
||||
Hello John
|
||||
Loading…
x
Reference in New Issue
Block a user