Exemplo n.º 1
0
// RewritePaths returns a new AssetPack with updated input and output.
// More precisely, if the AssetPack.Input or AssetPack.Output is relative, it is prefixed
// by the `input` and `output` parameters.
func (ap AssetPack) RewritePaths(input, output string) Asset {
	return AssetPack{
		Input:       helpers.RewritePath(input, ap.Input),
		Output:      helpers.RewritePath(output, ap.Output),
		Pattern:     ap.Pattern,
		Alterations: ap.Alterations,
		Dumper:      FileDumper{},
	}
}
Exemplo n.º 2
0
// RewritePaths returns a new SingleAsset with updated input and output.
// More precisely, if the SingleAsset.Input or SingleAsset.Output path is relative, it is prefixed
// by the `input` and `output` parameters.
func (sa SingleAsset) RewritePaths(input, output string) Asset {
	return SingleAsset{
		Input:  sa.Input.In(input),
		Output: helpers.RewritePath(output, sa.Output),
		Dumper: FileDumper{},
	}
}
Exemplo n.º 3
0
// URLFromFilename returns the url of an asset given its filename.
// It checks if the server defined in Manager.Server matches the filename.
// If not it checks all the servers defined in Manager.Servers one by one.
// If a correct server is found, the filename is rewritten into an url.
// If not, an empty string is returned.
func (m Manager) URLFromFilename(filename string) (string, error) {
	filename = helpers.RewritePath(".", filename)
	filename, err := filepath.Abs(filename)
	if err != nil {
		return "", err
	}

	servers := append([]Server{m.Server}, m.Servers...)

	for _, s := range servers {
		dir := helpers.RewritePath(m.Output, s.Directory)
		dir, _ = filepath.Abs(dir)

		if strings.HasPrefix(filename, dir) {
			u, err := url.Parse(s.URL + "/" + filename[len(dir):])
			if err == nil {
				u.Path = filepath.Clean(u.Path)
				return u.String(), nil
			}
		}
	}

	return "", fmt.Errorf("no server for file `%s`", filename)
}
Exemplo n.º 4
0
// AssetPackSymlink returns the filename of an asset symlink.
// It does not check if the symlink exists.
func (m Manager) AssetPackSymlink(ap AssetPack, filename string) (string, error) {
	ap = ap.RewritePaths(m.Input, m.Output).(AssetPack)
	symlink := helpers.RewritePath(ap.Output, filename)
	return filepath.Abs(symlink)
}