-
-
Save josher19/4167568 to your computer and use it in GitHub Desktop.
/** Give documentation (via mouseover) in title attributes for functions in code highlighted with rainbowco.de */ | |
function minidoc(docs,funcs) { | |
funcs = funcs || document.querySelectorAll('code span.function') // Could also do 'code span.method' | |
for(var i=0, len=funcs.length; i<len; ++i) { | |
var t = docs[funcs[i].textContent]; | |
if (t) funcs[i].title = t; | |
} | |
} | |
// JSON.stringify(docs) | |
var docs = {"Stapes":"A (really) tiny Javascript MVC microframework.","create":"Create a new instance of a Stapes object.","extend":"Extend your module by giving an object. Args: optional context, object","on":"Add an event listener for eventName with handler and optional context.","off":"Removes event handler(s) from this object. Optional args: eventType, handler.","emit":"Send event(s) to the module. Args: eventName(s), data.","set":"Sets an attribute of `key` to `value`, triggering an event unless `silent` is true. Args: key, value, optional silent","remove":"Deletes an attibute. Opposite of `.set(key)`. Args: key or function, optional silent.","getAllAsArray":"Returns all attributes as an array. Args: (None).","size":"Returns the number of attributes in a module.","push":"Sets a value, automatically generates an unique uuid as a key. Args: array or value, optional boolean silent","filter":"Iterate over all attributes of a module. Args: function, optional context","has":"Checks if a key is available and returns true or false.","update":"Updates an attribute with a new value, based on the return value of a function. Args: optional key, function"} | |
minidoc(docs); |
{
"Stapes": "A (really) tiny Javascript MVC microframework. See also: Stapes.create",
"create": "Create a new instance of a Stapes object. See also: mixinEvents, extend, on",
"each": "Iterate over all attributes of a module. Args: function, optional context (default: this module).",
"emit": "Send event(s) to the module. Args: string eventName(s), optional data.",
"extend": "Extend your module by giving an object from which to copy attributes. Args: optional context (default=this module), object.",
"filter": "Iterate over all attributes of a module. Args: function, optional context",
"get": "Gets an attribute by key. If the item is not available will return null. See also: set, has, getAll. Args: key (string) or filter function.",
"getAll": "Returns copy of all the attributes of a module as an object. See also: get, getAllAsArray",
"getAllAsArray": "Returns all attributes as an array. See also: get, getAll. Args: (None).",
"has": "Checks if a key is available and returns true or false. See also: get, set.",
"mixinEvents": "Add Stapes event handlers to existing (or new if blank) object. Args: optional object.",
"off": "Removes event handler(s) from this object. Args: optional string eventType, optional function handler.",
"on": "Add an event listener triggered by emit. Args: string eventName, function handler, optional context OR object {eventName1: handler1, eventName2: handler2, ...}, optional context.",
"push": "Sets a value, automatically generates an unique uuid as a key. Args: array or value, optional boolean silent.",
"remove": "Deletes an attibute. Opposite of .set(key)
. Args: key or function, optional boolean silent.",
"set": "Sets an attribute of key to value, triggering an event unless silent
is true. See also: get, emit. Args: string key, value, optional boolean silent.",
"size": "Returns the number of attributes in a module.",
"update": "Updates an attribute with a new value, based on the return value of a function. Args: optional key, function."
}
/** More full featured version. YAGNI. _/
function minidoc(docs,funcs) {
funcs = funcs || document.querySelectorAll('code span.function') // Could also do 'code span.method'
var hits=0, misses=0, missed = {};
for(var i=0, t, len=funcs.length; i<len; ++i) {
t = docs[funcs[i].textContent];
if (t) {++hits; funcs[i].title = t; } else { ++misses; missed[funcs[i].textContent]=0; }
}
return {hits:hits, misses:misses, perc:100_hits/(hits+misses), missed:missed}
}