Created
June 29, 2010 23:49
-
-
Save sxross/458007 to your computer and use it in GitHub Desktop.
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
# 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