Skip to content

Instantly share code, notes, and snippets.

@gnab
Created May 29, 2011 20:38
Show Gist options
  • Save gnab/998116 to your computer and use it in GitHub Desktop.
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
#
# 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