diff --git a/.travis.yml b/.travis.yml new file mode 100644 index 0000000..6e5919d --- /dev/null +++ b/.travis.yml @@ -0,0 +1,3 @@ +language: node_js +node_js: + - "0.10" diff --git a/lib/index.js b/lib/index.js index 0063e78..0a7ac6e 100644 --- a/lib/index.js +++ b/lib/index.js @@ -76,8 +76,9 @@ function parseHtmlStart(tag, tagName, attributes, selfClosing) { hooks = hooksFromAttributes(attributes, 'Element'); } var attributesMap = parseAttributes(attributes); - var namespaceUri = (lowerTagName === 'svg') ? - templates.NAMESPACE_URIS.svg : parseNode.namespaceUri; + var namespaceUri = attributes.xmlns ? attributes.xmlns : + (lowerTagName === 'svg') ? templates.NAMESPACE_URIS.svg : + parseNode.namespaceUri; var Constructor = templates.Element; if (lowerTagName === 'tag') { Constructor = templates.DynamicElement; diff --git a/test/templates.mocha.js b/test/templates.mocha.js index faaec61..8be06c9 100644 --- a/test/templates.mocha.js +++ b/test/templates.mocha.js @@ -4,6 +4,8 @@ var contexts = derbyTemplates.contexts; var templates = derbyTemplates.templates; var parsing = require('../lib/index'); +var SVG = 'http://www.w3.org/2000/svg'; + var model = { data: { _page: { @@ -65,6 +67,63 @@ describe('Parse and render literal HTML', function() { }); +describe('Parse and render SVG', function() { + function test(name, source, expected, check) { + it(name, function() { + var template = parsing.createTemplate(source); + expect(check(template.content)).equal(expected); + }); + } + + describe('renders an SVG tag', function() { + test('Empty SVG', '', SVG, function(content) { + return content[0].ns; + }); + }); + + describe('renders a g element', function() { + test('by itself (no namespace)', + '', undefined, function(content) { + return content[0].ns; + }); + test('inside of SVG', + '', SVG, function(content) { + return content[0].content[0].ns; + }); + test('with explicit namespace', + '', + SVG, + function(content) { + return content[0].ns; + }); + }); +}); + + +describe('Dynamically render SVG and/or HTML', function() { + function test(name, source, expected, check) { + it(name, function() { + var template = parsing.createTemplate(source); + expect(check(template.content)).eql(expected); + }); + } + + test('as a result of test', + '{{if layout.renderer == "svg"}}' + + '' + + '{{else}}' + + '
' + + '{{/if}}', + [SVG, undefined], + function(content) { + return [ + content[0].contents[0][0].ns, + content[0].contents[1][0].ns, + ]; + }); +}); + + describe('Parse and render dynamic text and blocks', function() { function test(source, expected) {