func StartServer(options map[string]string) { server := &AhcServer{FsParser: &parse.Fs{}, HtmlCompressor: htmlcompressor.InitAll()} server.Dev = (options["dev"] == "true") server.ReadComponents() port := options["port"] if port == "" { port = "8080" } http.HandleFunc("/", server.IndexHandler) http.HandleFunc("/v/", server.ViewHandler) http.HandleFunc("/t/", server.TemplateHandler) http.HandleFunc("/s/", server.StyleHandler) http.ListenAndServe(":"+port, nil) }
func (self *Fs) ParseIntoTestPool(testPool *component.TestPool, dirpath string) error { pool := &component.Pool{} err := self.ParseIntoPool(pool, dirpath) if err != nil { return err } htmlcompressor := htmlcompressor.InitAll() return filepath.Walk(dirpath, func(path string, f os.FileInfo, err error) error { if !f.IsDir() && filepath.Ext(f.Name()) == ".test" { testSuite, err := self.ParseComponentTest(path, pool) if err != nil { return err } testSuite.Compressor = htmlcompressor testPool.TestSuites = append(testPool.TestSuites, testSuite) } return nil }) }
func TestComponentTest(t *testing.T) { params := make(map[string]interface{}) params["name"] = "Button" expected := ` <div class="ahc_button">Button</div> ` test := &Test{Params: params, Expected: []byte(expected)} tmpl := `<div class="ahc_button">{{.name|html}}</div>` c := &Component{Namespace: "goog.a-button", Template: &Template{Content: tmpl}, Schema: &schema.Schema{}} compressor := htmlcompressor.InitAll() err := test.Run(c, nil, compressor) if err != nil { t.Errorf("Expected to get no test error, but got %v", err) } expected = ` <div class="ahc_button"> Button </div> ` test.Expected = []byte(expected) err = test.Run(c, nil, compressor) if err == nil { t.Errorf("Expected to get test error, but got nil") } }