Skip to content

Instantly share code, notes, and snippets.

@chrisdickinson
Created August 24, 2010 18:12
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 chrisdickinson/548017 to your computer and use it in GitHub Desktop.
Save chrisdickinson/548017 to your computer and use it in GitHub Desktop.
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__
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