Changeset 25 in code


Ignore:
Timestamp:
Aug 30, 2015, 12:22:00 PM (10 years ago)
Author:
zaitsev.serge
Message:

fixed output file names in html pages, fixed amber function bindings, replaced print command with build, fixed plugin functions, implemented zs and exec functions

Location:
trunk
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/zs.go

    r24 r25  
    133133                return err
    134134        }
    135         output := filepath.Join(PUBDIR, path)
    136         if s, ok := vars["output"]; ok {
    137                 output = s
    138         }
    139         err = ioutil.WriteFile(output, []byte(content), 0666)
    140         if err != nil {
    141                 return err
    142         }
    143         return nil
     135        if w == nil {
     136                f, err := os.Create(filepath.Join(PUBDIR, path))
     137                if err != nil {
     138                        return err
     139                }
     140                defer f.Close()
     141                w = f
     142        }
     143        _, err = io.WriteString(w, content)
     144        return err
    144145}
    145146
     
    151152                return err
    152153        }
     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
    153163        t, err := a.Compile()
    154164        if err != nil {
     
    163173                w = f
    164174        }
    165         return t.Execute(w, vars)
     175        return t.Execute(w, data)
    166176}
    167177
     
    276286        switch cmd {
    277287        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                }
    279297        case "watch":
    280298                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                 }
    287299        case "var":
    288300                fmt.Println(Var(args))
  • trunk/zs_util.go

    r24 r25  
    2020        return func(args ...string) string {
    2121                out := bytes.NewBuffer(nil)
    22                 if err := run(cmd, args, vars, out); err != nil {
     22                if err := run(filepath.Join(ZSDIR, cmd), args, vars, out); err != nil {
    2323                        return cmd + ":" + err.Error()
    2424                } else {
     
    2929
    3030func builtins() Funcs {
    31         exec := func(s ...string) string {
     31        exec := func(cmd string, args ...string) string {
     32                out := bytes.NewBuffer(nil)
     33                if err := run(cmd, args, Vars{}, out); err != nil {
     34                        return cmd + ":" + err.Error()
     35                } else {
     36                        return string(out.Bytes())
     37                }
    3238                return ""
    3339        }
     
    3541                "exec": exec,
    3642                "zs": func(args ...string) string {
    37                         cmd := []string{"zs"}
    38                         cmd = append(cmd, args...)
    39                         return exec(cmd...)
     43                        return exec(os.Args[0], args...)
    4044                },
    4145        }
Note: See TracChangeset for help on using the changeset viewer.