Created
March 11, 2014 22:28
-
-
Save raddrick/9496433 to your computer and use it in GitHub Desktop.
I use this to implement svg templating
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ | |
id: item[0], | |
date: item[1], | |
message: item[2], | |
commiter: item[3], | |
branch: item[4], | |
x: 0, | |
y: 0, | |
height: 0, | |
width: 0 | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function convert_template(options) { | |
var template=document.getElementById('commit'); | |
var res = this.update_template(template,m); | |
res="<svg version='1.1' xmlns='http://www.w3.org/2000/svg' xmlns:xlink='http://www.w3.org/1999/xlink'>"+res+'</svg>'; | |
var parser = new DOMParser(); | |
res=parser.parseFromString(res, "application/xml"); | |
return res.firstChild.firstElementChild; | |
} | |
function update_template(t,v){ | |
for(var prop in v) { | |
if(v.hasOwnProperty(prop)) { | |
// {{x}} for x, replace | |
var re = new RegExp("({{" + prop + "}})"); | |
t = t.replace(re, v[prop]); | |
} | |
} | |
return t; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<script type='text/template' id='commit'> | |
<g class="commit {{id}}" transform="transform{{x}} {{y}}"> | |
<rect x="0" y="0" height="{{height}}" width="{{width}}"></rect> | |
<text x="" y="" class="id">{{id}}</text> | |
<text x="" y="" class="date">{{date}}</text> | |
<text x="" y="" class="commiter">{{commiter}}</text> | |
<text x="" y="" class='branch'>{{branch}}</text> | |
<foreignObject width="100%" height="400"> | |
<div class="content"> | |
{{content}} | |
</div> | |
</foreignObject> | |
</g> | |
</script> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment