func (comp *Compiler) compileTo(compiled *components.Compiled, c *components.Component) (err error) { // Set defaults from base component context compiled.Context = compiled.Context.WithDefaults(c.Context) // Component base path base := strings.Replace(c.Name, ".", string(os.PathSeparator), -1) // Compile main component template if not empty if c.Main != "" { compiled.Main, err = parseTemplate(comp.Storage, c.Main, base) if err != nil { return } } // Parse urls and compile styles templates compiled.Styles, err = parseTemplates(comp.Storage, c.Styles, base, compiled.Styles) if err != nil { return } // Parse urls and compile scripts templates compiled.Scripts, err = parseTemplates(comp.Storage, c.Scripts, base, compiled.Scripts) if err != nil { return } // Compile `With` templates map and merge into `compiled` if compiled.With != nil && c.With != nil { compiled.With, err = compiled.With.ParseAndMerge(c.With) } else if c.With != nil { compiled.With, err = template.ParseMap(c.With) } if err != nil { return } // Compile a component which this one `extends` if c.Extends != "" { compiled.Extends, err = comp.CompileByName(c.Extends) if err != nil { return } } // Compile required components for name, r := range c.Require { req, err := comp.CompileFromStorage(&r) if err != nil { return err } if compiled.Require == nil { compiled.Require = make(map[string]*components.Compiled) } compiled.Require[name] = req } return }
func constructOptions(md *Middleware) (opts *middlewareOpts, err error) { opts = &middlewareOpts{ options: md.Options, context: make(map[string]contextNode), } opts.template, err = template.ParseMap(template.Context(md.Template)) if err != nil { return } for key, value := range md.Context { opts.context[key] = newContextNode(value) } return }