Exemple #1
0
func (*minify) Process(ctx goldsmith.Context, f goldsmith.File) error {
	var (
		buff bytes.Buffer
		err  error
	)

	switch m := min.New(); filepath.Ext(f.Path()) {
	case ".css":
		err = css.Minify(m, &buff, f, nil)
	case ".html", ".htm":
		err = html.Minify(m, &buff, f, nil)
	case ".js":
		err = js.Minify(m, &buff, f, nil)
	case ".json":
		err = json.Minify(m, &buff, f, nil)
	case ".svg":
		err = svg.Minify(m, &buff, f, nil)
	case ".xml":
		err = xml.Minify(m, &buff, f, nil)
	}

	if err != nil {
		return err
	}

	nf := goldsmith.NewFileFromData(f.Path(), buff.Bytes())
	nf.CopyValues(f)
	ctx.DispatchFile(nf)

	return nil
}
Exemple #2
0
func Fuzz(data []byte) int {
	r := bytes.NewBuffer(data)
	err := css.Minify(minify.New(), ioutil.Discard, r, nil)
	if err != nil {
		return 0
	}
	return 1
}
Exemple #3
0
func MinifyStylesheet(body string) (string, error) {
	b_result := bytes.NewBuffer([]byte{})
	body_reader := strings.NewReader(body)
	err := css.Minify(minifier, b_result, body_reader, map[string]string{})
	if err != nil {
		return "", errors.New(fmt.Sprintf("Minification error: %v", err))
	}
	return b_result.String(), nil
}