2021-11-02 02:13:49 +00:00
|
|
|
//go:build ignore
|
2016-12-13 17:56:45 +00:00
|
|
|
// +build ignore
|
|
|
|
|
|
|
|
package main
|
|
|
|
|
|
|
|
import (
|
|
|
|
"encoding/json"
|
2016-12-13 19:02:39 +00:00
|
|
|
"flag"
|
2017-11-17 16:26:04 +00:00
|
|
|
"fmt"
|
2016-12-13 17:56:45 +00:00
|
|
|
"log"
|
|
|
|
"os"
|
2021-11-02 02:12:03 +00:00
|
|
|
"strings"
|
2016-12-13 17:56:45 +00:00
|
|
|
"text/template"
|
2016-12-13 19:02:39 +00:00
|
|
|
|
2017-02-10 15:48:38 +00:00
|
|
|
"github.com/emojisum/emojisum/emoji"
|
2016-12-13 17:56:45 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
func main() {
|
2016-12-13 19:02:39 +00:00
|
|
|
flag.Parse()
|
|
|
|
input, err := os.Open(*flInput)
|
2016-12-13 17:56:45 +00:00
|
|
|
if err != nil {
|
|
|
|
log.Fatal(err)
|
|
|
|
}
|
|
|
|
defer input.Close()
|
|
|
|
|
2016-12-13 19:02:39 +00:00
|
|
|
vm := emoji.VersionedMap{}
|
2016-12-13 17:56:45 +00:00
|
|
|
|
|
|
|
dec := json.NewDecoder(input)
|
2016-12-13 19:02:39 +00:00
|
|
|
if err := dec.Decode(&vm); err != nil {
|
2016-12-13 17:56:45 +00:00
|
|
|
log.Fatal(err)
|
|
|
|
}
|
|
|
|
|
2016-12-13 19:02:39 +00:00
|
|
|
output, err := os.Create(*flOutput)
|
2016-12-13 17:56:45 +00:00
|
|
|
if err != nil {
|
|
|
|
log.Fatal(err)
|
|
|
|
}
|
|
|
|
defer output.Close()
|
2016-12-13 19:02:39 +00:00
|
|
|
|
2017-02-07 19:09:07 +00:00
|
|
|
//mapGoTemp := template.Must(template.ParseFiles(*flTemplate))
|
|
|
|
funcMap := template.FuncMap{
|
2017-11-17 16:26:04 +00:00
|
|
|
"IsColonNotation": emoji.IsColonNotation,
|
|
|
|
"IsCodepoint": emoji.IsCodepoint,
|
|
|
|
"CodepointLinkMarkdown": codepointLinkMarkdown,
|
2021-11-02 02:12:03 +00:00
|
|
|
"Join": join,
|
2017-02-07 19:09:07 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
mapGoTemp, err := template.New("").Funcs(funcMap).Parse(tmpl[*flTemplate])
|
|
|
|
if err != nil {
|
|
|
|
log.Fatal(err)
|
|
|
|
}
|
2016-12-13 19:02:39 +00:00
|
|
|
if err := mapGoTemp.Execute(output, vm); err != nil {
|
2016-12-13 17:56:45 +00:00
|
|
|
log.Fatal(err)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-11-17 16:26:04 +00:00
|
|
|
func codepointLinkMarkdown(word string) string {
|
2018-10-16 18:32:46 +00:00
|
|
|
return fmt.Sprintf(`[%s](%s)`, word, emoji.UnicodeLinkURL(word))
|
2017-11-17 16:26:04 +00:00
|
|
|
}
|
|
|
|
|
2021-11-02 02:12:03 +00:00
|
|
|
func join(sep string, v []string) string {
|
|
|
|
return strings.Join(v, sep)
|
|
|
|
}
|
|
|
|
|
2016-12-13 17:56:45 +00:00
|
|
|
var (
|
2016-12-13 19:02:39 +00:00
|
|
|
flInput = flag.String("in", "emojimap.json", "json input")
|
|
|
|
flOutput = flag.String("out", "map_gen.go", "golang output")
|
2017-02-07 19:09:07 +00:00
|
|
|
flTemplate = flag.String("template", "map_gen", "template to use (map_gen or markdown_gen)")
|
2016-12-13 17:56:45 +00:00
|
|
|
)
|
2017-02-07 19:09:07 +00:00
|
|
|
|
|
|
|
var tmpl = map[string]string{
|
2021-11-02 02:12:03 +00:00
|
|
|
"map_gen": `// THIS FILE IS GENERATED. DO NOT EDIT.
|
2017-02-07 19:09:07 +00:00
|
|
|
|
|
|
|
package emoji
|
|
|
|
|
|
|
|
func init() {
|
2021-11-02 02:12:03 +00:00
|
|
|
mapGen = VersionedMap{
|
|
|
|
Description: "{{.Description}}",
|
|
|
|
Version: "{{.Version}}",
|
|
|
|
EmojiWords: []Words{
|
|
|
|
{{- range .EmojiWords }}
|
|
|
|
{"{{- Join "\", \"" . }}"},
|
|
|
|
{{- end }}
|
|
|
|
},
|
|
|
|
}
|
2017-02-07 19:09:07 +00:00
|
|
|
}
|
|
|
|
`,
|
|
|
|
"markdown_gen": `
|
|
|
|
## Emoji Map list
|
|
|
|
|
|
|
|
_THIS FILE IS GENERATED. DO NOT EDIT._
|
|
|
|
|
|
|
|
This is for "pretty" viewing purposes.
|
|
|
|
To view the functional document, see [emojimap.json](./emojimap.json).
|
|
|
|
|
|
|
|
### Description
|
|
|
|
|
|
|
|
{{ .Description }}
|
|
|
|
|
|
|
|
### Version
|
|
|
|
|
|
|
|
{{ .Version }}
|
|
|
|
|
|
|
|
### List
|
|
|
|
|
|
|
|
{{- range $index, $words := .EmojiWords }}
|
2017-11-17 16:26:04 +00:00
|
|
|
* ` + "`{{ $index }}`" + ` -- {{ range $words }} {{- if IsColonNotation . -}} {{ . }} ` + "`{{ . }}`" + ` {{- else }} {{ CodepointLinkMarkdown . }} {{- end }}{{- end }}
|
2017-02-07 19:09:07 +00:00
|
|
|
{{- end }}
|
|
|
|
`,
|
|
|
|
}
|