Skip to content

Instantly share code, notes, and snippets.

@sxross
Created June 29, 2010 23:49
Show Gist options
  • Save sxross/458007 to your computer and use it in GitHub Desktop.
Save sxross/458007 to your computer and use it in GitHub Desktop.
# This may well be user error, but CoffeeScript:
ubb_text: ubb_text.replace /\[img\](.+?)\[\/img\]/gi, (str, args...) ->
throw "oh, crap!" unless args[0]
image_url: if args[0].match(/^http/i) then args[0] else "http://www1.istockphoto.com${args[0]}"
"<img src=\"${image_url}\" />"
# The resultant js is:
ubb_text = ubb_text.replace(/\[img\](.+?)\[\/img\]/gi, function(str) {
var args, image_url;
args = __slice.call(arguments, 1, arguments.length - 0);
if (!(args[0])) {
throw "oh, crap!";
}
image_url = args[0].match(/^http/i) ? args[0] : ("http://www1.istockphoto.com" + (args[0]));
return image_url;
});
# Now, by indenting the last line, as:
ubb_text: ubb_text.replace /\[img\](.+?)\[\/img\]/gi, (str, args...) ->
throw "oh, crap!" unless args[0]
image_url: if args[0].match(/^http/i) then args[0] else "http://www1.istockphoto.com${args[0]}"
"<img src=\"${image_url}\" />"
# The javascript generated is as desired:
ubb_text = ubb_text.replace(/\[img\](.+?)\[\/img\]/gi, function(str) {
var args, image_url;
args = __slice.call(arguments, 1, arguments.length - 0);
if (!(args[0])) {
throw "oh, crap!";
}
image_url = args[0].match(/^http/i) ? args[0] : ("http://www1.istockphoto.com" + (args[0]));
return "<img src=\"" + (image_url) + "\" />";
});
# This might be user error, but I'm not seeing why an extra level of indentation in necessary here.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment