Skip to content

Instantly share code, notes, and snippets.

@brunodles
Created June 9, 2015 12:37
Show Gist options
  • Save brunodles/b3a05e841dc9e5c3992f to your computer and use it in GitHub Desktop.
Save brunodles/b3a05e841dc9e5c3992f to your computer and use it in GitHub Desktop.
Apiary Routes
var mainFile = process.argv[2];
var fs = require('fs');
var route_regex = /\#.+\[\/(.+)\]/;
var method_regex = /\#*\s*(.+)\s*\[(\w+)\]/;
var file = fs.readFileSync(mainFile).toString().split("\n");
var url = "";
for (var i in file){
var line = file[i];
var u = route_regex.exec(line);
if (u !== null){
console.log("");
url = u[1];
}
var m = method_regex.exec(line);
if (m !== null)
print(url, m[2], m[1]);
}
function print(url, method, description){
u = paddy(url, 40);
m = paddy(method, 10);
console.log("%s %s \t %s", u, m, description);
}
function paddy(n, p) {
var pad_char = ' ';
var pad = new Array(1 + p).join(pad_char);
return (pad + n).slice(-pad.length);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment