annotate zs.go @ 32:75822e38c3e0 draft

removed funcs, ext and utils
author zaitsev.serge
date Wed, 02 Sep 2015 15:00:14 +0000
parents b2f491299cee
children e3c902a7380d
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
0
45a9e1fac18e initial commit
zaitsev.serge
parents:
diff changeset
1 package main
45a9e1fac18e initial commit
zaitsev.serge
parents:
diff changeset
2
45a9e1fac18e initial commit
zaitsev.serge
parents:
diff changeset
3 import (
45a9e1fac18e initial commit
zaitsev.serge
parents:
diff changeset
4 "bytes"
45a9e1fac18e initial commit
zaitsev.serge
parents:
diff changeset
5 "fmt"
45a9e1fac18e initial commit
zaitsev.serge
parents:
diff changeset
6 "io"
45a9e1fac18e initial commit
zaitsev.serge
parents:
diff changeset
7 "io/ioutil"
45a9e1fac18e initial commit
zaitsev.serge
parents:
diff changeset
8 "log"
45a9e1fac18e initial commit
zaitsev.serge
parents:
diff changeset
9 "os"
32
75822e38c3e0 removed funcs, ext and utils
zaitsev.serge
parents: 31
diff changeset
10 "os/exec"
0
45a9e1fac18e initial commit
zaitsev.serge
parents:
diff changeset
11 "path"
45a9e1fac18e initial commit
zaitsev.serge
parents:
diff changeset
12 "path/filepath"
45a9e1fac18e initial commit
zaitsev.serge
parents:
diff changeset
13 "strings"
18
ae3116ea938b started migration to go templates
zaitsev.serge
parents: 17
diff changeset
14 "text/template"
0
45a9e1fac18e initial commit
zaitsev.serge
parents:
diff changeset
15 "time"
45a9e1fac18e initial commit
zaitsev.serge
parents:
diff changeset
16
22
f5627d4212a3 restored the original amber since my issue has been fixed
zaitsev.serge
parents: 20
diff changeset
17 "github.com/eknkc/amber"
0
45a9e1fac18e initial commit
zaitsev.serge
parents:
diff changeset
18 "github.com/russross/blackfriday"
17
0214b1b5f5eb added amber and gcss compilers
zaitsev.serge
parents: 15
diff changeset
19 "github.com/yosssi/gcss"
0
45a9e1fac18e initial commit
zaitsev.serge
parents:
diff changeset
20 )
45a9e1fac18e initial commit
zaitsev.serge
parents:
diff changeset
21
45a9e1fac18e initial commit
zaitsev.serge
parents:
diff changeset
22 const (
45a9e1fac18e initial commit
zaitsev.serge
parents:
diff changeset
23 ZSDIR = ".zs"
45a9e1fac18e initial commit
zaitsev.serge
parents:
diff changeset
24 PUBDIR = ".pub"
45a9e1fac18e initial commit
zaitsev.serge
parents:
diff changeset
25 )
45a9e1fac18e initial commit
zaitsev.serge
parents:
diff changeset
26
17
0214b1b5f5eb added amber and gcss compilers
zaitsev.serge
parents: 15
diff changeset
27 type Vars map[string]string
32
75822e38c3e0 removed funcs, ext and utils
zaitsev.serge
parents: 31
diff changeset
28
75822e38c3e0 removed funcs, ext and utils
zaitsev.serge
parents: 31
diff changeset
29 func renameExt(path, from, to string) string {
75822e38c3e0 removed funcs, ext and utils
zaitsev.serge
parents: 31
diff changeset
30 if from == "" {
75822e38c3e0 removed funcs, ext and utils
zaitsev.serge
parents: 31
diff changeset
31 from = filepath.Ext(path)
75822e38c3e0 removed funcs, ext and utils
zaitsev.serge
parents: 31
diff changeset
32 }
75822e38c3e0 removed funcs, ext and utils
zaitsev.serge
parents: 31
diff changeset
33 if strings.HasSuffix(path, from) {
75822e38c3e0 removed funcs, ext and utils
zaitsev.serge
parents: 31
diff changeset
34 return strings.TrimSuffix(path, from) + to
75822e38c3e0 removed funcs, ext and utils
zaitsev.serge
parents: 31
diff changeset
35 } else {
75822e38c3e0 removed funcs, ext and utils
zaitsev.serge
parents: 31
diff changeset
36 return path
75822e38c3e0 removed funcs, ext and utils
zaitsev.serge
parents: 31
diff changeset
37 }
75822e38c3e0 removed funcs, ext and utils
zaitsev.serge
parents: 31
diff changeset
38 }
75822e38c3e0 removed funcs, ext and utils
zaitsev.serge
parents: 31
diff changeset
39
75822e38c3e0 removed funcs, ext and utils
zaitsev.serge
parents: 31
diff changeset
40 func globals() Vars {
75822e38c3e0 removed funcs, ext and utils
zaitsev.serge
parents: 31
diff changeset
41 vars := Vars{}
75822e38c3e0 removed funcs, ext and utils
zaitsev.serge
parents: 31
diff changeset
42 for _, e := range os.Environ() {
75822e38c3e0 removed funcs, ext and utils
zaitsev.serge
parents: 31
diff changeset
43 pair := strings.Split(e, "=")
75822e38c3e0 removed funcs, ext and utils
zaitsev.serge
parents: 31
diff changeset
44 if strings.HasPrefix(pair[0], "ZS_") {
75822e38c3e0 removed funcs, ext and utils
zaitsev.serge
parents: 31
diff changeset
45 vars[strings.ToLower(pair[0][3:])] = pair[1]
75822e38c3e0 removed funcs, ext and utils
zaitsev.serge
parents: 31
diff changeset
46 }
75822e38c3e0 removed funcs, ext and utils
zaitsev.serge
parents: 31
diff changeset
47 }
75822e38c3e0 removed funcs, ext and utils
zaitsev.serge
parents: 31
diff changeset
48 return vars
75822e38c3e0 removed funcs, ext and utils
zaitsev.serge
parents: 31
diff changeset
49 }
75822e38c3e0 removed funcs, ext and utils
zaitsev.serge
parents: 31
diff changeset
50
75822e38c3e0 removed funcs, ext and utils
zaitsev.serge
parents: 31
diff changeset
51 // Converts zs markdown variables into environment variables
75822e38c3e0 removed funcs, ext and utils
zaitsev.serge
parents: 31
diff changeset
52 func env(vars Vars) []string {
75822e38c3e0 removed funcs, ext and utils
zaitsev.serge
parents: 31
diff changeset
53 env := []string{"ZS=" + os.Args[0], "ZS_OUTDIR=" + PUBDIR}
75822e38c3e0 removed funcs, ext and utils
zaitsev.serge
parents: 31
diff changeset
54 env = append(env, os.Environ()...)
75822e38c3e0 removed funcs, ext and utils
zaitsev.serge
parents: 31
diff changeset
55 if vars != nil {
75822e38c3e0 removed funcs, ext and utils
zaitsev.serge
parents: 31
diff changeset
56 for k, v := range vars {
75822e38c3e0 removed funcs, ext and utils
zaitsev.serge
parents: 31
diff changeset
57 env = append(env, "ZS_"+strings.ToUpper(k)+"="+v)
75822e38c3e0 removed funcs, ext and utils
zaitsev.serge
parents: 31
diff changeset
58 }
75822e38c3e0 removed funcs, ext and utils
zaitsev.serge
parents: 31
diff changeset
59 }
75822e38c3e0 removed funcs, ext and utils
zaitsev.serge
parents: 31
diff changeset
60 return env
75822e38c3e0 removed funcs, ext and utils
zaitsev.serge
parents: 31
diff changeset
61 }
75822e38c3e0 removed funcs, ext and utils
zaitsev.serge
parents: 31
diff changeset
62
75822e38c3e0 removed funcs, ext and utils
zaitsev.serge
parents: 31
diff changeset
63 // Runs command with given arguments and variables, intercepts stderr and
75822e38c3e0 removed funcs, ext and utils
zaitsev.serge
parents: 31
diff changeset
64 // redirects stdout into the given writer
75822e38c3e0 removed funcs, ext and utils
zaitsev.serge
parents: 31
diff changeset
65 func run(cmd string, args []string, vars Vars, output io.Writer) error {
75822e38c3e0 removed funcs, ext and utils
zaitsev.serge
parents: 31
diff changeset
66 var errbuf bytes.Buffer
75822e38c3e0 removed funcs, ext and utils
zaitsev.serge
parents: 31
diff changeset
67 c := exec.Command(cmd, args...)
75822e38c3e0 removed funcs, ext and utils
zaitsev.serge
parents: 31
diff changeset
68 c.Env = env(vars)
75822e38c3e0 removed funcs, ext and utils
zaitsev.serge
parents: 31
diff changeset
69 c.Stdout = output
75822e38c3e0 removed funcs, ext and utils
zaitsev.serge
parents: 31
diff changeset
70 c.Stderr = &errbuf
75822e38c3e0 removed funcs, ext and utils
zaitsev.serge
parents: 31
diff changeset
71
75822e38c3e0 removed funcs, ext and utils
zaitsev.serge
parents: 31
diff changeset
72 err := c.Run()
75822e38c3e0 removed funcs, ext and utils
zaitsev.serge
parents: 31
diff changeset
73
75822e38c3e0 removed funcs, ext and utils
zaitsev.serge
parents: 31
diff changeset
74 if errbuf.Len() > 0 {
75822e38c3e0 removed funcs, ext and utils
zaitsev.serge
parents: 31
diff changeset
75 log.Println("ERROR:", errbuf.String())
75822e38c3e0 removed funcs, ext and utils
zaitsev.serge
parents: 31
diff changeset
76 }
75822e38c3e0 removed funcs, ext and utils
zaitsev.serge
parents: 31
diff changeset
77
75822e38c3e0 removed funcs, ext and utils
zaitsev.serge
parents: 31
diff changeset
78 if err != nil {
75822e38c3e0 removed funcs, ext and utils
zaitsev.serge
parents: 31
diff changeset
79 return err
75822e38c3e0 removed funcs, ext and utils
zaitsev.serge
parents: 31
diff changeset
80 }
75822e38c3e0 removed funcs, ext and utils
zaitsev.serge
parents: 31
diff changeset
81 return nil
75822e38c3e0 removed funcs, ext and utils
zaitsev.serge
parents: 31
diff changeset
82 }
75822e38c3e0 removed funcs, ext and utils
zaitsev.serge
parents: 31
diff changeset
83
75822e38c3e0 removed funcs, ext and utils
zaitsev.serge
parents: 31
diff changeset
84 // Splits a string in exactly two parts by delimiter
75822e38c3e0 removed funcs, ext and utils
zaitsev.serge
parents: 31
diff changeset
85 // If no delimiter is found - the second string is be empty
75822e38c3e0 removed funcs, ext and utils
zaitsev.serge
parents: 31
diff changeset
86 func split2(s, delim string) (string, string) {
75822e38c3e0 removed funcs, ext and utils
zaitsev.serge
parents: 31
diff changeset
87 parts := strings.SplitN(s, delim, 2)
75822e38c3e0 removed funcs, ext and utils
zaitsev.serge
parents: 31
diff changeset
88 if len(parts) == 2 {
75822e38c3e0 removed funcs, ext and utils
zaitsev.serge
parents: 31
diff changeset
89 return parts[0], parts[1]
75822e38c3e0 removed funcs, ext and utils
zaitsev.serge
parents: 31
diff changeset
90 } else {
75822e38c3e0 removed funcs, ext and utils
zaitsev.serge
parents: 31
diff changeset
91 return parts[0], ""
75822e38c3e0 removed funcs, ext and utils
zaitsev.serge
parents: 31
diff changeset
92 }
75822e38c3e0 removed funcs, ext and utils
zaitsev.serge
parents: 31
diff changeset
93 }
0
45a9e1fac18e initial commit
zaitsev.serge
parents:
diff changeset
94
17
0214b1b5f5eb added amber and gcss compilers
zaitsev.serge
parents: 15
diff changeset
95 // Parses markdown content. Returns parsed header variables and content
19
802b96e67bae added global variables, added default date for markdown
zaitsev.serge
parents: 18
diff changeset
96 func md(path string, globals Vars) (Vars, string, error) {
17
0214b1b5f5eb added amber and gcss compilers
zaitsev.serge
parents: 15
diff changeset
97 b, err := ioutil.ReadFile(path)
0214b1b5f5eb added amber and gcss compilers
zaitsev.serge
parents: 15
diff changeset
98 if err != nil {
0214b1b5f5eb added amber and gcss compilers
zaitsev.serge
parents: 15
diff changeset
99 return nil, "", err
0214b1b5f5eb added amber and gcss compilers
zaitsev.serge
parents: 15
diff changeset
100 }
0214b1b5f5eb added amber and gcss compilers
zaitsev.serge
parents: 15
diff changeset
101 s := string(b)
6
cb66f5b86616 rewritted default variables assignment
zaitsev.serge
parents: 5
diff changeset
102 url := path[:len(path)-len(filepath.Ext(path))] + ".html"
17
0214b1b5f5eb added amber and gcss compilers
zaitsev.serge
parents: 15
diff changeset
103 v := Vars{
28
5ee89d094279 removed default date value, added some default title/description/keywords for markdown
zaitsev.serge
parents: 27
diff changeset
104 "title": "",
5ee89d094279 removed default date value, added some default title/description/keywords for markdown
zaitsev.serge
parents: 27
diff changeset
105 "description": "",
5ee89d094279 removed default date value, added some default title/description/keywords for markdown
zaitsev.serge
parents: 27
diff changeset
106 "keywords": "",
29
dd669a7e582f file, url and output should not be overridden by globals
zaitsev.serge
parents: 28
diff changeset
107 }
dd669a7e582f file, url and output should not be overridden by globals
zaitsev.serge
parents: 28
diff changeset
108 for name, value := range globals {
dd669a7e582f file, url and output should not be overridden by globals
zaitsev.serge
parents: 28
diff changeset
109 v[name] = value
6
cb66f5b86616 rewritted default variables assignment
zaitsev.serge
parents: 5
diff changeset
110 }
20
f8373c23a3ff replaced amber with my own fork, fixed file paths for amber and html
zaitsev.serge
parents: 19
diff changeset
111 if _, err := os.Stat(filepath.Join(ZSDIR, "layout.amber")); err == nil {
f8373c23a3ff replaced amber with my own fork, fixed file paths for amber and html
zaitsev.serge
parents: 19
diff changeset
112 v["layout"] = "layout.amber"
f8373c23a3ff replaced amber with my own fork, fixed file paths for amber and html
zaitsev.serge
parents: 19
diff changeset
113 } else {
f8373c23a3ff replaced amber with my own fork, fixed file paths for amber and html
zaitsev.serge
parents: 19
diff changeset
114 v["layout"] = "layout.html"
f8373c23a3ff replaced amber with my own fork, fixed file paths for amber and html
zaitsev.serge
parents: 19
diff changeset
115 }
29
dd669a7e582f file, url and output should not be overridden by globals
zaitsev.serge
parents: 28
diff changeset
116 v["file"] = path
dd669a7e582f file, url and output should not be overridden by globals
zaitsev.serge
parents: 28
diff changeset
117 v["url"] = url
dd669a7e582f file, url and output should not be overridden by globals
zaitsev.serge
parents: 28
diff changeset
118 v["output"] = filepath.Join(PUBDIR, url)
20
f8373c23a3ff replaced amber with my own fork, fixed file paths for amber and html
zaitsev.serge
parents: 19
diff changeset
119
2
fd79b3a90bef fixed empty header in markdown
zaitsev.serge
parents: 0
diff changeset
120 if strings.Index(s, "\n\n") == -1 {
19
802b96e67bae added global variables, added default date for markdown
zaitsev.serge
parents: 18
diff changeset
121 return v, s, nil
2
fd79b3a90bef fixed empty header in markdown
zaitsev.serge
parents: 0
diff changeset
122 }
0
45a9e1fac18e initial commit
zaitsev.serge
parents:
diff changeset
123 header, body := split2(s, "\n\n")
45a9e1fac18e initial commit
zaitsev.serge
parents:
diff changeset
124 for _, line := range strings.Split(header, "\n") {
45a9e1fac18e initial commit
zaitsev.serge
parents:
diff changeset
125 key, value := split2(line, ":")
45a9e1fac18e initial commit
zaitsev.serge
parents:
diff changeset
126 v[strings.ToLower(strings.TrimSpace(key))] = strings.TrimSpace(value)
45a9e1fac18e initial commit
zaitsev.serge
parents:
diff changeset
127 }
6
cb66f5b86616 rewritted default variables assignment
zaitsev.serge
parents: 5
diff changeset
128 if strings.HasPrefix(v["url"], "./") {
cb66f5b86616 rewritted default variables assignment
zaitsev.serge
parents: 5
diff changeset
129 v["url"] = v["url"][2:]
cb66f5b86616 rewritted default variables assignment
zaitsev.serge
parents: 5
diff changeset
130 }
17
0214b1b5f5eb added amber and gcss compilers
zaitsev.serge
parents: 15
diff changeset
131 return v, body, nil
0
45a9e1fac18e initial commit
zaitsev.serge
parents:
diff changeset
132 }
45a9e1fac18e initial commit
zaitsev.serge
parents:
diff changeset
133
18
ae3116ea938b started migration to go templates
zaitsev.serge
parents: 17
diff changeset
134 // Use standard Go templates
32
75822e38c3e0 removed funcs, ext and utils
zaitsev.serge
parents: 31
diff changeset
135 func render(s string, vars Vars) (string, error) {
75822e38c3e0 removed funcs, ext and utils
zaitsev.serge
parents: 31
diff changeset
136 tmpl, err := template.New("").Parse(s)
18
ae3116ea938b started migration to go templates
zaitsev.serge
parents: 17
diff changeset
137 if err != nil {
ae3116ea938b started migration to go templates
zaitsev.serge
parents: 17
diff changeset
138 return "", err
ae3116ea938b started migration to go templates
zaitsev.serge
parents: 17
diff changeset
139 }
ae3116ea938b started migration to go templates
zaitsev.serge
parents: 17
diff changeset
140 out := &bytes.Buffer{}
ae3116ea938b started migration to go templates
zaitsev.serge
parents: 17
diff changeset
141 if err := tmpl.Execute(out, vars); err != nil {
ae3116ea938b started migration to go templates
zaitsev.serge
parents: 17
diff changeset
142 return "", err
ae3116ea938b started migration to go templates
zaitsev.serge
parents: 17
diff changeset
143 }
ae3116ea938b started migration to go templates
zaitsev.serge
parents: 17
diff changeset
144 return string(out.Bytes()), nil
0
45a9e1fac18e initial commit
zaitsev.serge
parents:
diff changeset
145 }
45a9e1fac18e initial commit
zaitsev.serge
parents:
diff changeset
146
18
ae3116ea938b started migration to go templates
zaitsev.serge
parents: 17
diff changeset
147 // Renders markdown with the given layout into html expanding all the macros
32
75822e38c3e0 removed funcs, ext and utils
zaitsev.serge
parents: 31
diff changeset
148 func buildMarkdown(path string, w io.Writer, vars Vars) error {
19
802b96e67bae added global variables, added default date for markdown
zaitsev.serge
parents: 18
diff changeset
149 v, body, err := md(path, vars)
0
45a9e1fac18e initial commit
zaitsev.serge
parents:
diff changeset
150 if err != nil {
45a9e1fac18e initial commit
zaitsev.serge
parents:
diff changeset
151 return err
45a9e1fac18e initial commit
zaitsev.serge
parents:
diff changeset
152 }
32
75822e38c3e0 removed funcs, ext and utils
zaitsev.serge
parents: 31
diff changeset
153 content, err := render(body, v)
0
45a9e1fac18e initial commit
zaitsev.serge
parents:
diff changeset
154 if err != nil {
45a9e1fac18e initial commit
zaitsev.serge
parents:
diff changeset
155 return err
45a9e1fac18e initial commit
zaitsev.serge
parents:
diff changeset
156 }
31
b2f491299cee dead end with template functions
zaitsev.serge
parents: 30
diff changeset
157 v["content"] = string(blackfriday.MarkdownCommon([]byte(content)))
23
40f55059fbfa fixed output file names in html pages, fixed amber function bindings, replaced print command with build, fixed plugin functions, implemented zs and exec functions
zaitsev.serge
parents: 22
diff changeset
158 if w == nil {
40f55059fbfa fixed output file names in html pages, fixed amber function bindings, replaced print command with build, fixed plugin functions, implemented zs and exec functions
zaitsev.serge
parents: 22
diff changeset
159 out, err := os.Create(filepath.Join(PUBDIR, renameExt(path, "", ".html")))
40f55059fbfa fixed output file names in html pages, fixed amber function bindings, replaced print command with build, fixed plugin functions, implemented zs and exec functions
zaitsev.serge
parents: 22
diff changeset
160 if err != nil {
40f55059fbfa fixed output file names in html pages, fixed amber function bindings, replaced print command with build, fixed plugin functions, implemented zs and exec functions
zaitsev.serge
parents: 22
diff changeset
161 return err
40f55059fbfa fixed output file names in html pages, fixed amber function bindings, replaced print command with build, fixed plugin functions, implemented zs and exec functions
zaitsev.serge
parents: 22
diff changeset
162 }
40f55059fbfa fixed output file names in html pages, fixed amber function bindings, replaced print command with build, fixed plugin functions, implemented zs and exec functions
zaitsev.serge
parents: 22
diff changeset
163 defer out.Close()
40f55059fbfa fixed output file names in html pages, fixed amber function bindings, replaced print command with build, fixed plugin functions, implemented zs and exec functions
zaitsev.serge
parents: 22
diff changeset
164 w = out
40f55059fbfa fixed output file names in html pages, fixed amber function bindings, replaced print command with build, fixed plugin functions, implemented zs and exec functions
zaitsev.serge
parents: 22
diff changeset
165 }
18
ae3116ea938b started migration to go templates
zaitsev.serge
parents: 17
diff changeset
166 if strings.HasSuffix(v["layout"], ".amber") {
32
75822e38c3e0 removed funcs, ext and utils
zaitsev.serge
parents: 31
diff changeset
167 return buildAmber(filepath.Join(ZSDIR, v["layout"]), w, v)
18
ae3116ea938b started migration to go templates
zaitsev.serge
parents: 17
diff changeset
168 } else {
32
75822e38c3e0 removed funcs, ext and utils
zaitsev.serge
parents: 31
diff changeset
169 return buildHTML(filepath.Join(ZSDIR, v["layout"]), w, v)
18
ae3116ea938b started migration to go templates
zaitsev.serge
parents: 17
diff changeset
170 }
14
515078352442 moved html rendering into a separate function
zaitsev.serge
parents: 13
diff changeset
171 }
515078352442 moved html rendering into a separate function
zaitsev.serge
parents: 13
diff changeset
172
18
ae3116ea938b started migration to go templates
zaitsev.serge
parents: 17
diff changeset
173 // Renders text file expanding all variable macros inside it
32
75822e38c3e0 removed funcs, ext and utils
zaitsev.serge
parents: 31
diff changeset
174 func buildHTML(path string, w io.Writer, vars Vars) error {
23
40f55059fbfa fixed output file names in html pages, fixed amber function bindings, replaced print command with build, fixed plugin functions, implemented zs and exec functions
zaitsev.serge
parents: 22
diff changeset
175 b, err := ioutil.ReadFile(path)
0
45a9e1fac18e initial commit
zaitsev.serge
parents:
diff changeset
176 if err != nil {
45a9e1fac18e initial commit
zaitsev.serge
parents:
diff changeset
177 return err
45a9e1fac18e initial commit
zaitsev.serge
parents:
diff changeset
178 }
32
75822e38c3e0 removed funcs, ext and utils
zaitsev.serge
parents: 31
diff changeset
179 content, err := render(string(b), vars)
0
45a9e1fac18e initial commit
zaitsev.serge
parents:
diff changeset
180 if err != nil {
45a9e1fac18e initial commit
zaitsev.serge
parents:
diff changeset
181 return err
45a9e1fac18e initial commit
zaitsev.serge
parents:
diff changeset
182 }
24
d052f3a44195 fixed output file names in html pages, fixed amber function bindings, replaced print command with build, fixed plugin functions, implemented zs and exec functions
zaitsev.serge
parents: 23
diff changeset
183 if w == nil {
d052f3a44195 fixed output file names in html pages, fixed amber function bindings, replaced print command with build, fixed plugin functions, implemented zs and exec functions
zaitsev.serge
parents: 23
diff changeset
184 f, err := os.Create(filepath.Join(PUBDIR, path))
d052f3a44195 fixed output file names in html pages, fixed amber function bindings, replaced print command with build, fixed plugin functions, implemented zs and exec functions
zaitsev.serge
parents: 23
diff changeset
185 if err != nil {
d052f3a44195 fixed output file names in html pages, fixed amber function bindings, replaced print command with build, fixed plugin functions, implemented zs and exec functions
zaitsev.serge
parents: 23
diff changeset
186 return err
d052f3a44195 fixed output file names in html pages, fixed amber function bindings, replaced print command with build, fixed plugin functions, implemented zs and exec functions
zaitsev.serge
parents: 23
diff changeset
187 }
d052f3a44195 fixed output file names in html pages, fixed amber function bindings, replaced print command with build, fixed plugin functions, implemented zs and exec functions
zaitsev.serge
parents: 23
diff changeset
188 defer f.Close()
d052f3a44195 fixed output file names in html pages, fixed amber function bindings, replaced print command with build, fixed plugin functions, implemented zs and exec functions
zaitsev.serge
parents: 23
diff changeset
189 w = f
14
515078352442 moved html rendering into a separate function
zaitsev.serge
parents: 13
diff changeset
190 }
24
d052f3a44195 fixed output file names in html pages, fixed amber function bindings, replaced print command with build, fixed plugin functions, implemented zs and exec functions
zaitsev.serge
parents: 23
diff changeset
191 _, err = io.WriteString(w, content)
d052f3a44195 fixed output file names in html pages, fixed amber function bindings, replaced print command with build, fixed plugin functions, implemented zs and exec functions
zaitsev.serge
parents: 23
diff changeset
192 return err
0
45a9e1fac18e initial commit
zaitsev.serge
parents:
diff changeset
193 }
45a9e1fac18e initial commit
zaitsev.serge
parents:
diff changeset
194
18
ae3116ea938b started migration to go templates
zaitsev.serge
parents: 17
diff changeset
195 // Renders .amber file into .html
32
75822e38c3e0 removed funcs, ext and utils
zaitsev.serge
parents: 31
diff changeset
196 func buildAmber(path string, w io.Writer, vars Vars) error {
17
0214b1b5f5eb added amber and gcss compilers
zaitsev.serge
parents: 15
diff changeset
197 a := amber.New()
23
40f55059fbfa fixed output file names in html pages, fixed amber function bindings, replaced print command with build, fixed plugin functions, implemented zs and exec functions
zaitsev.serge
parents: 22
diff changeset
198 err := a.ParseFile(path)
17
0214b1b5f5eb added amber and gcss compilers
zaitsev.serge
parents: 15
diff changeset
199 if err != nil {
0214b1b5f5eb added amber and gcss compilers
zaitsev.serge
parents: 15
diff changeset
200 return err
0214b1b5f5eb added amber and gcss compilers
zaitsev.serge
parents: 15
diff changeset
201 }
24
d052f3a44195 fixed output file names in html pages, fixed amber function bindings, replaced print command with build, fixed plugin functions, implemented zs and exec functions
zaitsev.serge
parents: 23
diff changeset
202
d052f3a44195 fixed output file names in html pages, fixed amber function bindings, replaced print command with build, fixed plugin functions, implemented zs and exec functions
zaitsev.serge
parents: 23
diff changeset
203 data := map[string]interface{}{}
d052f3a44195 fixed output file names in html pages, fixed amber function bindings, replaced print command with build, fixed plugin functions, implemented zs and exec functions
zaitsev.serge
parents: 23
diff changeset
204 for k, v := range vars {
d052f3a44195 fixed output file names in html pages, fixed amber function bindings, replaced print command with build, fixed plugin functions, implemented zs and exec functions
zaitsev.serge
parents: 23
diff changeset
205 data[k] = v
d052f3a44195 fixed output file names in html pages, fixed amber function bindings, replaced print command with build, fixed plugin functions, implemented zs and exec functions
zaitsev.serge
parents: 23
diff changeset
206 }
d052f3a44195 fixed output file names in html pages, fixed amber function bindings, replaced print command with build, fixed plugin functions, implemented zs and exec functions
zaitsev.serge
parents: 23
diff changeset
207
17
0214b1b5f5eb added amber and gcss compilers
zaitsev.serge
parents: 15
diff changeset
208 t, err := a.Compile()
0214b1b5f5eb added amber and gcss compilers
zaitsev.serge
parents: 15
diff changeset
209 if err != nil {
0214b1b5f5eb added amber and gcss compilers
zaitsev.serge
parents: 15
diff changeset
210 return err
0214b1b5f5eb added amber and gcss compilers
zaitsev.serge
parents: 15
diff changeset
211 }
23
40f55059fbfa fixed output file names in html pages, fixed amber function bindings, replaced print command with build, fixed plugin functions, implemented zs and exec functions
zaitsev.serge
parents: 22
diff changeset
212 if w == nil {
40f55059fbfa fixed output file names in html pages, fixed amber function bindings, replaced print command with build, fixed plugin functions, implemented zs and exec functions
zaitsev.serge
parents: 22
diff changeset
213 f, err := os.Create(filepath.Join(PUBDIR, renameExt(path, ".amber", ".html")))
40f55059fbfa fixed output file names in html pages, fixed amber function bindings, replaced print command with build, fixed plugin functions, implemented zs and exec functions
zaitsev.serge
parents: 22
diff changeset
214 if err != nil {
40f55059fbfa fixed output file names in html pages, fixed amber function bindings, replaced print command with build, fixed plugin functions, implemented zs and exec functions
zaitsev.serge
parents: 22
diff changeset
215 return err
40f55059fbfa fixed output file names in html pages, fixed amber function bindings, replaced print command with build, fixed plugin functions, implemented zs and exec functions
zaitsev.serge
parents: 22
diff changeset
216 }
40f55059fbfa fixed output file names in html pages, fixed amber function bindings, replaced print command with build, fixed plugin functions, implemented zs and exec functions
zaitsev.serge
parents: 22
diff changeset
217 defer f.Close()
40f55059fbfa fixed output file names in html pages, fixed amber function bindings, replaced print command with build, fixed plugin functions, implemented zs and exec functions
zaitsev.serge
parents: 22
diff changeset
218 w = f
17
0214b1b5f5eb added amber and gcss compilers
zaitsev.serge
parents: 15
diff changeset
219 }
24
d052f3a44195 fixed output file names in html pages, fixed amber function bindings, replaced print command with build, fixed plugin functions, implemented zs and exec functions
zaitsev.serge
parents: 23
diff changeset
220 return t.Execute(w, data)
17
0214b1b5f5eb added amber and gcss compilers
zaitsev.serge
parents: 15
diff changeset
221 }
0214b1b5f5eb added amber and gcss compilers
zaitsev.serge
parents: 15
diff changeset
222
18
ae3116ea938b started migration to go templates
zaitsev.serge
parents: 17
diff changeset
223 // Compiles .gcss into .css
23
40f55059fbfa fixed output file names in html pages, fixed amber function bindings, replaced print command with build, fixed plugin functions, implemented zs and exec functions
zaitsev.serge
parents: 22
diff changeset
224 func buildGCSS(path string, w io.Writer) error {
18
ae3116ea938b started migration to go templates
zaitsev.serge
parents: 17
diff changeset
225 f, err := os.Open(path)
ae3116ea938b started migration to go templates
zaitsev.serge
parents: 17
diff changeset
226 if err != nil {
ae3116ea938b started migration to go templates
zaitsev.serge
parents: 17
diff changeset
227 return err
ae3116ea938b started migration to go templates
zaitsev.serge
parents: 17
diff changeset
228 }
23
40f55059fbfa fixed output file names in html pages, fixed amber function bindings, replaced print command with build, fixed plugin functions, implemented zs and exec functions
zaitsev.serge
parents: 22
diff changeset
229 defer f.Close()
40f55059fbfa fixed output file names in html pages, fixed amber function bindings, replaced print command with build, fixed plugin functions, implemented zs and exec functions
zaitsev.serge
parents: 22
diff changeset
230
40f55059fbfa fixed output file names in html pages, fixed amber function bindings, replaced print command with build, fixed plugin functions, implemented zs and exec functions
zaitsev.serge
parents: 22
diff changeset
231 if w == nil {
40f55059fbfa fixed output file names in html pages, fixed amber function bindings, replaced print command with build, fixed plugin functions, implemented zs and exec functions
zaitsev.serge
parents: 22
diff changeset
232 s := strings.TrimSuffix(path, ".gcss") + ".css"
40f55059fbfa fixed output file names in html pages, fixed amber function bindings, replaced print command with build, fixed plugin functions, implemented zs and exec functions
zaitsev.serge
parents: 22
diff changeset
233 css, err := os.Create(filepath.Join(PUBDIR, s))
40f55059fbfa fixed output file names in html pages, fixed amber function bindings, replaced print command with build, fixed plugin functions, implemented zs and exec functions
zaitsev.serge
parents: 22
diff changeset
234 if err != nil {
40f55059fbfa fixed output file names in html pages, fixed amber function bindings, replaced print command with build, fixed plugin functions, implemented zs and exec functions
zaitsev.serge
parents: 22
diff changeset
235 return err
40f55059fbfa fixed output file names in html pages, fixed amber function bindings, replaced print command with build, fixed plugin functions, implemented zs and exec functions
zaitsev.serge
parents: 22
diff changeset
236 }
40f55059fbfa fixed output file names in html pages, fixed amber function bindings, replaced print command with build, fixed plugin functions, implemented zs and exec functions
zaitsev.serge
parents: 22
diff changeset
237 defer css.Close()
40f55059fbfa fixed output file names in html pages, fixed amber function bindings, replaced print command with build, fixed plugin functions, implemented zs and exec functions
zaitsev.serge
parents: 22
diff changeset
238 w = css
18
ae3116ea938b started migration to go templates
zaitsev.serge
parents: 17
diff changeset
239 }
23
40f55059fbfa fixed output file names in html pages, fixed amber function bindings, replaced print command with build, fixed plugin functions, implemented zs and exec functions
zaitsev.serge
parents: 22
diff changeset
240 _, err = gcss.Compile(w, f)
18
ae3116ea938b started migration to go templates
zaitsev.serge
parents: 17
diff changeset
241 return err
ae3116ea938b started migration to go templates
zaitsev.serge
parents: 17
diff changeset
242 }
ae3116ea938b started migration to go templates
zaitsev.serge
parents: 17
diff changeset
243
23
40f55059fbfa fixed output file names in html pages, fixed amber function bindings, replaced print command with build, fixed plugin functions, implemented zs and exec functions
zaitsev.serge
parents: 22
diff changeset
244 // Copies file as is from path to writer
40f55059fbfa fixed output file names in html pages, fixed amber function bindings, replaced print command with build, fixed plugin functions, implemented zs and exec functions
zaitsev.serge
parents: 22
diff changeset
245 func buildRaw(path string, w io.Writer) error {
40f55059fbfa fixed output file names in html pages, fixed amber function bindings, replaced print command with build, fixed plugin functions, implemented zs and exec functions
zaitsev.serge
parents: 22
diff changeset
246 in, err := os.Open(path)
40f55059fbfa fixed output file names in html pages, fixed amber function bindings, replaced print command with build, fixed plugin functions, implemented zs and exec functions
zaitsev.serge
parents: 22
diff changeset
247 if err != nil {
40f55059fbfa fixed output file names in html pages, fixed amber function bindings, replaced print command with build, fixed plugin functions, implemented zs and exec functions
zaitsev.serge
parents: 22
diff changeset
248 return err
40f55059fbfa fixed output file names in html pages, fixed amber function bindings, replaced print command with build, fixed plugin functions, implemented zs and exec functions
zaitsev.serge
parents: 22
diff changeset
249 }
40f55059fbfa fixed output file names in html pages, fixed amber function bindings, replaced print command with build, fixed plugin functions, implemented zs and exec functions
zaitsev.serge
parents: 22
diff changeset
250 defer in.Close()
40f55059fbfa fixed output file names in html pages, fixed amber function bindings, replaced print command with build, fixed plugin functions, implemented zs and exec functions
zaitsev.serge
parents: 22
diff changeset
251 if w == nil {
40f55059fbfa fixed output file names in html pages, fixed amber function bindings, replaced print command with build, fixed plugin functions, implemented zs and exec functions
zaitsev.serge
parents: 22
diff changeset
252 if out, err := os.Create(filepath.Join(PUBDIR, path)); err != nil {
40f55059fbfa fixed output file names in html pages, fixed amber function bindings, replaced print command with build, fixed plugin functions, implemented zs and exec functions
zaitsev.serge
parents: 22
diff changeset
253 return err
40f55059fbfa fixed output file names in html pages, fixed amber function bindings, replaced print command with build, fixed plugin functions, implemented zs and exec functions
zaitsev.serge
parents: 22
diff changeset
254 } else {
0
45a9e1fac18e initial commit
zaitsev.serge
parents:
diff changeset
255 defer out.Close()
23
40f55059fbfa fixed output file names in html pages, fixed amber function bindings, replaced print command with build, fixed plugin functions, implemented zs and exec functions
zaitsev.serge
parents: 22
diff changeset
256 w = out
0
45a9e1fac18e initial commit
zaitsev.serge
parents:
diff changeset
257 }
45a9e1fac18e initial commit
zaitsev.serge
parents:
diff changeset
258 }
23
40f55059fbfa fixed output file names in html pages, fixed amber function bindings, replaced print command with build, fixed plugin functions, implemented zs and exec functions
zaitsev.serge
parents: 22
diff changeset
259 _, err = io.Copy(w, in)
7
11073a30f71f simplified build process, added pre and post build hooks
zaitsev.serge
parents: 6
diff changeset
260 return err
0
45a9e1fac18e initial commit
zaitsev.serge
parents:
diff changeset
261 }
45a9e1fac18e initial commit
zaitsev.serge
parents:
diff changeset
262
32
75822e38c3e0 removed funcs, ext and utils
zaitsev.serge
parents: 31
diff changeset
263 func build(path string, w io.Writer, vars Vars) error {
23
40f55059fbfa fixed output file names in html pages, fixed amber function bindings, replaced print command with build, fixed plugin functions, implemented zs and exec functions
zaitsev.serge
parents: 22
diff changeset
264 ext := filepath.Ext(path)
40f55059fbfa fixed output file names in html pages, fixed amber function bindings, replaced print command with build, fixed plugin functions, implemented zs and exec functions
zaitsev.serge
parents: 22
diff changeset
265 if ext == ".md" || ext == ".mkd" {
32
75822e38c3e0 removed funcs, ext and utils
zaitsev.serge
parents: 31
diff changeset
266 return buildMarkdown(path, w, vars)
23
40f55059fbfa fixed output file names in html pages, fixed amber function bindings, replaced print command with build, fixed plugin functions, implemented zs and exec functions
zaitsev.serge
parents: 22
diff changeset
267 } else if ext == ".html" || ext == ".xml" {
32
75822e38c3e0 removed funcs, ext and utils
zaitsev.serge
parents: 31
diff changeset
268 return buildHTML(path, w, vars)
23
40f55059fbfa fixed output file names in html pages, fixed amber function bindings, replaced print command with build, fixed plugin functions, implemented zs and exec functions
zaitsev.serge
parents: 22
diff changeset
269 } else if ext == ".amber" {
32
75822e38c3e0 removed funcs, ext and utils
zaitsev.serge
parents: 31
diff changeset
270 return buildAmber(path, w, vars)
23
40f55059fbfa fixed output file names in html pages, fixed amber function bindings, replaced print command with build, fixed plugin functions, implemented zs and exec functions
zaitsev.serge
parents: 22
diff changeset
271 } else if ext == ".gcss" {
40f55059fbfa fixed output file names in html pages, fixed amber function bindings, replaced print command with build, fixed plugin functions, implemented zs and exec functions
zaitsev.serge
parents: 22
diff changeset
272 return buildGCSS(path, w)
40f55059fbfa fixed output file names in html pages, fixed amber function bindings, replaced print command with build, fixed plugin functions, implemented zs and exec functions
zaitsev.serge
parents: 22
diff changeset
273 } else {
40f55059fbfa fixed output file names in html pages, fixed amber function bindings, replaced print command with build, fixed plugin functions, implemented zs and exec functions
zaitsev.serge
parents: 22
diff changeset
274 return buildRaw(path, w)
18
ae3116ea938b started migration to go templates
zaitsev.serge
parents: 17
diff changeset
275 }
ae3116ea938b started migration to go templates
zaitsev.serge
parents: 17
diff changeset
276 }
ae3116ea938b started migration to go templates
zaitsev.serge
parents: 17
diff changeset
277
23
40f55059fbfa fixed output file names in html pages, fixed amber function bindings, replaced print command with build, fixed plugin functions, implemented zs and exec functions
zaitsev.serge
parents: 22
diff changeset
278 func buildAll(watch bool) {
0
45a9e1fac18e initial commit
zaitsev.serge
parents:
diff changeset
279 lastModified := time.Unix(0, 0)
7
11073a30f71f simplified build process, added pre and post build hooks
zaitsev.serge
parents: 6
diff changeset
280 modified := false
19
802b96e67bae added global variables, added default date for markdown
zaitsev.serge
parents: 18
diff changeset
281
802b96e67bae added global variables, added default date for markdown
zaitsev.serge
parents: 18
diff changeset
282 vars := globals()
0
45a9e1fac18e initial commit
zaitsev.serge
parents:
diff changeset
283 for {
45a9e1fac18e initial commit
zaitsev.serge
parents:
diff changeset
284 os.Mkdir(PUBDIR, 0755)
45a9e1fac18e initial commit
zaitsev.serge
parents:
diff changeset
285 err := filepath.Walk(".", func(path string, info os.FileInfo, err error) error {
45a9e1fac18e initial commit
zaitsev.serge
parents:
diff changeset
286 // ignore hidden files and directories
45a9e1fac18e initial commit
zaitsev.serge
parents:
diff changeset
287 if filepath.Base(path)[0] == '.' || strings.HasPrefix(path, ".") {
45a9e1fac18e initial commit
zaitsev.serge
parents:
diff changeset
288 return nil
45a9e1fac18e initial commit
zaitsev.serge
parents:
diff changeset
289 }
30
526ba3c717ba added check for fs walk errors
zaitsev.serge
parents: 29
diff changeset
290 // inform user about fs walk errors, but continue iteration
526ba3c717ba added check for fs walk errors
zaitsev.serge
parents: 29
diff changeset
291 if err != nil {
526ba3c717ba added check for fs walk errors
zaitsev.serge
parents: 29
diff changeset
292 log.Println("ERROR:", err)
526ba3c717ba added check for fs walk errors
zaitsev.serge
parents: 29
diff changeset
293 return nil
526ba3c717ba added check for fs walk errors
zaitsev.serge
parents: 29
diff changeset
294 }
0
45a9e1fac18e initial commit
zaitsev.serge
parents:
diff changeset
295
7
11073a30f71f simplified build process, added pre and post build hooks
zaitsev.serge
parents: 6
diff changeset
296 if info.IsDir() {
11073a30f71f simplified build process, added pre and post build hooks
zaitsev.serge
parents: 6
diff changeset
297 os.Mkdir(filepath.Join(PUBDIR, path), 0755)
11073a30f71f simplified build process, added pre and post build hooks
zaitsev.serge
parents: 6
diff changeset
298 return nil
11073a30f71f simplified build process, added pre and post build hooks
zaitsev.serge
parents: 6
diff changeset
299 } else if info.ModTime().After(lastModified) {
11073a30f71f simplified build process, added pre and post build hooks
zaitsev.serge
parents: 6
diff changeset
300 if !modified {
11073a30f71f simplified build process, added pre and post build hooks
zaitsev.serge
parents: 6
diff changeset
301 // About to be modified, so run pre-build hook
18
ae3116ea938b started migration to go templates
zaitsev.serge
parents: 17
diff changeset
302 // FIXME on windows it might not work well
7
11073a30f71f simplified build process, added pre and post build hooks
zaitsev.serge
parents: 6
diff changeset
303 run(filepath.Join(ZSDIR, "pre"), []string{}, nil, nil)
11073a30f71f simplified build process, added pre and post build hooks
zaitsev.serge
parents: 6
diff changeset
304 modified = true
11073a30f71f simplified build process, added pre and post build hooks
zaitsev.serge
parents: 6
diff changeset
305 }
23
40f55059fbfa fixed output file names in html pages, fixed amber function bindings, replaced print command with build, fixed plugin functions, implemented zs and exec functions
zaitsev.serge
parents: 22
diff changeset
306 log.Println("build: ", path)
32
75822e38c3e0 removed funcs, ext and utils
zaitsev.serge
parents: 31
diff changeset
307 return build(path, nil, vars)
0
45a9e1fac18e initial commit
zaitsev.serge
parents:
diff changeset
308 }
45a9e1fac18e initial commit
zaitsev.serge
parents:
diff changeset
309 return nil
45a9e1fac18e initial commit
zaitsev.serge
parents:
diff changeset
310 })
45a9e1fac18e initial commit
zaitsev.serge
parents:
diff changeset
311 if err != nil {
45a9e1fac18e initial commit
zaitsev.serge
parents:
diff changeset
312 log.Println("ERROR:", err)
45a9e1fac18e initial commit
zaitsev.serge
parents:
diff changeset
313 }
7
11073a30f71f simplified build process, added pre and post build hooks
zaitsev.serge
parents: 6
diff changeset
314 if modified {
11073a30f71f simplified build process, added pre and post build hooks
zaitsev.serge
parents: 6
diff changeset
315 // Something was modified, so post-build hook
18
ae3116ea938b started migration to go templates
zaitsev.serge
parents: 17
diff changeset
316 // FIXME on windows it might not work well
7
11073a30f71f simplified build process, added pre and post build hooks
zaitsev.serge
parents: 6
diff changeset
317 run(filepath.Join(ZSDIR, "post"), []string{}, nil, nil)
11073a30f71f simplified build process, added pre and post build hooks
zaitsev.serge
parents: 6
diff changeset
318 modified = false
11073a30f71f simplified build process, added pre and post build hooks
zaitsev.serge
parents: 6
diff changeset
319 }
23
40f55059fbfa fixed output file names in html pages, fixed amber function bindings, replaced print command with build, fixed plugin functions, implemented zs and exec functions
zaitsev.serge
parents: 22
diff changeset
320 if !watch {
0
45a9e1fac18e initial commit
zaitsev.serge
parents:
diff changeset
321 break
45a9e1fac18e initial commit
zaitsev.serge
parents:
diff changeset
322 }
23
40f55059fbfa fixed output file names in html pages, fixed amber function bindings, replaced print command with build, fixed plugin functions, implemented zs and exec functions
zaitsev.serge
parents: 22
diff changeset
323 lastModified = time.Now()
0
45a9e1fac18e initial commit
zaitsev.serge
parents:
diff changeset
324 time.Sleep(1 * time.Second)
45a9e1fac18e initial commit
zaitsev.serge
parents:
diff changeset
325 }
45a9e1fac18e initial commit
zaitsev.serge
parents:
diff changeset
326 }
45a9e1fac18e initial commit
zaitsev.serge
parents:
diff changeset
327
45a9e1fac18e initial commit
zaitsev.serge
parents:
diff changeset
328 func main() {
45a9e1fac18e initial commit
zaitsev.serge
parents:
diff changeset
329 if len(os.Args) == 1 {
45a9e1fac18e initial commit
zaitsev.serge
parents:
diff changeset
330 fmt.Println(os.Args[0], "<command> [args]")
45a9e1fac18e initial commit
zaitsev.serge
parents:
diff changeset
331 return
45a9e1fac18e initial commit
zaitsev.serge
parents:
diff changeset
332 }
45a9e1fac18e initial commit
zaitsev.serge
parents:
diff changeset
333 cmd := os.Args[1]
45a9e1fac18e initial commit
zaitsev.serge
parents:
diff changeset
334 args := os.Args[2:]
45a9e1fac18e initial commit
zaitsev.serge
parents:
diff changeset
335 switch cmd {
45a9e1fac18e initial commit
zaitsev.serge
parents:
diff changeset
336 case "build":
24
d052f3a44195 fixed output file names in html pages, fixed amber function bindings, replaced print command with build, fixed plugin functions, implemented zs and exec functions
zaitsev.serge
parents: 23
diff changeset
337 if len(args) == 0 {
d052f3a44195 fixed output file names in html pages, fixed amber function bindings, replaced print command with build, fixed plugin functions, implemented zs and exec functions
zaitsev.serge
parents: 23
diff changeset
338 buildAll(false)
d052f3a44195 fixed output file names in html pages, fixed amber function bindings, replaced print command with build, fixed plugin functions, implemented zs and exec functions
zaitsev.serge
parents: 23
diff changeset
339 } else if len(args) == 1 {
32
75822e38c3e0 removed funcs, ext and utils
zaitsev.serge
parents: 31
diff changeset
340 if err := build(args[0], os.Stdout, globals()); err != nil {
24
d052f3a44195 fixed output file names in html pages, fixed amber function bindings, replaced print command with build, fixed plugin functions, implemented zs and exec functions
zaitsev.serge
parents: 23
diff changeset
341 fmt.Println("ERROR: " + err.Error())
d052f3a44195 fixed output file names in html pages, fixed amber function bindings, replaced print command with build, fixed plugin functions, implemented zs and exec functions
zaitsev.serge
parents: 23
diff changeset
342 }
d052f3a44195 fixed output file names in html pages, fixed amber function bindings, replaced print command with build, fixed plugin functions, implemented zs and exec functions
zaitsev.serge
parents: 23
diff changeset
343 } else {
d052f3a44195 fixed output file names in html pages, fixed amber function bindings, replaced print command with build, fixed plugin functions, implemented zs and exec functions
zaitsev.serge
parents: 23
diff changeset
344 fmt.Println("ERROR: too many arguments")
d052f3a44195 fixed output file names in html pages, fixed amber function bindings, replaced print command with build, fixed plugin functions, implemented zs and exec functions
zaitsev.serge
parents: 23
diff changeset
345 }
0
45a9e1fac18e initial commit
zaitsev.serge
parents:
diff changeset
346 case "watch":
23
40f55059fbfa fixed output file names in html pages, fixed amber function bindings, replaced print command with build, fixed plugin functions, implemented zs and exec functions
zaitsev.serge
parents: 22
diff changeset
347 buildAll(true)
40f55059fbfa fixed output file names in html pages, fixed amber function bindings, replaced print command with build, fixed plugin functions, implemented zs and exec functions
zaitsev.serge
parents: 22
diff changeset
348 case "var":
32
75822e38c3e0 removed funcs, ext and utils
zaitsev.serge
parents: 31
diff changeset
349 if len(args) == 0 {
75822e38c3e0 removed funcs, ext and utils
zaitsev.serge
parents: 31
diff changeset
350 fmt.Println("var: filename expected")
75822e38c3e0 removed funcs, ext and utils
zaitsev.serge
parents: 31
diff changeset
351 } else {
75822e38c3e0 removed funcs, ext and utils
zaitsev.serge
parents: 31
diff changeset
352 s := ""
75822e38c3e0 removed funcs, ext and utils
zaitsev.serge
parents: 31
diff changeset
353 if vars, _, err := md(args[0], globals()); err != nil {
75822e38c3e0 removed funcs, ext and utils
zaitsev.serge
parents: 31
diff changeset
354 fmt.Println("var: " + err.Error())
75822e38c3e0 removed funcs, ext and utils
zaitsev.serge
parents: 31
diff changeset
355 } else {
75822e38c3e0 removed funcs, ext and utils
zaitsev.serge
parents: 31
diff changeset
356 if len(args) > 1 {
75822e38c3e0 removed funcs, ext and utils
zaitsev.serge
parents: 31
diff changeset
357 for _, a := range args[1:] {
75822e38c3e0 removed funcs, ext and utils
zaitsev.serge
parents: 31
diff changeset
358 s = s + vars[a] + "\n"
75822e38c3e0 removed funcs, ext and utils
zaitsev.serge
parents: 31
diff changeset
359 }
75822e38c3e0 removed funcs, ext and utils
zaitsev.serge
parents: 31
diff changeset
360 } else {
75822e38c3e0 removed funcs, ext and utils
zaitsev.serge
parents: 31
diff changeset
361 for k, v := range vars {
75822e38c3e0 removed funcs, ext and utils
zaitsev.serge
parents: 31
diff changeset
362 s = s + k + ":" + v + "\n"
75822e38c3e0 removed funcs, ext and utils
zaitsev.serge
parents: 31
diff changeset
363 }
75822e38c3e0 removed funcs, ext and utils
zaitsev.serge
parents: 31
diff changeset
364 }
75822e38c3e0 removed funcs, ext and utils
zaitsev.serge
parents: 31
diff changeset
365 }
75822e38c3e0 removed funcs, ext and utils
zaitsev.serge
parents: 31
diff changeset
366 fmt.Println(strings.TrimSpace(s))
75822e38c3e0 removed funcs, ext and utils
zaitsev.serge
parents: 31
diff changeset
367 }
0
45a9e1fac18e initial commit
zaitsev.serge
parents:
diff changeset
368 default:
27
1254e8cb6e75 passing globals when running a plugin
zaitsev.serge
parents: 25
diff changeset
369 err := run(path.Join(ZSDIR, cmd), args, globals(), os.Stdout)
4
05fc24caac37 render uses strings, not bytes; added helpers for env and run
zaitsev.serge
parents: 3
diff changeset
370 if err != nil {
20
f8373c23a3ff replaced amber with my own fork, fixed file paths for amber and html
zaitsev.serge
parents: 19
diff changeset
371 log.Println("ERROR:", err)
0
45a9e1fac18e initial commit
zaitsev.serge
parents:
diff changeset
372 }
45a9e1fac18e initial commit
zaitsev.serge
parents:
diff changeset
373 }
45a9e1fac18e initial commit
zaitsev.serge
parents:
diff changeset
374 }