Created
May 29, 2011 20:38
-
-
Save gnab/998116 to your computer and use it in GitHub Desktop.
Script for wrapping knockout.js template files in Javascript to be included in DOM
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
# | |
# Wraps the given files inside the following Javascript code for use with | |
# knockout.js: | |
# | |
# $('body').append("<script id=\"<templateId>\" type=\"text/html\"><templateContent></script>"); | |
# | |
# - <templateId> the filename without the extension | |
# - <templateContent> the content of the file, with quotes escaped | |
# | |
for file in "$@"; do | |
id=`echo $file | awk -F"/" '{print $NF}' | awk -F"." '{print $1}'` | |
html="<script id=\"${id}Template\" type=\"text/html\">`cat $file`</script>" | |
html=`echo $html | sed 's/"/\\\"/g'` | |
echo "\$('body').append(\"$html\");" | |
done |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment