當前位置: 首頁>>代碼示例>>Golang>>正文


Golang pongo2.Value類代碼示例

本文整理匯總了Golang中github.com/flosch/pongo2.Value的典型用法代碼示例。如果您正苦於以下問題:Golang Value類的具體用法?Golang Value怎麽用?Golang Value使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。


在下文中一共展示了Value類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。

示例1: jsonPrettyFilter

func jsonPrettyFilter(in *pongo2.Value, param *pongo2.Value) (out *pongo2.Value, e *pongo2.Error) {
	body, err := json.MarshalIndent(in.Interface(), "", "  ")
	if err != nil {
		return nil, &pongo2.Error{ErrorMsg: err.Error()}
	}
	return pongo2.AsValue(string(body)), nil
}
開發者ID:crackcomm,項目名稱:renderer,代碼行數:7,代碼來源:filters.go

示例2: getBranchIcon

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
}
開發者ID:golang-lib,項目名稱:gobuilder,代碼行數:26,代碼來源:filters.go

示例3: filterBool

func filterBool(in *pongo2.Value, param *pongo2.Value) (*pongo2.Value, *pongo2.Error) {
	if in.IsNil() {
		return pongo2.AsValue(false), nil
	}
	switch t := in.Interface().(type) {
	case string:
		if t == "" {
			return pongo2.AsValue(false), nil
		}
		v, err := strconv.ParseBool(t)
		if err != nil {
			return nil, &pongo2.Error{
				Sender:   "filter:bool",
				ErrorMsg: "Filter input value invalid.",
			}
		}
		return pongo2.AsValue(v), nil
	case bool:
		return pongo2.AsValue(t), nil
	}
	return nil, &pongo2.Error{
		Sender:   "filter:bool",
		ErrorMsg: "Filter input value must be of type 'bool' or 'string'.",
	}
}
開發者ID:crackcomm,項目名稱:renderer,代碼行數:25,代碼來源:filters.go

示例4: filterTruncatesentences

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
}
開發者ID:whyrusleeping,項目名稱:gobuilder,代碼行數:8,代碼來源:filters.go

示例5: toSwagger

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
}
開發者ID:cloudwan,項目名稱:gohan,代碼行數:9,代碼來源:template.go

示例6: filterAfterNow

func filterAfterNow(in *pongo2.Value, param *pongo2.Value) (*pongo2.Value, *pongo2.Error) {
	t, isTime := in.Interface().(time.Time)
	if !isTime {
		return nil, &pongo2.Error{
			Sender:   "filter:past_now",
			ErrorMsg: "Filter input argument must be of type 'time.Time'.",
		}
	}
	return pongo2.AsValue(time.Now().Before(t)), nil
}
開發者ID:crackcomm,項目名稱:renderer,代碼行數:10,代碼來源:filters.go

示例7: filterHumanizeTime

func filterHumanizeTime(in *pongo2.Value, param *pongo2.Value) (*pongo2.Value, *pongo2.Error) {
	t, isTime := in.Interface().(time.Time)
	if !isTime {
		return nil, &pongo2.Error{
			Sender:   "filter:humanize_time",
			ErrorMsg: "Filter input argument must be of type: 'time.Time'.",
		}
	}
	return pongo2.AsValue(humanize.Time(t)), nil
}
開發者ID:crackcomm,項目名稱:renderer,代碼行數:10,代碼來源:filters.go

示例8: filterRead

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
}
開發者ID:mbrodala,項目名稱:otto,代碼行數:11,代碼來源:filter_read.go

示例9: checkMainArch

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
}
開發者ID:golang-lib,項目名稱:gobuilder,代碼行數:18,代碼來源:filters.go

示例10: timeSince

func timeSince(in *pongo2.Value, param *pongo2.Value) (*pongo2.Value, *pongo2.Error) {
	errMsg := &pongo2.Error{
		Sender:   "filter:timeuntil/timesince",
		ErrorMsg: "time-value is not a time.Time string.",
	}

	dateStr, ok := in.Interface().(string)
	if !ok {
		return nil, errMsg
	}

	basetime, err := time.Parse(time.RFC3339, dateStr)
	if err != nil {
		return nil, errMsg
	}

	return pongo2.AsValue(util.FormatTime(basetime)), nil
}
開發者ID:hi-trust,項目名稱:friendfeed,代碼行數:18,代碼來源:filter.go

示例11: filterJson

func filterJson(in *pongo2.Value, param *pongo2.Value) (out *pongo2.Value, err *pongo2.Error) {
	var value []byte

	mapValue, ok := in.Interface().(map[string]interface{})
	if ok {
		value, _ = json.Marshal(mapValue)
	} else {
		var arrMapValue []map[string]interface{}
		in.Iterate(func(idx int, count int, key *pongo2.Value, value *pongo2.Value) bool {
			mapItem, ok := key.Interface().(map[string]interface{})
			if ok {
				arrMapValue = append(arrMapValue, mapItem)
			} else {
				panic("[gin_pongo2.filterJson] Unknow format #1")
			}
			return true
		}, func() {})
		value, _ = json.Marshal(arrMapValue)
	}
	return pongo2.AsValue(string(value)), nil
}
開發者ID:stepan-perlov,項目名稱:gin_pongo2,代碼行數:21,代碼來源:filters.go

示例12: toUnderScoreCase

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
}
開發者ID:vozhyk-,項目名稱:gohan,代碼行數:23,代碼來源:gen.go

示例13: toSwagger

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
}
開發者ID:vozhyk-,項目名稱:gohan,代碼行數:24,代碼來源:template.go

示例14: filterTruncatesentencesHtml

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
}
開發者ID:whyrusleeping,項目名稱:gobuilder,代碼行數:52,代碼來源:filters.go

示例15: filterTimeuntilTimesince

func filterTimeuntilTimesince(in *pongo2.Value, param *pongo2.Value) (*pongo2.Value, *pongo2.Error) {
	basetime, is_time := in.Interface().(time.Time)
	if !is_time {
		return nil, &pongo2.Error{
			Sender:   "filter:timeuntil/timesince",
			ErrorMsg: "time-value is not a time.Time-instance.",
		}
	}
	var paramtime time.Time
	if !param.IsNil() {
		paramtime, is_time = param.Interface().(time.Time)
		if !is_time {
			return nil, &pongo2.Error{
				Sender:   "filter:timeuntil/timesince",
				ErrorMsg: "time-parameter is not a time.Time-instance.",
			}
		}
	} else {
		paramtime = time.Now()
	}

	return pongo2.AsValue(humanize.TimeDuration(basetime.Sub(paramtime))), nil
}
開發者ID:whyrusleeping,項目名稱:gobuilder,代碼行數:23,代碼來源:filters.go


注:本文中的github.com/flosch/pongo2.Value類示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。