示例#1
0
文件: app.go 项目: rainycape/gondola
func New(opts Options) *App {
	data := &appData{
		Groups: opts.Groups,
	}
	a := reusableapp.New(reusableapp.Options{
		Name:          "Docs",
		AssetsData:    assetsData,
		TemplatesData: tmplData,
		Data:          data,
	})
	a.Prefix = "/doc/"
	reverseDoc := func(s string) string { return a.MustReverse(PackageHandlerName, s) }
	reverseSource := func(s string) string { return a.MustReverse(SourceHandlerName, s) }
	data.Environment = doc.NewEnvironment(reverseDoc, reverseSource)
	data.Environment.Set(envAppKey, a)
	a.AddTemplateVars(map[string]interface{}{
		"List":    ListHandlerName,
		"StdList": StdListHandlerName,
		"Package": PackageHandlerName,
		"Source":  SourceHandlerName,
	})
	a.Handle("^/$", ListHandler, app.NamedHandler(ListHandlerName))
	a.Handle("^/pkg/std/?", StdListHandler, app.NamedHandler(StdListHandlerName))
	a.Handle("^/pkg/(.+)", PackageHandler, app.NamedHandler(PackageHandlerName))
	a.Handle("^/src/(.+)", SourceHandler, app.NamedHandler(SourceHandlerName))
	return &App{App: *a}
}
示例#2
0
文件: app.go 项目: rainycape/gondola
func New() *App {
	a := reusableapp.New(reusableapp.Options{
		Name:          "Articles",
		Data:          &appData{},
		TemplatesData: tmplData,
	})
	a.AddTemplateVars(map[string]interface{}{
		"Article": ArticleHandlerName,
		"List":    ArticleListHandlerName,
	})
	a.Handle("^/(.+)/$", ArticleHandler, app.NamedHandler(ArticleHandlerName))
	a.Handle("^/$", ArticleListHandler, app.NamedHandler(ArticleListHandlerName))
	return &App{App: *a}
}
示例#3
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
}