assets: github.com/fragmenta/assets Index | Files | Directories

package assets

import "github.com/fragmenta/assets"

Package assets provides asset compilation, concatenation and fingerprinting.

Index

Package Files

assets.go file.go group.go helpers.go

func ScriptLink(name string) template.HTML

ScriptLink returns an html tag for a given file path

func StyleLink(name string) template.HTML

StyleLink returns an html tag for a given file path

type Collection Uses

type Collection struct {
    // contains filtered or unexported fields
}

Collection holds the complete list of groups

func New Uses

func New(compiled bool) *Collection

New returns a new assets.Collection

func (*Collection) Compile Uses

func (c *Collection) Compile(src string, dst string) error

Compile images, styles and scripts asset folders from src into dst (minifying and amalgamating)

func (*Collection) FetchOrCreateGroup Uses

func (c *Collection) FetchOrCreateGroup(name string) *Group

FetchOrCreateGroup returns the named group if it exists, or creates it if not

func (*Collection) File Uses

func (c *Collection) File(name string) *File

File returns the first asset file matching name - this assumes files have unique names between groups

func (*Collection) Group Uses

func (c *Collection) Group(name string) *Group

Group returns the named group if it exists or an empty group if not

func (*Collection) Load Uses

func (c *Collection) Load() error

Load the asset groups from the assets json file Call this on startup from your app to read the asset details after assets are compiled

func (*Collection) MarshalJSON Uses

func (c *Collection) MarshalJSON() ([]byte, error)

MarshalJSON generates json for this collection, of the form {group:{file:hash}}

func (*Collection) Save Uses

func (c *Collection) Save() error

Save the assets to a file after compilation

func (c *Collection) ScriptLink(names ...string) template.HTML

ScriptLink converts a set of group names to one script tag (production) or to a list of script tags (development)

func (c *Collection) StyleLink(names ...string) template.HTML

StyleLink converts a set of group names to one style link tag (production) or to a list of style link tags (development)

type File Uses

type File struct {
    // contains filtered or unexported fields
}

File stores a filename and hash fingerprint for the asset file

func NewFile Uses

func NewFile(p string) (*File, error)

NewFile returns a new file object

func (*File) AssetPath Uses

func (f *File) AssetPath(dst string) string

AssetPath returns the path of this file within the assets folder

func (*File) Copy Uses

func (f *File) Copy(dst string) error

Copy our bytes to dstpath

func (*File) LocalPath Uses

func (f *File) LocalPath() string

LocalPath returns the relative path of this file

func (*File) MarshalJSON Uses

func (f *File) MarshalJSON() ([]byte, error)

MarshalJSON generates json for this file, of the form {group:{file:hash}}

func (*File) Newer Uses

func (f *File) Newer(dst string) bool

Newer returns true if file exists at path

func (*File) Script Uses

func (f *File) Script() bool

Script returns true if this file is a js file

func (*File) String Uses

func (f *File) String() string

String returns a string representation of this object

func (*File) Style Uses

func (f *File) Style() bool

Style returns true if this file is a CSS file

type Group Uses

type Group struct {
    // contains filtered or unexported fields
}

Group holds a name and a list of files (images, scripts, styles)

func (*Group) AddAsset Uses

func (g *Group) AddAsset(p, h string)

AddAsset adds this asset to the group

func (*Group) Compile Uses

func (g *Group) Compile(dst string) error

Compile compiles all our files and calculates hashes from their contents The group hash is a hash of hashes

func (*Group) MarshalJSON Uses

func (g *Group) MarshalJSON() ([]byte, error)

MarshalJSON generates json for this collection, of the form {group:{file:hash}}

func (*Group) ParseFile Uses

func (g *Group) ParseFile(p string, dst string) error

ParseFile adds this asset to our list of files, along with a fingerprint based on the content

func (*Group) RemoveFiles Uses

func (g *Group) RemoveFiles(dst string) error

RemoveFiles removes old compiled files for this group from dst

func (*Group) ScriptName Uses

func (g *Group) ScriptName() string

ScriptName returns a fingerprinted group name for scripts

func (*Group) ScriptPath Uses

func (g *Group) ScriptPath(dst string) string

ScriptPath returns a fingerprinted group path for scripts

func (*Group) Scripts Uses

func (g *Group) Scripts() []*File

Scripts returns an array of file names for styles

func (*Group) String Uses

func (g *Group) String() string

String returns a string represention of group

func (*Group) StyleName Uses

func (g *Group) StyleName() string

StyleName returns a fingerprinted group name for styles

func (*Group) StylePath Uses

func (g *Group) StylePath(dst string) string

StylePath returns a fingerprinted group path for styles

func (*Group) Styles Uses

func (g *Group) Styles() []*File

Styles returns an array of file names for styles

Directories

PathSynopsis
internal/cssminPackage cssmin minifies CSS.
internal/jsminPackage jsmin implements JavaScript minifier.

Package assets imports 14 packages (graph) and is imported by 5 packages. Updated 2017-01-08. Refresh now. Tools for package owners.