func getBranchIcon(in *pongo2.Value, param *pongo2.Value) (*pongo2.Value, *pongo2.Error) { str := in.String() s := strings.Split(str, "-") if len(s) < 2 { return nil, &pongo2.Error{ Sender: "filter:branchicon", ErrorMsg: "Field did not contain a valid GoBuilder filename", } } s = strings.Split(s[len(s)-2], "_") // Map the architectures used by golang to fontawesome icon names switch s[len(s)-1] { case "darwin": return pongo2.AsValue("apple"), nil case "linux": return pongo2.AsValue("linux"), nil case "windows": return pongo2.AsValue("windows"), nil case "android": return pongo2.AsValue("android"), nil } // Not all archs have icons, use a generic file icon return pongo2.AsValue("file"), nil }
func filterTruncatesentences(in *pongo2.Value, param *pongo2.Value) (*pongo2.Value, *pongo2.Error) { count := param.Integer() if count <= 0 { return pongo2.AsValue(""), nil } sentencens := filterTruncatesentencesRe.FindAllString(strings.TrimSpace(in.String()), -1) return pongo2.AsValue(strings.TrimSpace(strings.Join(sentencens[:min(count, len(sentencens))], ""))), nil }
func toSwagger(in *pongo2.Value, param *pongo2.Value) (*pongo2.Value, *pongo2.Error) { i := in.Interface() m := i.(map[string]interface{}) fixPropertyTree(m) data, _ := json.MarshalIndent(i, param.String(), " ") return pongo2.AsValue(string(data)), nil }
func filterRead(in *pongo2.Value, param *pongo2.Value) (*pongo2.Value, *pongo2.Error) { data, err := ioutil.ReadFile(in.String()) if err != nil { return nil, &pongo2.Error{ Sender: "filter:read", ErrorMsg: err.Error(), } } return pongo2.AsSafeValue(string(data)), nil }
func filterTruncatesentencesHtml(in *pongo2.Value, param *pongo2.Value) (*pongo2.Value, *pongo2.Error) { count := param.Integer() if count <= 0 { return pongo2.AsValue(""), nil } value := in.String() newLen := max(param.Integer(), 0) new_output := bytes.NewBuffer(nil) sentencefilter := 0 filterTruncateHtmlHelper(value, new_output, func() bool { return sentencefilter >= newLen }, func(_ rune, _ int, idx int) int { // Get next word word_found := false for idx < len(value) { c2, size2 := utf8.DecodeRuneInString(value[idx:]) if c2 == utf8.RuneError { idx += size2 continue } if c2 == '<' { // HTML tag start, don't consume it return idx } new_output.WriteRune(c2) idx += size2 if (c2 == '.' && !(idx+1 < len(value) && value[idx+1] >= '0' && value[idx+1] <= '9')) || c2 == '!' || c2 == '?' || c2 == '\n' { // Sentence ends here, stop capturing it now break } else { word_found = true } } if word_found { sentencefilter++ } return idx }, func() {}) return pongo2.AsSafeValue(new_output.String()), nil }
func checkMainArch(in *pongo2.Value, param *pongo2.Value) (*pongo2.Value, *pongo2.Error) { str := in.String() s := strings.Split(str, "-") if len(s) < 2 { return nil, &pongo2.Error{ Sender: "filter:branchicon", ErrorMsg: "Field did not contain a valid GoBuilder filename", } } s = strings.Split(s[len(s)-2], "_") for _, v := range []string{"linux", "darwin", "windows"} { if s[len(s)-1] == v { return pongo2.AsValue(true), nil } } return pongo2.AsValue(false), nil }
func toUnderScoreCase(in *pongo2.Value, param *pongo2.Value) (*pongo2.Value, *pongo2.Error) { s := in.String() if len(s) == 0 { return nil, nil } parts := []string{} chars := []rune(s) var buffer bytes.Buffer for i := 0; i < len(chars)-1; i++ { if unicode.IsUpper(chars[i]) && unicode.IsLower(chars[i+1]) && buffer.String() != "" { parts = append(parts, buffer.String()) buffer.Reset() } buffer.WriteRune(unicode.ToLower(chars[i])) if unicode.IsLower(chars[i]) && unicode.IsUpper(chars[i+1]) { parts = append(parts, buffer.String()) buffer.Reset() } } buffer.WriteRune(unicode.ToLower(chars[len(chars)-1])) parts = append(parts, buffer.String()) return pongo2.AsValue(strings.Join(parts, "_")), nil }
func toSwagger(in *pongo2.Value, param *pongo2.Value) (*pongo2.Value, *pongo2.Error) { i := in.Interface() m := i.(map[string]interface{}) switch properties := m["properties"].(type) { case map[string]interface{}: for _, value := range properties { deleteGohanExtendedProperties(value.(map[string]interface{})) } delete(properties, "propertiesOrder") case map[string]map[string]interface{}: for _, value := range properties { deleteGohanExtendedProperties(value) } delete(properties, "propertiesOrder") } if list, ok := m["required"].([]string); ok { if len(list) == 0 { delete(m, "required") } } delete(m, "propertiesOrder") data, _ := json.MarshalIndent(i, param.String(), " ") return pongo2.AsValue(string(data)), nil }
func filterReset(in *pongo2.Value, param *pongo2.Value) (*pongo2.Value, *pongo2.Error) { return pongo2.AsValue(in.String() == "reset"), nil }
func filterIgnored(in *pongo2.Value, param *pongo2.Value) (*pongo2.Value, *pongo2.Error) { return pongo2.AsValue(in.String() == "ignored"), nil }
func filterSuccess(in *pongo2.Value, param *pongo2.Value) (*pongo2.Value, *pongo2.Error) { return pongo2.AsValue(in.String() == "success"), nil }
func hasIdParam(in *pongo2.Value, param *pongo2.Value) (*pongo2.Value, *pongo2.Error) { i := in.String() return pongo2.AsValue(strings.Contains(i, ":id")), nil }
func filterAbspath(in *pongo2.Value, param *pongo2.Value) (*pongo2.Value, *pongo2.Error) { return pongo2.AsValue(path.Join(rootPath, in.String())), nil }
func filterSlugify(in *pongo2.Value, param *pongo2.Value) (*pongo2.Value, *pongo2.Error) { return pongo2.AsValue(slug.Slug(in.String())), nil }
func filterMarkdown(in *pongo2.Value, param *pongo2.Value) (*pongo2.Value, *pongo2.Error) { return pongo2.AsSafeValue(string(blackfriday.MarkdownCommon([]byte(in.String())))), nil }
func filterFailure(in *pongo2.Value, param *pongo2.Value) (*pongo2.Value, *pongo2.Error) { return pongo2.AsValue(in.String() == "failure"), nil }
// filterAddquote pongo2 filter for adding an extra quote func filterAddquote(in *pongo2.Value, param *pongo2.Value) (*pongo2.Value, *pongo2.Error) { output := strings.Replace(in.String(), "'", "''", -1) return pongo2.AsValue(output), nil }
func toSwaggerPath(in *pongo2.Value, param *pongo2.Value) (*pongo2.Value, *pongo2.Error) { i := in.String() r := regexp.MustCompile(":([^/]+)") return pongo2.AsValue(r.ReplaceAllString(i, "{$1}")), nil }