github.com/insionng/yougam@v0.0.0-20170714101924-2bc18d833463/helper/pongo2.go (about)

     1  package helper
     2  
     3  import (
     4  	"encoding/base64"
     5  	"strings"
     6  	"time"
     7  	"github.com/insionng/yougam/libraries/flosch/pongo2.v3"
     8  )
     9  
    10  func ConvertToBase64(in string) string {
    11  	return base64.StdEncoding.EncodeToString([]byte(in))
    12  }
    13  
    14  func ConvertToBase64ByPongo2(in *pongo2.Value) *pongo2.Value {
    15  	return pongo2.AsValue(base64.StdEncoding.EncodeToString([]byte(in.String())))
    16  }
    17  
    18  func SplitByPongo2(in *pongo2.Value, splitor *pongo2.Value) *pongo2.Value {
    19  	return pongo2.AsValue(Split(in.String(), splitor.String()))
    20  }
    21  
    22  func MarkdownByPongo2(in *pongo2.Value) *pongo2.Value {
    23  	return pongo2.AsValue(Markdown(in.String()))
    24  }
    25  
    26  func CropwordByPongo2(in *pongo2.Value, start *pongo2.Value, length *pongo2.Value, symbol *pongo2.Value) *pongo2.Value {
    27  	return pongo2.AsValue(Substr(in.String(), start.Integer(), length.Integer(), symbol.String()))
    28  }
    29  
    30  func Cropword(in string, start int, length int, symbol string) string {
    31  	return Substr(in, start, length, symbol)
    32  }
    33  
    34  func File(s string) string {
    35  	if len(s) > 0 {
    36  		if strings.HasPrefix(s, "http") || strings.HasPrefix(s, "/identicon") {
    37  			return s
    38  		} else {
    39  			return "/file" + s
    40  		}
    41  	}
    42  	return s
    43  }
    44  
    45  func Unix2TimeByPongo2(in *pongo2.Value, timeLayout *pongo2.Value) *pongo2.Value {
    46  	return pongo2.AsValue(time.Unix(int64(in.Integer()), 0).Format(timeLayout.String()))
    47  }