Created
June 9, 2015 12:37
-
-
Save brunodles/b3a05e841dc9e5c3992f to your computer and use it in GitHub Desktop.
Apiary Routes
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 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