func doTemplate(c *cli.Context) { template := c.String("template") manager := schema.GetManager() configFile := c.String("config-file") config := util.GetConfig() err := config.ReadConfig(configFile) if err != nil { util.ExitFatal(err) return } templateCode, err := util.GetContent(template) if err != nil { util.ExitFatal(err) return } pwd, _ := os.Getwd() os.Chdir(path.Dir(configFile)) schemaFiles := config.GetStringList("schemas", nil) if schemaFiles == nil { util.ExitFatal("No schema specified in configuraion") } else { err = manager.LoadSchemasFromFiles(schemaFiles...) if err != nil { util.ExitFatal(err) return } } schemas := manager.OrderedSchemas() if err != nil { util.ExitFatal(err) return } tpl, err := pongo2.FromString(string(templateCode)) if err != nil { util.ExitFatal(err) return } output, err := tpl.Execute(pongo2.Context{"schemas": schemas}) if err != nil { util.ExitFatal(err) return } os.Chdir(pwd) fmt.Println(output) }
//NewExtension returns new extension from object func NewExtension(raw interface{}) (*Extension, error) { typeData := raw.(map[string](interface{})) extension := &Extension{} extension.ID, _ = typeData["id"].(string) extension.CodeType, _ = typeData["code_type"].(string) if extension.CodeType == "" { extension.CodeType = DefaultExtension } if _, ok := typeData["url"].(string); ok { url, err := url.Parse(typeData["url"].(string)) if err != nil { return nil, err } if isURLRelative := url.Scheme == "file" && url.Host == "."; isURLRelative { workingDirectory, err := os.Getwd() if err != nil { return nil, err } url.Host = "" url.Path = filepath.Join(workingDirectory, url.Path) } extension.URL = url.String() } extension.Code, _ = typeData["code"].(string) path, _ := typeData["path"].(string) match, err := regexp.Compile(path) if err != nil { return nil, fmt.Errorf("failed to parse regexp: %s", err) } extension.Path = match if extension.URL != "" { remoteCode, err := util.GetContent(extension.URL) extension.Code += string(remoteCode) if err != nil { return nil, fmt.Errorf("failed to load remote code: %s", err) } } return extension, nil }