func (s *Spriter) parseImage(imgFile string) (*stamp, error) { if img, ok := s.loadedImages[imgFile]; ok { return img, nil } if f, err := s.sv.OpenImage(imgFile); err != nil { return nil, errors.NewInput(err) } else { defer closeClosable(f) img, _, err := image.Decode(f) if err != nil { return nil, errors.NewInput(err) } st := &stamp{ imgFile, img, image.Pt(-1, -1), } s.loadedImages[imgFile] = st return st, nil } }
func main() { cmdline.Go(func() error { var bps basePathSlice srcCssFile := flag.String("i", "", "Input css file") dstCssFile := flag.String("o", "", "Output css file, can be the same as input css file") flag.Var(&bps, "base", "Base directory to resolve image files. Default to input css file directory. Can be specified multiple times, it is useful if the input css file is created by tools such as scss from multiple .css files in different directories.") flag.Parse() var ( css []byte out string err error ) if *srcCssFile == "" || *dstCssFile == "" { flag.Usage() return cmdline.NewExitError(2) } if len(bps) == 0 { bps = basePathSlice{filepath.Dir(*srcCssFile)} } if css, err = ioutil.ReadFile(*srcCssFile); err != nil { return errors.NewInput(err) } spriter := sprite.New(string(css), sprite.NewFileService(([]string)(bps), filepath.Dir(*dstCssFile))) if out, err = spriter.Gen(); err != nil { return err } if err = ioutil.WriteFile(*dstCssFile, ([]byte)(out), 0); err != nil { return errors.NewRuntime(err) } return nil }) }
}) It("NewBug", func() { assertError(errors.NewBug(syserr.New("foo")), "foo", errors.ByBug) }) It("NewRuntime", func() { assertError(errors.NewRuntime(syserr.New("foo")), "foo", errors.ByRuntime) }) It("NewExternal", func() { assertError(errors.NewExternal(syserr.New("foo")), "foo", errors.ByExternal) }) It("NewInput", func() { assertError(errors.NewInput(syserr.New("foo")), "foo", errors.ByInput) }) Context("Not wrap nil", func() { It("NewBug", func() { Ω(errors.NewBug(nil)).Should(BeNil()) }) It("NewRuntime", func() { Ω(errors.NewRuntime(nil)).Should(BeNil()) }) It("NewInput", func() { Ω(errors.NewInput(nil)).Should(BeNil()) })