site/controllers/projects.moon

30 lines
835 B
Plaintext
Raw Normal View History

config = require("lapis.config").get!
discount = require "discount"
lapis = require "lapis"
http = require "lapis.nginx.http"
oleg = require "lib/oleg"
require "base64"
gh = require('github').new({access_token: os.getenv "GITHUB_TOKEN", httpclient_driver: 'httpclient.ngx_driver'})
2015-02-01 08:17:40 +00:00
class Projects extends lapis.Application
2015-02-04 17:33:24 +00:00
[projects: "/projects"]: =>
2015-02-07 00:33:34 +00:00
@title = "Projects"
2015-02-01 08:17:40 +00:00
render: true
[readme: "/projects/:name"]: =>
2015-02-07 00:33:34 +00:00
@title = "Readme for #{@params.name}"
2015-02-07 00:42:44 +00:00
@name = @params.name
2015-02-13 19:28:23 +00:00
@doc = oleg.cache "readmes", @params.name, ->
reply, err = gh\authed_request "/repos/Xe/#{@params.name}/contents/README.md"
readme = base64.decode reply.content
if code == 404
return render: "notfound", status_code: 404
2015-02-13 19:28:23 +00:00
discount readme, "toc", "nopants", "autolink"
render: true