Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Non xhtml namespaceuri #5

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
language: node_js
node_js:
- "0.10"
5 changes: 3 additions & 2 deletions lib/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
59 changes: 59 additions & 0 deletions test/templates.mocha.js
Original file line number Diff line number Diff line change
Expand Up @@ -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: {
Expand Down Expand Up @@ -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 />', SVG, function(content) {
return content[0].ns;
});
});

describe('renders a g element', function() {
test('by itself (no namespace)',
'<g />', undefined, function(content) {
return content[0].ns;
});
test('inside of SVG',
'<svg><g /></svg>', SVG, function(content) {
return content[0].content[0].ns;
});
test('with explicit namespace',
'<g xmlns="http://www.w3.org/2000/svg" />',
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"}}' +
'<g xmlns="http://www.w3.org/2000/svg" />' +
'{{else}}' +
'<div />' +
'{{/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) {
Expand Down