Пример #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
}
Пример #2
0
func Fuzz(data []byte) int {
	r := bytes.NewBuffer(data)
	err := js.Minify(minify.New(), ioutil.Discard, r, nil)
	if err != nil {
		panic(err)
	}
	return 1
}
Пример #3
0
func MinifyJavascript(body string) (string, error) {
	b_result := bytes.NewBuffer([]byte{})
	body_reader := strings.NewReader(body)

	err := js.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
}