Mercurial > yakumo_izuru > aya
changeset 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 |
files | zs.go zs_util.go |
diffstat | 2 files changed, 37 insertions(+), 21 deletions(-) [+] |
line wrap: on
line diff
--- a/zs.go Sun Aug 30 12:20:35 2015 +0000 +++ b/zs.go Sun Aug 30 12:22:00 2015 +0000 @@ -132,15 +132,16 @@ if err != nil { return err } - output := filepath.Join(PUBDIR, path) - if s, ok := vars["output"]; ok { - output = s + if w == nil { + f, err := os.Create(filepath.Join(PUBDIR, path)) + if err != nil { + return err + } + defer f.Close() + w = f } - err = ioutil.WriteFile(output, []byte(content), 0666) - if err != nil { - return err - } - return nil + _, err = io.WriteString(w, content) + return err } // Renders .amber file into .html @@ -150,6 +151,15 @@ if err != nil { return err } + + data := map[string]interface{}{} + for k, v := range vars { + data[k] = v + } + for k, v := range funcs { + data[k] = v + } + t, err := a.Compile() if err != nil { return err @@ -162,7 +172,7 @@ defer f.Close() w = f } - return t.Execute(w, vars) + return t.Execute(w, data) } // Compiles .gcss into .css @@ -275,15 +285,17 @@ args := os.Args[2:] switch cmd { case "build": - buildAll(false) + if len(args) == 0 { + buildAll(false) + } else if len(args) == 1 { + if err := build(args[0], os.Stdout, builtins(), globals()); err != nil { + fmt.Println("ERROR: " + err.Error()) + } + } else { + fmt.Println("ERROR: too many arguments") + } case "watch": buildAll(true) - case "print": - if len(args) != 1 { - fmt.Println("ERROR: filename expected") - } else { - build(args[0], os.Stdout, builtins(), globals()) - } case "var": fmt.Println(Var(args)) case "lorem":
--- a/zs_util.go Sun Aug 30 12:20:35 2015 +0000 +++ b/zs_util.go Sun Aug 30 12:22:00 2015 +0000 @@ -19,7 +19,7 @@ func pluginFunc(cmd string, vars Vars) func(args ...string) string { return func(args ...string) string { out := bytes.NewBuffer(nil) - if err := run(cmd, args, vars, out); err != nil { + if err := run(filepath.Join(ZSDIR, cmd), args, vars, out); err != nil { return cmd + ":" + err.Error() } else { return string(out.Bytes()) @@ -28,15 +28,19 @@ } func builtins() Funcs { - exec := func(s ...string) string { + exec := func(cmd string, args ...string) string { + out := bytes.NewBuffer(nil) + if err := run(cmd, args, Vars{}, out); err != nil { + return cmd + ":" + err.Error() + } else { + return string(out.Bytes()) + } return "" } return Funcs{ "exec": exec, "zs": func(args ...string) string { - cmd := []string{"zs"} - cmd = append(cmd, args...) - return exec(cmd...) + return exec(os.Args[0], args...) }, } }