Created
August 24, 2010 18:12
-
-
Save chrisdickinson/548017 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
sys: require 'sys' | |
require './jsdocstring' | |
howdy: (lol) -> | |
"Well hello there, folks. I'm testing out my docString thing. | |
In coffeescript. | |
DocStrings are awesome." | |
lol | |
sys.puts howdy.__doc__ |
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
var sys = require('sys'); | |
var getDocString = function() { | |
if(this.__docString !== undefined) { | |
return this.__docString; | |
} | |
var source = this.toString(); | |
var re = /\s*('(.*)(('|\\)([;\s]*))|"(.*)(("|\\)([;\s]*)))/g, | |
parts = []; | |
do { | |
var match = re(source); | |
if(match) { | |
var part = match[0].replace(/\s*$/g, '').replace(/^\s*/g, ''), | |
last = part.charAt(part.length-1); | |
parts.push(part.replace(/^('|")/g,'').replace(/(['"\\]{1})(;)?$/, '')); | |
source = source.slice(match.index + match[0].length); | |
if(last == '\\') { | |
re = /\s*(.*)(['"\\]{1})(;)?\s*/; | |
} | |
} | |
} while(match); | |
this.__docString = parts.join("\n"); | |
return this.__docString; | |
}; | |
Function.prototype.__defineGetter__('__doc__', getDocString); | |
var test1 = function() { | |
"Double quote style"; | |
}; | |
var test2 = function() { | |
'single quote style'; | |
} | |
var test3 = function() { | |
'i\'m happy for you'; | |
} | |
var test4 = function() { | |
'multi line score \ | |
lol hi'; | |
} | |
var test5 = function() { | |
'multi line score \ | |
that ends weird' | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment