Skip to content

Commit

Permalink
allow multiple SVGs - fixes #130
Browse files Browse the repository at this point in the history
  • Loading branch information
Rich-Harris committed Dec 6, 2016
1 parent 29a81cb commit 1d941ab
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 1 deletion.
2 changes: 1 addition & 1 deletion compiler/generate/visitors/Element.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ export default {

const local = {
name,
namespace: name === 'svg' ? 'http://www.w3.org/2000/svg' : generator.current.namespace,
namespace: node.name === 'svg' ? 'http://www.w3.org/2000/svg' : generator.current.namespace,
isComponent: false,

allUsedContexts: new Set(),
Expand Down
29 changes: 29 additions & 0 deletions test/compiler/svg-multiple/_config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
export default {
data: {
x: 0,
y: 0,
width: 100,
height: 100
},

html: `
<svg><rect x="0" y="0" width="100" height="100"></rect></svg>
<svg><rect x="0" y="0" width="100" height="100"></rect></svg>
`,

test ( assert, component, target ) {
const svgs = target.querySelectorAll( 'svg' );
const rects = target.querySelectorAll( 'rect' );

assert.equal( svgs[0].namespaceURI, 'http://www.w3.org/2000/svg' );
assert.equal( svgs[0].namespaceURI, 'http://www.w3.org/2000/svg' );
assert.equal( rects[1].namespaceURI, 'http://www.w3.org/2000/svg' );
assert.equal( rects[1].namespaceURI, 'http://www.w3.org/2000/svg' );

component.set({ width: 150, height: 50 });
assert.htmlEqual( target.innerHTML, `
<svg><rect x="0" y="0" width="150" height="50"></rect></svg>
<svg><rect x="0" y="0" width="150" height="50"></rect></svg>
` );
}
};
7 changes: 7 additions & 0 deletions test/compiler/svg-multiple/main.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
<svg>
<rect x='{{x}}' y='{{y}}' width='{{width}}' height='{{height}}'/>
</svg>

<svg>
<rect x='{{x}}' y='{{y}}' width='{{width}}' height='{{height}}'/>
</svg>

0 comments on commit 1d941ab

Please sign in to comment.