b0VIM 7.4y‚ VÅ©ÆìIsqzkiwi~sqz/projects/coffeerest-api-doc/index.coffeeutf-8 3210#"! UtpQ$Rad"‚QÖ¸žih32åÀ¡�a+  ó Ç r #  í Ó ® r  Ë < û š t o C ì Ò } a  ùظ›,ñÛ¤‰3ÐonR2ךa*÷˪ŽiZ?ÿä¹v\ èÕ¹V0ò‚� # #restext += (if resource.description? then resource.description+line else "no description (yet)"+line) # #restext += "### "+method.toUpperCase()+" "+url+line #for method,resource of methods vars.resources[ resource ].children.push { name: resource, url: url, methods: methods_flat } payload: payload url: url requestors: requestors query_params: (if query_params.length then query_params else undefined ) schema: schema notes: ( if method.notes? then method.notes else false ) description: method.description methodname: name id: String(name+vars.host+url).replace(/[\W_]+/g,"_") methods_flat.push }) payload: payload_flat method: name, url: vars.host+url code: mustache.render( code, { type: type requestors.push requestors = []; for type,code of vars.request console.log JSON.stringify query_params,null,2 query_params.push { varname: queryvar, info: v } v.values = v.values.join(',') for queryvar, v of method.query_params if method.query_params? query_params = []; payload_flat = JSON.stringify defaults({ type: 'object', properties: method.payload }) payload = JSON.stringify defaults({ type: 'object', properties: method.payload }),null,2 schema.push { field:k, schema: util.inspect(v) } for k,v of method.payload if method.payload? payload_flat = false; payload = false schema = []; for name,method of methods methods_flat = []; vars.resources[ resource ] = { resourcename: resource, children: [] } if not vars.resources[ resource ]? resource = urlparts[1] urlparts = url.split("/") for url,methods of resources vars.resources = {} vars.replyschema_codes = JSON.stringify model.replyschema.messages, null, 2 vars.host += urlprefix vars.replyschema_payload = JSON.stringify( defaults model.replyschema, null, 2 ) vars = model.doc template = require('fs').readFileSync(__dirname+"/mustache/index.html").toString() @.html = (resources, urlprefix, model) -> return header+description+restext restext += "JSON Schema:"+line+indent( 4, JSON.stringify(resource.payload,null,2) )+line restext += "> "+ resource.notes+ "\n" if resource.notes? restext += "Example payload:"+line+indent( 4, JSON.stringify(defaults( { type: "object", properties: resource.payload}),null,2) )+line continue if not resource.payload? or not method? restext += (if resource.description? then resource.description+line else "no description (yet)"+line) restext += "### "+method.toUpperCase()+" "+url+line for method,resource of methods url = urlprefix+url for url,methods of resources restext = "" description += "\n"+model.doc.description+"\n\n"+model.doc.security+"\n\n" description = "Documentation of "+model.name+" "+urlprefix+" API endpoints"+line header = "JSON API\n========"+line line = "\n\n" return lines.join("\n") ( lines[k] = blank + line for k,line of lines ) blank = blank + " " for i in [0..spaces] blank = "" lines = str.split("\n"); return str if str == undefined indent = (spaces,str) -> @.markdown = (resources, urlprefix, model) ->module.exports = (server, model, lib, urlprefix ) ->clone = (obj) -> JSON.parse( JSON.stringify obj )util = require 'util'mustache = require 'mustache'defaults = require 'json-schema-defaults'adá � $Å4Ñž‘gN$# à § i * Õ ¬ ’ ~ m V U ? ý á § l N  ï Õ Á ° ™ ˜ � Œ return @ )(urlprefix,model,@) next() res.end() res.write(body) 'Content-Type': 'text/html' 'Content-Length': Buffer.byteLength(body), res.writeHead 200, body = me.html model.resources, urlprefix, model server.get urlprefix+"/doc/html", (req,res,next) -> ( (urlprefix,model,me) -> console.log "registering REST resource: "+urlprefix+"/doc/html" # register html url )(urlprefix,model,@) next() res.end() res.write(body) 'Content-Type': 'text/plain' 'Content-Length': Buffer.byteLength(body), res.writeHead 200, body = me.markdown model.resources, urlprefix, model server.get urlprefix+"/doc/markdown", (req,res,next) -> ( (urlprefix,model,me) -> console.log "registering REST resource: "+urlprefix+"/doc/markdown" # register markdown url return mustache.render template, vars vars.resources = arr arr.push r for k,r of vars.resources arr = [] # convert to array since mustache loves arrays # #restext += "JSON Schema:"+line+indent( 4, JSON.stringify(resource.payload,null,2) )+line # #restext += "Example payload:"+line+indent( 4, JSON.stringify(defaults( { type: "object", properties: resource.payload}),null,2) )+line # #continue if not resource.payload? or not method?