Mercurial > yakumo_izuru > aya
comparison zs.go @ 24:d052f3a44195 draft
fixed output file names in html pages, fixed amber function bindings, replaced print command with build, fixed plugin functions, implemented zs and exec functions
author | zaitsev.serge |
---|---|
date | Sun, 30 Aug 2015 12:22:00 +0000 |
parents | 40f55059fbfa |
children | 42b0a9fa5883 |
comparison
equal
deleted
inserted
replaced
23:40f55059fbfa | 24:d052f3a44195 |
---|---|
130 } | 130 } |
131 content, err := render(string(b), funcs, vars) | 131 content, err := render(string(b), funcs, vars) |
132 if err != nil { | 132 if err != nil { |
133 return err | 133 return err |
134 } | 134 } |
135 output := filepath.Join(PUBDIR, path) | 135 if w == nil { |
136 if s, ok := vars["output"]; ok { | 136 f, err := os.Create(filepath.Join(PUBDIR, path)) |
137 output = s | 137 if err != nil { |
138 } | 138 return err |
139 err = ioutil.WriteFile(output, []byte(content), 0666) | 139 } |
140 if err != nil { | 140 defer f.Close() |
141 return err | 141 w = f |
142 } | 142 } |
143 return nil | 143 _, err = io.WriteString(w, content) |
144 return err | |
144 } | 145 } |
145 | 146 |
146 // Renders .amber file into .html | 147 // Renders .amber file into .html |
147 func buildAmber(path string, w io.Writer, funcs Funcs, vars Vars) error { | 148 func buildAmber(path string, w io.Writer, funcs Funcs, vars Vars) error { |
148 a := amber.New() | 149 a := amber.New() |
149 err := a.ParseFile(path) | 150 err := a.ParseFile(path) |
150 if err != nil { | 151 if err != nil { |
151 return err | 152 return err |
152 } | 153 } |
154 | |
155 data := map[string]interface{}{} | |
156 for k, v := range vars { | |
157 data[k] = v | |
158 } | |
159 for k, v := range funcs { | |
160 data[k] = v | |
161 } | |
162 | |
153 t, err := a.Compile() | 163 t, err := a.Compile() |
154 if err != nil { | 164 if err != nil { |
155 return err | 165 return err |
156 } | 166 } |
157 if w == nil { | 167 if w == nil { |
160 return err | 170 return err |
161 } | 171 } |
162 defer f.Close() | 172 defer f.Close() |
163 w = f | 173 w = f |
164 } | 174 } |
165 return t.Execute(w, vars) | 175 return t.Execute(w, data) |
166 } | 176 } |
167 | 177 |
168 // Compiles .gcss into .css | 178 // Compiles .gcss into .css |
169 func buildGCSS(path string, w io.Writer) error { | 179 func buildGCSS(path string, w io.Writer) error { |
170 f, err := os.Open(path) | 180 f, err := os.Open(path) |
273 } | 283 } |
274 cmd := os.Args[1] | 284 cmd := os.Args[1] |
275 args := os.Args[2:] | 285 args := os.Args[2:] |
276 switch cmd { | 286 switch cmd { |
277 case "build": | 287 case "build": |
278 buildAll(false) | 288 if len(args) == 0 { |
289 buildAll(false) | |
290 } else if len(args) == 1 { | |
291 if err := build(args[0], os.Stdout, builtins(), globals()); err != nil { | |
292 fmt.Println("ERROR: " + err.Error()) | |
293 } | |
294 } else { | |
295 fmt.Println("ERROR: too many arguments") | |
296 } | |
279 case "watch": | 297 case "watch": |
280 buildAll(true) | 298 buildAll(true) |
281 case "print": | |
282 if len(args) != 1 { | |
283 fmt.Println("ERROR: filename expected") | |
284 } else { | |
285 build(args[0], os.Stdout, builtins(), globals()) | |
286 } | |
287 case "var": | 299 case "var": |
288 fmt.Println(Var(args)) | 300 fmt.Println(Var(args)) |
289 case "lorem": | 301 case "lorem": |
290 fmt.Println(Lorem(args)) | 302 fmt.Println(Lorem(args)) |
291 case "dateparse": | 303 case "dateparse": |