Exemplo n.º 1
0
// Dump dumps the asset defined in SingleAsset.Input.
// If some filters are passed in the `filters` parameter, they will be applied before
// dumping the asset.
func (sa SingleAsset) Dump(filters []Filter) error {
	r := sa.Input

	output, err := sa.OutputFile("")
	for _, f := range filters {
		if f.Pattern.Match(output) {
			r, err = f.Alteration.Alter(r)
			if err != nil {
				return err
			}
		}
	}

	c, err := r.Dump()
	if err != nil {
		return err
	}

	md5Output, err := sa.OutputFile("." + helpers.MD5(c))
	if err != nil {
		return err
	}

	err = sa.Dumper.Dump(md5Output, output, c)
	if err != nil {
		return err
	}

	return nil
}
Exemplo n.º 2
0
// Dump reads files contained in AssetPack.Input and dumps
// them in AssetPack.Output if they match AssetPack.Pattern.
// If some filters are defined in AssetPack.Filters, they will be
// applied before dumping the assets with the AssetPack.Dumper.
// If some filters are passed in the `filters` parameter, they will be applied just after
// filters in AssetPack.Filters.
func (ap AssetPack) Dump(filters []Filter) error {
	var r resource.Resource

	files, err := ap.InputFiles()
	if err != nil {
		return err
	}

	for _, filename := range files {
		c, err := ioutil.ReadFile(filename)
		if err != nil {
			return err
		}

		r = resource.NewBytes(c)

		for _, a := range ap.Alterations {
			r, err = a.Alter(r)
			if err != nil {
				return err
			}
		}

		output, err := ap.OutputFile(filename, "")
		for _, f := range filters {
			if f.Pattern.Match(output) {
				r, err = f.Alteration.Alter(r)
				if err != nil {
					return err
				}
			}
		}

		c, err = r.Dump()
		if err != nil {
			return err
		}

		md5Output, err := ap.OutputFile(filename, "."+helpers.MD5(c))
		if err != nil {
			return err
		}

		err = ap.Dumper.Dump(md5Output, output, c)
		if err != nil {
			return err
		}
	}

	return nil
}