Skip to content

Commit 75c0ef7

Browse files
committed
fix: list files correctly and use new embed feature
1 parent 16b7d2a commit 75c0ef7

File tree

2 files changed

+36
-53
lines changed

2 files changed

+36
-53
lines changed

generate/generate.go

Lines changed: 28 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,34 @@ func buff(list []string, t string) (mList, mBundle map[string]string) {
6262
return
6363
}
6464

65-
// Generate ...
65+
// ListLangs on folder langs
66+
func ListLangs() (list []string) {
67+
files, _ := vimTemplate.ReadDir("vim_template/langs")
68+
for _, f := range files {
69+
list = append(list, f.Name())
70+
}
71+
return
72+
}
73+
74+
// ListFrameworks on folder frameworks
75+
func ListFrameworks() (list []string) {
76+
files, _ := vimTemplate.ReadDir("vim_template/frameworks")
77+
for _, f := range files {
78+
list = append(list, f.Name())
79+
}
80+
return
81+
}
82+
83+
// ListThemes on folder themes
84+
func ListThemes() (list []string) {
85+
files, _ := vimTemplate.ReadDir("vim_template/themes")
86+
for _, f := range files {
87+
list = append(list, f.Name())
88+
}
89+
return
90+
}
91+
92+
// Generate file from configurations
6693
func Generate(obj *Object) (buffer string) {
6794
// Clean VimBuffer, not append old result
6895
VimBuffer.Reset()

web/web.go

Lines changed: 8 additions & 52 deletions
Original file line numberDiff line numberDiff line change
@@ -2,77 +2,33 @@ package web
22

33
import (
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
5913
func 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
6520
func 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.
7632
func 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
10056
func 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
10561
func 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
11066
func HandleLangs(w http.ResponseWriter, r *http.Request) {
111-
handleList(w, listLangs)
67+
handleList(w, generate.ListLangs)
11268
}
11369

11470
func handleList(w http.ResponseWriter, function func() []string) {

0 commit comments

Comments
 (0)