From 4a1ba50221fdf4b9865ff6c7d08868e0c73c1f7b Mon Sep 17 00:00:00 2001 From: Christine Dodrill Date: Sun, 1 Feb 2015 00:17:40 -0800 Subject: [PATCH] add autogenned list of projects --- app.moon | 1 + app.yaml | 1 + controllers/projects.moon | 35 +++++++++++++++++++++++++++++++++++ layout/bootstrap.moon | 2 +- views/projects.moon | 20 ++++++++++++++++++++ 5 files changed, 58 insertions(+), 1 deletion(-) create mode 100644 controllers/projects.moon create mode 100644 views/projects.moon diff --git a/app.moon b/app.moon index 7e005e6..97d0d48 100644 --- a/app.moon +++ b/app.moon @@ -5,6 +5,7 @@ class extends lapis.Application layout: require "layout.bootstrap" @include "controllers.hire" + @include "controllers.projects" [index: "/"]: => @user, err = gh\get_authenticated_user() diff --git a/app.yaml b/app.yaml index c1df408..51f27b2 100644 --- a/app.yaml +++ b/app.yaml @@ -7,3 +7,4 @@ overlay: dependencies: - moonscript - github + - dkjson diff --git a/controllers/projects.moon b/controllers/projects.moon new file mode 100644 index 0000000..d8c5831 --- /dev/null +++ b/controllers/projects.moon @@ -0,0 +1,35 @@ +lapis = require "lapis" +http = require "lapis.nginx.http" +json = require "dkjson" + +import respond_to from require "lapis.application" +import assert_valid from require "lapis.validate" + +class Projects extends lapis.Application + [projects: "/projects"]: => + res, code = http.simple { + url: "https://api.github.com/users/Xe/repos" + } + + if code != 200 + @err = res + return render: "error", status: 500 + + repos, _, err = json.decode res + + if err + @err = err + return render: "error", status: 500 + + @repos = {} + + for _, repo in pairs(repos) + if not repo.fork + table.insert repos, repo + + render: true + + [portfolio: "/portfolio"]: => + + render: true + diff --git a/layout/bootstrap.moon b/layout/bootstrap.moon index 7d6d00d..a4c1d8e 100644 --- a/layout/bootstrap.moon +++ b/layout/bootstrap.moon @@ -43,7 +43,7 @@ class Layout extends Widget div id: "navbar", class: "collapse navbar-collapse", -> ul class: "nav navbar-nav", -> li -> - a href: "/about", "About" + a href: "/projects", "Projects" li -> a href: "/hire", "Hire Me" diff --git a/views/projects.moon b/views/projects.moon new file mode 100644 index 0000000..4548050 --- /dev/null +++ b/views/projects.moon @@ -0,0 +1,20 @@ +import Widget from require "lapis.html" + +class Projects extends Widget + content: => + h1 "My Projects" + + element "table" class: "table table-striped", -> + tr -> + td "Name" + td "Description" + td "Language" + td "Star Count" + + for _, repo in pairs @repos + tr -> + td -> + a href: repo.html_url, repo.name + td repo.description or "" + td repo.language + td repo.stargazers_count