Skip to content

Instantly share code, notes, and snippets.

@gjtorikian
Created August 29, 2012 22:43
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save gjtorikian/3519845 to your computer and use it in GitHub Desktop.
Save gjtorikian/3519845 to your computer and use it in GitHub Desktop.
Wraps a chunk of text in Javascript, to support CORS and CLoud9 IDE external plugins
#!/bin/bash -e
# original here: https://github.com/lennartcl/cloud9-hello-plugin/blob/master/wrap-in-js.sh
if [ $# == 0 ]; then
echo No files specified
exit 1
fi
for F in $*; do
echo -n '// Wrapped in JavaScript, to avoid cross-origin restrictions, created using wrap-in-js.sh
define(function() {
return ' > "$F".js
cat "$F" | sed 's/\\/\\\\/g;'" s/'/\\\\'/g; s/^/'/g; s/$/\\\\n' +/g" >> "$F".js
echo "'';});" >> "$F".js
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment