Beispiel #1
0
func (app *App) rewriteAssets(t *template.Template, included *includedApp) error {
	if !app.shouldImportAssets() {
		return nil
	}
	for _, group := range t.Assets() {
		for _, a := range group.Assets {
			if a.IsRemote() || a.IsHTML() {
				continue
			}
			orig := a.Name
			if a.IsTemplate() {
				orig = a.TemplateName()
			}
			name := included.renames[orig]
			if name == "" {
				return fmt.Errorf("asset %q referenced from template %q does not exist", a.Name, t.Name())
			}
			a.Rename(name)
		}
		group.Manager = app.assetsManager
	}
	fname := included.assetFuncName()
	for _, v := range t.Trees() {
		templateutil.WalkTree(v, func(n, p parse.Node) {
			if n.Type() == parse.NodeIdentifier {
				id := n.(*parse.IdentifierNode)
				if id.Ident == template.AssetFuncName {
					id.Ident = fname
				}
			}
		})
	}
	return nil
}
Beispiel #2
0
func (a *includedApp) assetFunc(t *template.Template) func(string) (string, error) {
	return func(arg string) (string, error) {
		name := a.renames[arg]
		return t.Asset(name)
	}
}