func RawOutput(r *app.Request) error { if err := hooks.PreCompile(); err != nil { return err } if err := gss.Compile(); err != nil { return err } if err := soy.Compile(); err != nil { return err } _, namespaces, err := js.GenerateDeps("input-production") if err != nil { return err } log.Println("Output RAW mode") conf := config.Current() content := bytes.NewBuffer(nil) base := path.Join(conf.Library.Root, "closure", "goog", "base.js") if err := addFile(content, base); err != nil { return err } if err := addFile(content, path.Join(conf.Build, config.RENAMING_MAP_NAME)); err != nil { return err } if err := addFile(content, path.Join(conf.Build, config.DEPS_NAME)); err != nil { return err } if err := hooks.PostCompile(); err != nil { return err } css := make([]byte, 0) if conf.Gss != nil { css, err = ioutil.ReadFile(filepath.Join(conf.Build, config.CSS_NAME)) if err != nil { return app.Error(err) } } data := map[string]interface{}{ "Content": template.HTML(string(content.Bytes())), "Port": config.Port, "LT": template.HTML("<"), "Namespaces": template.HTML("'" + strings.Join(namespaces, "', '") + "'"), "Css": template.HTML(template.JSEscapeString(string(css))), } r.W.Header().Set("Content-Type", "text/javascript") return r.ExecuteTemplate([]string{"raw"}, data) }
func Input(r *app.Request) error { name := mux.Vars(r.Req)["name"] if name == config.DEPS_NAME { if err := hooks.PreCompile(); err != nil { return err } if err := soy.Compile(); err != nil { return err } if _, _, err := js.GenerateDeps("input"); err != nil { return err } conf := config.Current() f, err := os.Open(path.Join(conf.Build, config.DEPS_NAME)) if err != nil { return app.Error(err) } defer f.Close() r.W.Header().Set("Content-Type", "text/javascript") if _, err := io.Copy(r.W, f); err != nil { return app.Error(err) } if err := hooks.PostCompile(); err != nil { return err } return nil } // Otherwise serve the file if it can be found paths := scan.BaseJSPaths() for _, p := range paths { f, err := os.Open(path.Join(p, name)) if err != nil && !os.IsNotExist(err) { return app.Error(err) } else if err == nil { defer f.Close() r.W.Header().Set("Content-Type", "text/javascript") io.Copy(r.W, f) return nil } } return app.Errorf("file not found: %s", name) }
func FullCompile() error { if err := hooks.PreCompile(); err != nil { return err } if err := gss.Compile(); err != nil { return err } if err := soy.Compile(); err != nil { return err } if err := Compile(); err != nil { return err } if err := hooks.PostCompile(); err != nil { return err } return nil }