forked from asoul-sig/asouldocs
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
8 changed files
with
22,533 additions
and
57 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
go-bindata -o=modules/bindata/bindata.go -ignore="\\.DS_Store|config.codekit|less" -pkg=bindata templates/... conf/... public/... |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,105 @@ | ||
package cmd | ||
|
||
import ( | ||
"fmt" | ||
"os" | ||
"path/filepath" | ||
"strings" | ||
|
||
"github.com/Unknwon/com" | ||
"github.com/codegangsta/cli" | ||
"gopkg.in/ini.v1" | ||
|
||
"github.com/peachdocs/peach/modules/bindata" | ||
) | ||
|
||
var New = cli.Command{ | ||
Name: "new", | ||
Usage: "Initialize a new Peach project", | ||
Action: runNew, | ||
Flags: []cli.Flag{ | ||
cli.StringFlag{"target, t", "my.peach", "Directory to save project files", ""}, | ||
cli.BoolFlag{"yes, y", "Yes to all confirmations", ""}, | ||
}, | ||
} | ||
|
||
func checkYesNo() bool { | ||
var choice string | ||
fmt.Scan(&choice) | ||
return strings.HasPrefix(strings.ToLower(choice), "y") | ||
} | ||
|
||
func toRed(str string) string { | ||
return fmt.Sprintf("\033[31m%s\033[0m", str) | ||
} | ||
|
||
func toGreen(str string) string { | ||
return fmt.Sprintf("\033[32m%s\033[0m", str) | ||
} | ||
|
||
func toYellow(str string) string { | ||
return fmt.Sprintf("\033[33m%s\033[0m", str) | ||
} | ||
|
||
func restoreAssets(target, dir string) { | ||
if err := bindata.RestoreAssets(target, dir); err != nil { | ||
fmt.Printf(toRed("✗ %v\n"), err) | ||
os.Exit(1) | ||
} | ||
} | ||
|
||
func runNew(ctx *cli.Context) { | ||
target := ctx.String("target") | ||
if com.IsExist(target) && !ctx.Bool("yes") { | ||
fmt.Printf(toYellow("Directory '%s' already exists, do you want to overwrite?[Y/n] "), target) | ||
if !checkYesNo() { | ||
os.Exit(0) | ||
} | ||
} | ||
|
||
fmt.Printf("➜ Creating '%s'...\n", target) | ||
os.MkdirAll(target, os.ModePerm) | ||
|
||
// Create default files. | ||
dirs := []string{"templates", "public"} | ||
for _, dir := range dirs { | ||
fmt.Printf("➜ Creating '%s'...\n", dir) | ||
os.RemoveAll(filepath.Join(target, dir)) | ||
restoreAssets(target, dir) | ||
} | ||
|
||
// Create custom templates. | ||
yes := ctx.Bool("yes") | ||
if !yes { | ||
fmt.Printf(toYellow("Do you want to use custom templates?[Y/n] ")) | ||
yes = checkYesNo() | ||
} | ||
|
||
if yes { | ||
fmt.Println("➜ Creating 'custom/templates'...") | ||
restoreAssets(filepath.Join(target, "custom"), "templates") | ||
|
||
// Update configuration to use custom templates. | ||
fmt.Println("➜ Updating custom configuration...") | ||
var cfg *ini.File | ||
var err error | ||
customPath := filepath.Join(target, "custom/app.ini") | ||
if com.IsExist(customPath) { | ||
cfg, err = ini.Load(customPath) | ||
if err != nil { | ||
fmt.Printf(toRed("✗ %v\n"), err) | ||
os.Exit(1) | ||
} | ||
} else { | ||
cfg = ini.Empty() | ||
} | ||
|
||
cfg.Section("page").Key("USE_CUSTOM_TPL").SetValue("true") | ||
if err = cfg.SaveTo(customPath); err != nil { | ||
fmt.Printf(toRed("✗ %v\n"), err) | ||
os.Exit(1) | ||
} | ||
} | ||
|
||
fmt.Println(toGreen("✓ Done!")) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
package cmd | ||
|
||
import ( | ||
"fmt" | ||
"net/http" | ||
|
||
"github.com/Unknwon/log" | ||
"github.com/codegangsta/cli" | ||
"github.com/go-macaron/i18n" | ||
"github.com/go-macaron/pongo2" | ||
"gopkg.in/macaron.v1" | ||
|
||
"github.com/peachdocs/peach/models" | ||
"github.com/peachdocs/peach/modules/middleware" | ||
"github.com/peachdocs/peach/modules/setting" | ||
"github.com/peachdocs/peach/routers" | ||
) | ||
|
||
var Web = cli.Command{ | ||
Name: "web", | ||
Usage: "Start Peach web server", | ||
Action: runWeb, | ||
Flags: []cli.Flag{ | ||
cli.StringFlag{"config, c", "custom/app.ini", "Custom configuration file path", ""}, | ||
}, | ||
} | ||
|
||
func runWeb(ctx *cli.Context) { | ||
if ctx.IsSet("config") { | ||
setting.CustomConf = ctx.String("config") | ||
} | ||
setting.NewContext() | ||
models.NewContext() | ||
|
||
log.Info("Peach %s", setting.AppVer) | ||
|
||
m := macaron.New() | ||
m.Use(macaron.Logger()) | ||
m.Use(macaron.Recovery()) | ||
m.Use(macaron.Statics(macaron.StaticOptions{ | ||
SkipLogging: setting.ProdMode, | ||
}, "custom/public", "public", models.HTMLRoot)) | ||
m.Use(i18n.I18n(i18n.Options{ | ||
Files: setting.Docs.Locales, | ||
})) | ||
tplDir := "templates" | ||
if setting.Page.UseCustomTpl { | ||
tplDir = "custom/templates" | ||
} | ||
m.Use(pongo2.Pongoer(pongo2.Options{ | ||
Directory: tplDir, | ||
})) | ||
m.Use(middleware.Contexter()) | ||
|
||
m.Get("/", routers.Home) | ||
m.Get("/docs", routers.Docs) | ||
m.Get("/docs/images/*", routers.DocsStatic) | ||
m.Get("/docs/*", routers.Docs) | ||
m.Post("/hook", routers.Hook) | ||
m.Get("/search", routers.Search) | ||
m.Get("/*", routers.Pages) | ||
|
||
m.NotFound(routers.NotFound) | ||
|
||
listenAddr := fmt.Sprintf("0.0.0.0:%d", setting.HTTPPort) | ||
log.Info("%s Listen on %s", setting.Site.Name, listenAddr) | ||
log.Fatal("Fail to start Peach: %v", http.ListenAndServe(listenAddr, m)) | ||
} |
Oops, something went wrong.