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"
|
|
|
|
"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,
|
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 {
|
|
|
|
return fmt.Sprintf(`[%s](%s)`, word, emoji.UnicodeLink(word))
|
|
|
|
}
|
|
|
|
|
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{
|
|
|
|
"map_gen": `
|
|
|
|
// THIS FILE IS GENERATED. DO NOT EDIT.
|
|
|
|
|
|
|
|
package emoji
|
|
|
|
|
|
|
|
func init() {
|
|
|
|
mapGen = VersionedMap{
|
|
|
|
Description: "{{.Description}}",
|
|
|
|
Version: "{{.Version}}",
|
|
|
|
EmojiWords: []Words{ {{- range .EmojiWords }}
|
|
|
|
Words{ {{ range . -}}
|
|
|
|
"{{- . }}",{{- end }}
|
|
|
|
},{{- end }}
|
|
|
|
},
|
|
|
|
}
|
|
|
|
}
|
|
|
|
`,
|
|
|
|
"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 }}
|
|
|
|
`,
|
|
|
|
}
|