예제 #1
0
func init() {
	template.AddFuncs(template.FuncMap{
		"#config": func(name string, def string) template.HTML {
			var buf bytes.Buffer
			buf.WriteString("<h3 class=\"config\">")
			buf.WriteString(html.Escape(name))
			if def != "" {
				buf.WriteString(" <span class=\"label label-success\">optional</span>")
				fmt.Fprintf(&buf, " <span class=\"default\">default: %s</span>", html.Escape(def))
			} else {
				buf.WriteString(" <span class=\"label label-danger\">required</span>")
			}
			buf.WriteString("</h3>")
			return template.HTML(buf.String())
		}})
	config.MustParse()
	App = app.New()
	App.SetTrustXHeaders(true)

	// Redirect all other possible hosts to governator.io
	redir := app.RedirectHandler("http://governator.io${0}", true)
	App.Handle("(.*)", redir, app.HostHandler("governator-io.appspot.com"))
	App.Handle("(.*)", redir, app.HostHandler("www.governator.io"))

	App.HandleAssets("/assets/", pathutil.Relative("assets"))
	App.Handle("^/$", app.TemplateHandler("main.html", nil))
	App.Handle("^/install\\.sh$", fileHandler("contrib/install.sh"))
	App.Handle("^/get/releases/linux/x86_64/latest/governator$", fileHandler("governator"))

	App.Handle("^/contrib/(.*)", func(ctx *app.Context) {
		path := filepath.Join(data, "contrib", filepath.FromSlash(ctx.IndexValue(0)))
		serveFile(ctx, path)
	})
}
예제 #2
0
파일: funcs.go 프로젝트: rainycape/gondola
func init() {
	template.AddFuncs([]*template.Func{
		{Name: "func_id", Fn: funcId},
		{Name: "func_name", Fn: funcName},
		{Name: "type_id", Fn: typeId},
		{Name: "issues_color", Fn: issuesColor},
		{Name: "complexity_color", Fn: complexityColor},
		{Name: "bootstrap_color", Fn: bootstrapColor},
		{Name: "func_list_name", Fn: funcListName},
	})
}
예제 #3
0
func init() {
	template.AddFuncs([]*template.Func{
		{Name: "reverse_article", Fn: reverseArticle, Traits: template.FuncTraitContext},
		{Name: "reverse_app_article", Fn: reverseAppArticle},
	})
}
예제 #4
0
파일: app.go 프로젝트: rainycape/gondola
func New(opts Options) *App {
	d := &appData{
		opts: opts,
	}
	d.setUserType(opts.UserType)
	a := &App{App: *reusableapp.New(reusableapp.Options{
		Name:          "Users",
		Data:          d,
		DataKey:       appDataKey,
		AssetsData:    assetsData,
		TemplatesData: tmplData,
	})}
	a.Prefix = "/users/"
	a.AddTemplateVars(map[string]interface{}{
		"SiteName":            opts.SiteName,
		"FacebookApp":         opts.FacebookApp,
		"GoogleApp":           opts.GoogleApp,
		"GoogleScopes":        opts.GoogleScopes,
		"TwitterApp":          opts.TwitterApp,
		"GithubApp":           opts.GithubApp,
		"JSSignIn":            JSSignInHandlerName,
		"JSSignInFacebook":    JSSignInFacebookHandlerName,
		"JSSignInGoogle":      JSSignInGoogleHandlerName,
		"JSSignUp":            JSSignUpHandlerName,
		"Forgot":              ForgotHandlerName,
		"Reset":               ResetHandlerName,
		"SignIn":              func() string { return SignInHandlerName },
		"SignInFacebook":      SignInFacebookHandlerName,
		"SignInGoogle":        SignInGoogleHandlerName,
		"SignInTwitter":       SignInTwitterHandlerName,
		"SignInGithub":        SignInGithubHandlerName,
		"SignUp":              SignUpHandlerName,
		"SignOut":             SignOutHandlerName,
		"FacebookChannel":     FacebookChannelHandlerName,
		"Current":             Current,
		"DisableDirectSignIn": opts.DisableDirectSignIn,
		"DisableRegistration": opts.disableRegistration(),
		"SocialAccountTypes":  d.enabledSocialAccountTypes(),
	})

	a.Handle("^/sign-in/$", SignInHandler, app.NamedHandler(SignInHandlerName))
	if opts.FacebookApp != nil {
		signInFacebookHandler := oauth2SignInHandler(signInFacebookTokenHandler,
			opts.FacebookApp.Client, opts.FacebookPermissions)
		a.Handle("^/sign-in/facebook/$", signInFacebookHandler, app.NamedHandler(SignInFacebookHandlerName))
		a.Handle("^/js/sign-in/facebook/$", JSSignInFacebookHandler, app.NamedHandler(JSSignInFacebookHandlerName))
		a.Handle("^/fb-channel/$", FacebookChannelHandler, app.NamedHandler(FacebookChannelHandlerName))
	}
	if opts.GoogleApp != nil {
		signInGoogleHandler := oauth2SignInHandler(signInGoogleTokenHandler,
			opts.GoogleApp.Client, opts.googleScopes())
		a.Handle("^/sign-in/google/$", signInGoogleHandler, app.NamedHandler(SignInGoogleHandlerName))
		a.Handle("^/js/sign-in/google/$", JSSignInGoogleHandler, app.NamedHandler(JSSignInGoogleHandlerName))
	}
	if opts.TwitterApp != nil {
		signInTwitterHandler := twitter.AuthHandler(opts.TwitterApp, signInTwitterUserHandler)
		a.Handle("^/sign-in/twitter/$", signInTwitterHandler, app.NamedHandler(SignInTwitterHandlerName))
	}
	if opts.GithubApp != nil {
		signInGithubHandler := oauth2SignInHandler(signInGithubTokenHandler,
			opts.GithubApp.Client, opts.githubScopes())
		a.Handle("^/sign-in/github/$", signInGithubHandler, app.NamedHandler(SignInGithubHandlerName))
	}
	a.Handle("^/sign-up/$", SignUpHandler, app.NamedHandler(SignUpHandlerName))
	a.Handle("^/sign-out/$", SignOutHandler, app.NamedHandler(SignOutHandlerName))
	a.Handle("^/forgot/$", ForgotHandler, app.NamedHandler(ForgotHandlerName))
	a.Handle("^/reset/$", ResetHandler, app.NamedHandler(ResetHandlerName))
	a.Handle("^/js/sign-in/$", JSSignInHandler, app.NamedHandler(JSSignInHandlerName))
	a.Handle("^/js/sign-up/$", JSSignUpHandler, app.NamedHandler(JSSignUpHandlerName))
	template.AddFuncs([]*template.Func{
		{Name: "user_image", Fn: Image, Traits: template.FuncTraitContext},
		{Name: "__users_get_social", Fn: getSocial},
	})
	a.MustLoadTemplatePlugin("users-plugin.html", assets.Bottom)
	a.MustLoadTemplatePlugin("social-button.html", assets.None)
	return a
}