Permalink
Browse files

Initial

  • Loading branch information...
mjibson committed Mar 14, 2013
0 parents commit 55fd9885659977aa8298f89d91b11d860687a6b1
Showing with 33,089 additions and 0 deletions.
  1. +15 −0 app.yaml
  2. +57 −0 goapp/funcs.go
  3. +69 −0 goapp/main.go
  4. +55 −0 goapp/types.go
  5. +87 −0 goapp/utils.go
  6. +6,158 −0 static/css/bootstrap-2.3.1.css
  7. +14,733 −0 static/js/angular-1.0.5.js
  8. +2,276 −0 static/js/bootstrap-2.3.1.js
  9. +9,597 −0 static/js/jquery-1.9.1.js
  10. +1 −0 static/js/site.js
  11. +41 −0 templates/base.html
@@ -0,0 +1,15 @@
application: go-read
version: 1
runtime: go
api_version: go1
handlers:
- url: /static
static_dir: static
- url: /login/google
login: required
script: _go_app
- url: /.*
script: _go_app
@@ -0,0 +1,57 @@
/*
* Copyright (c) 2013 Matt Jibson <matt.jibson@gmail.com>
*
* Permission to use, copy, modify, and distribute this software for any
* purpose with or without fee is hereby granted, provided that the above
* copyright notice and this permission notice appear in all copies.
*
* THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
* WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
* MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
* ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
* WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
* ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
* OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
*/
package goapp
import (
"html/template"
"reflect"
)
// eq reports whether the first argument is equal to
// any of the remaining arguments.
func eq(args ...interface{}) bool {
if len(args) == 0 {
return false
}
x := args[0]
switch x := x.(type) {
case string, int, int64, byte, float32, float64:
for _, y := range args[1:] {
if x == y {
return true
}
}
return false
}
for _, y := range args[1:] {
if reflect.DeepEqual(x, y) {
return true
}
}
return false
}
func url(name string, pairs ...string) string {
u, _ := router.Get(name).URL(pairs...)
return u.String()
}
var funcs = template.FuncMap{
"eq": eq,
"url": url,
}
@@ -0,0 +1,69 @@
/*
* Copyright (c) 2013 Matt Jibson <matt.jibson@gmail.com>
*
* Permission to use, copy, modify, and distribute this software for any
* purpose with or without fee is hereby granted, provided that the above
* copyright notice and this permission notice appear in all copies.
*
* THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
* WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
* MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
* ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
* WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
* ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
* OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
*/
package goapp
import (
"appengine/user"
"github.com/gorilla/mux"
"github.com/mjibson/MiniProfiler/go/miniprofiler"
mpg "github.com/mjibson/MiniProfiler/go/miniprofiler_gae"
"github.com/mjibson/goon"
"html/template"
"log"
"net/http"
)
var router = new(mux.Router)
var templates *template.Template
func init() {
var err error
if templates, err = template.New("").Funcs(funcs).
ParseFiles(
"templates/base.html",
); err != nil {
log.Fatal(err)
}
router.Handle("/", mpg.NewHandler(Main)).Name("main")
router.Handle("/login/google", mpg.NewHandler(LoginGoogle)).Name("login-google")
http.Handle("/", router)
miniprofiler.Position = "right"
miniprofiler.ShowControls = false
}
func Main(c mpg.Context, w http.ResponseWriter, r *http.Request) {
_ = goon.FromContext(c)
if err := templates.ExecuteTemplate(w, "base.html", includes(c)); err != nil {
serveError(w, err)
}
}
func LoginGoogle(c mpg.Context, w http.ResponseWriter, r *http.Request) {
if u := user.Current(c); u != nil {
gn := goon.FromContext(c)
user := User{}
if e, err := gn.GetById(&user, u.ID, 0, nil); err == nil && e.NotFound {
user.Email = u.Email
gn.Put(e)
}
}
http.Redirect(w, r, url("main"), http.StatusFound)
}
@@ -0,0 +1,55 @@
/*
* Copyright (c) 2013 Matt Jibson <matt.jibson@gmail.com>
*
* Permission to use, copy, modify, and distribute this software for any
* purpose with or without fee is hereby granted, provided that the above
* copyright notice and this permission notice appear in all copies.
*
* THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
* WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
* MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
* ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
* WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
* ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
* OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
*/
package goapp
import (
"appengine/datastore"
"time"
)
// key: ID
type User struct {
Email string `datastore:"e,noindex"`
}
func (u *User) String() string {
return u.Email
}
// key: URL
type Feed struct {
Title string `datastore:"t,noindex"`
Updated time.Time `datastore:"u"`
Link string `datastore:"l,noindex"`
}
type FeedIndex struct {
Users []*datastore.Key `datastore:"u"`
}
type Story struct {
Date time.Time `datastore:"d,noindex"`
Text string `datastore:"t,noindex"`
Author string `datastore:"a,noindex"`
Content string `datastore:"i,noindex"`
Summary string `datastore:"s,noindex"`
Link string `datastore:"l,noindex"`
}
type StoryIndex struct {
Users []*datastore.Key `datastore:"u"`
}
@@ -0,0 +1,87 @@
/*
* Copyright (c) 2013 Matt Jibson <matt.jibson@gmail.com>
*
* Permission to use, copy, modify, and distribute this software for any
* purpose with or without fee is hereby granted, provided that the above
* copyright notice and this permission notice appear in all copies.
*
* THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
* WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
* MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
* ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
* WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
* ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
* OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
*/
package goapp
import (
"appengine"
"appengine/user"
"fmt"
mpg "github.com/mjibson/MiniProfiler/go/miniprofiler_gae"
"github.com/mjibson/goon"
"html/template"
"net/http"
)
func serveError(w http.ResponseWriter, err error) {
http.Error(w, err.Error(), http.StatusInternalServerError)
}
type Includes struct {
Angular string
BootstrapCss string
BootstrapJs string
Jquery string
MiniProfiler template.HTML
Site string
User *User
}
var (
Angular string
BootstrapCss string
BootstrapJs string
Jquery string
)
func init() {
angular_ver := "1.0.5"
bootstrap_ver := "2.3.1"
jquery_ver := "1.9.1"
if appengine.IsDevAppServer() {
Angular = fmt.Sprintf("/static/js/angular-%v.js", angular_ver)
BootstrapCss = fmt.Sprintf("/static/css/bootstrap-%v.css", bootstrap_ver)
BootstrapJs = fmt.Sprintf("/static/js/bootstrap-%v.js", bootstrap_ver)
Jquery = fmt.Sprintf("/static/js/jquery-%v.js", jquery_ver)
} else {
Angular = fmt.Sprintf("//ajax.googleapis.com/ajax/libs/angularjs/%v/angular.min.js", angular_ver)
BootstrapCss = fmt.Sprintf("//netdna.bootstrapcdn.com/twitter-bootstrap/%v/css/bootstrap-combined.min.css", bootstrap_ver)
BootstrapJs = fmt.Sprintf("//netdna.bootstrapcdn.com/twitter-bootstrap/%v/js/bootstrap.min.js", bootstrap_ver)
Jquery = fmt.Sprintf("//ajax.googleapis.com/ajax/libs/jquery/%v/jquery.min.js", jquery_ver)
}
}
func includes(c mpg.Context) *Includes {
i := &Includes{
Angular: Angular,
BootstrapCss: BootstrapCss,
BootstrapJs: BootstrapJs,
Jquery: Jquery,
MiniProfiler: c.P.Includes(),
Site: "/static/js/site.js",
}
if u := user.Current(c); u != nil {
gn := goon.FromContext(c)
user := new(User)
if _, err := gn.GetById(user, u.ID, 0, nil); err == nil {
i.User = user
}
}
return i
}
Oops, something went wrong.

0 comments on commit 55fd988

Please sign in to comment.