Last active
May 16, 2016 01:36
-
-
Save kyoh86/66d3bebcc6c9316b251e to your computer and use it in GitHub Desktop.
golangでellipsis ref: http://qiita.com/kyoh86/items/6393e2d7567e71ea741d
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package main | |
// Ellipsis a text | |
func Ellipsis(length int, text string) string { | |
r := []rune(text) | |
if len(r) > length { | |
return string(r[0:length]) + "..." | |
} | |
return text | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package main | |
// Ellipsis a text | |
func Ellipsis(length int, text string) string { | |
r := []rune(text) | |
if len(r) > length { | |
return string(r[0:length]) + "..." | |
} | |
return text | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package main | |
import ( | |
"bytes" | |
"fmt" | |
"text/template" | |
) | |
func main() { | |
var buf bytes.Buffer | |
template.New("text"). | |
Funcs(template.FuncMap{"ellipsis": Ellipse}). | |
Parse(`{{.value | ellipsis 5}}`). | |
Execute(buf, map[string]string{"value": "みんみんみらくる☆"}) | |
fmt.Println(buf.String()) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment