@@ -2,77 +2,33 @@ package web
22
33import (
44 "html/template"
5- "io/ioutil"
65 "net/http"
76 "strings"
87 "time"
98
109 "github.com/editor-bootstrap/vim-bootstrap/generate"
1110)
1211
13- const (
14- git = "git"
15- checkout = "checkout"
16- force = "-f"
17- pull = "pull"
18- submodule = "submodule"
19- update = "update"
20- remote = "--remote"
21- merge = "--merge"
22- add = "add"
23- tmpl = "template"
24- commit = "commit"
25- message = "-m \" update template \" "
26- push = "push"
27- origin = "origin"
28- master = "master"
29- )
30-
31- func listLangs () (list []string ) {
32- // List all languages on folder
33- files , _ := ioutil .ReadDir ("./vim_template/langs" )
34- for _ , f := range files {
35- list = append (list , f .Name ())
36- }
37- return
38- }
39-
40- func listFrameworks () (list []string ) {
41- // List all frameworks on folder
42- files , _ := ioutil .ReadDir ("./vim_template/frameworks" )
43- for _ , f := range files {
44- list = append (list , f .Name ())
45- }
46- return
47- }
48-
49- func listThemes () (list []string ) {
50- // List all themes on folder
51- files , _ := ioutil .ReadDir ("./vim_template/themes" )
52- for _ , f := range files {
53- list = append (list , f .Name ())
54- }
55- return
56- }
57-
5812// HashCommit returns timestamp
5913func HashCommit () string {
6014 t := time .Now ()
6115 // yearmonthdayhourminutesseconds
6216 return t .Format ("2006-01-02 15:04:05" )
6317}
6418
19+ // HandleHome is a handler to expose main page configurations
6520func HandleHome (w http.ResponseWriter , r * http.Request ) {
6621 Body := make (map [string ]interface {})
67- Body ["Langs" ] = listLangs ()
68- Body ["Frameworks" ] = listFrameworks ()
69- Body ["Themes" ] = listThemes ()
22+ Body ["Langs" ] = generate . ListLangs ()
23+ Body ["Frameworks" ] = generate . ListFrameworks ()
24+ Body ["Themes" ] = generate . ListThemes ()
7025 Body ["Version" ] = HashCommit ()
7126
7227 t := template .Must (template .ParseFiles ("./template/index.html" ))
7328 t .Execute (w , Body )
7429}
7530
31+ // HandleGenerate receives a post request with configurations and returns a config file.
7632func HandleGenerate (w http.ResponseWriter , r * http.Request ) {
7733 w .Header ().Set ("Content-Disposition" , "attachment; filename=generate.vim" )
7834 r .ParseForm ()
@@ -98,17 +54,17 @@ func HandleGenerate(w http.ResponseWriter, r *http.Request) {
9854
9955// HandleThemes is an endpoint to list availables frameworks
10056func HandleThemes (w http.ResponseWriter , r * http.Request ) {
101- handleList (w , listThemes )
57+ handleList (w , generate . ListThemes )
10258}
10359
10460// HandleFrameworks is an endpoint to list availables frameworks
10561func HandleFrameworks (w http.ResponseWriter , r * http.Request ) {
106- handleList (w , listFrameworks )
62+ handleList (w , generate . ListFrameworks )
10763}
10864
10965// HandleLangs is an endpoint to list availables frameworks
11066func HandleLangs (w http.ResponseWriter , r * http.Request ) {
111- handleList (w , listLangs )
67+ handleList (w , generate . ListLangs )
11268}
11369
11470func handleList (w http.ResponseWriter , function func () []string ) {
0 commit comments