Documentation ¶
Index ¶
- type Asset
- type AssetPack
- type Dumper
- type FileDumper
- type Filter
- type Manager
- func (m Manager) AssetPackSymlink(ap AssetPack, filename string) (string, error)
- func (m Manager) Dump() error
- func (m Manager) SingleAssetSymlink(sa SingleAsset) (string, error)
- func (m Manager) Symlink(assetName string, paths ...string) (string, error)
- func (m Manager) URL(assetName string, paths ...string) string
- func (m Manager) URLFromFilename(filename string) (string, error)
- func (m Manager) URLFromSymlink(symlink string) (string, error)
- type Pattern
- type Server
- type SingleAsset
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type AssetPack ¶
type AssetPack struct { Input string Output string Pattern Pattern Alterations []resource.Alteration Dumper Dumper }
AssetPack implements the Asset interface. It includes all the assets located in the AssetPack.Input directory. Only the files with an output (without md5 suffix) matching the AssetPack.Pattern are part of the AssetPack. When the asset is dumped with the AssetPack.Dumper, AssetPack.Filters are applied before writing the assets in the AssetPack.Output directory.
func (AssetPack) Dump ¶
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 (AssetPack) InputFiles ¶
InputFiles returns all the files contained in AssetPack.Input that are not directories and that match AssetPack.Pattern.
func (AssetPack) OutputFile ¶
OutputFile returns the absolute filename of an output based on the filename of the input. It also add a suffix in the basename (for example an md5 hash or a version number). The suffix is inserted just before the file extension and at the end of the filename if no extension was found.
func (AssetPack) RewritePaths ¶
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.
type FileDumper ¶
type FileDumper struct{}
FileDumper implements the Dumper interface to dump assets into files.
type Filter ¶
type Filter struct { Alteration resource.Alteration Pattern Pattern }
Filter is the combination of an Alteration and a Pattern. The Pattern may allow to apply an Alteration only to some files.
type Manager ¶
type Manager struct { Input string Output string Server Server Servers []Server Filters []Filter Assets map[string]Asset }
Manager contains the definition of your asset and can dump them. It can also get the url of your assets.
- Manager.Input will be the base directory for all your assets with a relative path. Assets with an absolute path will not be changed by this attribute.
- Manager.Output works the same way as Manager.Input does but is the base directory in which your assets will be dumped.
- Manager.Server defines an url for a directory. When your want to know the url of a given asset, this attribute will be used.
- Manager.Servers is used like Manager.Server. Use it if your assets are in different directories.
- Filters contains a list of filters that will be applied to all your assets before dumping them.
- Assets contains all your assets. The key of the map is the name of the asset.
func (Manager) AssetPackSymlink ¶
AssetPackSymlink returns the filename of an asset symlink. It does not check if the symlink exists.
func (Manager) Dump ¶
Dump dumps all defined assets. If an asset path is relative, it is rewritten to be based in manager.Input and Manager.Output.
func (Manager) SingleAssetSymlink ¶
func (m Manager) SingleAssetSymlink(sa SingleAsset) (string, error)
SingleAssetSymlink returns the filename of an asset symlink. It does not check if the symlink exists.
func (Manager) Symlink ¶
Symlink returns the filename of an asset symlink. For a SingleAsset, only the name of the asset is needed. For AssetPack, you also need to provide the path of the file inside the output directory
func (Manager) URL ¶
URL returns the url of an asset thanks to its name and what is defined in Manager.Server and Manager.Servers. If an error occurs, an empty string is returned.
If the asset is a SingleAsset, the name is enought to get its url. For example manager.Url("single") works.
But if the asset is an AssetPack, you also need to give its path inside the output directory. For example, manager.Url("pack", "/js/jquery.js") will look into the output directory of the asset named "pack" for the file {outputDirectory}/js/jquery.js
func (Manager) URLFromFilename ¶
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.
type Pattern ¶
type Pattern struct {
Regexp string
}
Pattern is a wrapper for regular expressions.
func NewExtensionPattern ¶
NewExtensionPattern returns a Pattern with a regexp matching all the filenames with the extensions given in parameter.
func NewPattern ¶
NewPattern returns a Pattern based on a given `regexp`.
type SingleAsset ¶
SingleAsset implements the Asset interface. It includes only one asset (SingleAsset.Input) implementing the Asset interface located in the asset package. The asset will be dump in the SingleAsset.Output file.
func (SingleAsset) Dump ¶
func (sa SingleAsset) Dump(filters []Filter) error
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 (SingleAsset) OutputFile ¶
func (sa SingleAsset) OutputFile(suffix string) (string, error)
OutputFile returns the absolute filename of the SingleAsset.Output. It also add a suffix in the basename (for example an md5 hash or a version number). The suffix is inserted just before the file extension and at the end of the filename if no extension was found.
func (SingleAsset) RewritePaths ¶
func (sa SingleAsset) RewritePaths(input, output string) Asset
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.