1
0
Fork 0
mirror of https://github.com/emojisum/emojisum.git synced 2024-11-23 16:05:40 +00:00
emojisum/emoji/map_json.go
Vincent Batts cc9cb5d099
emoji: fix merged unicode
for several of the emoji "words", they are a union of unicode points.
Like flags are the two letters together. Female Detective is a number of
connected symbols. This representation needs to be alltogether.

With this update the unicode points are joined, and require spliting on
the "U+". To help with this and be useful as a library there is a
function `emoji.CodepointToUnicode(string) string` to do this now.

Signed-off-by: Vincent Batts <vbatts@hashbangbash.com>
2018-10-16 14:38:00 -04:00

103 lines
2.1 KiB
Go

// +build ignore
package main
import (
"encoding/json"
"flag"
"fmt"
"log"
"os"
"text/template"
"github.com/emojisum/emojisum/emoji"
)
func main() {
flag.Parse()
input, err := os.Open(*flInput)
if err != nil {
log.Fatal(err)
}
defer input.Close()
vm := emoji.VersionedMap{}
dec := json.NewDecoder(input)
if err := dec.Decode(&vm); err != nil {
log.Fatal(err)
}
output, err := os.Create(*flOutput)
if err != nil {
log.Fatal(err)
}
defer output.Close()
//mapGoTemp := template.Must(template.ParseFiles(*flTemplate))
funcMap := template.FuncMap{
"IsColonNotation": emoji.IsColonNotation,
"IsCodepoint": emoji.IsCodepoint,
"CodepointLinkMarkdown": codepointLinkMarkdown,
}
mapGoTemp, err := template.New("").Funcs(funcMap).Parse(tmpl[*flTemplate])
if err != nil {
log.Fatal(err)
}
if err := mapGoTemp.Execute(output, vm); err != nil {
log.Fatal(err)
}
}
func codepointLinkMarkdown(word string) string {
return fmt.Sprintf(`[%s](%s)`, word, emoji.UnicodeLinkURL(word))
}
var (
flInput = flag.String("in", "emojimap.json", "json input")
flOutput = flag.String("out", "map_gen.go", "golang output")
flTemplate = flag.String("template", "map_gen", "template to use (map_gen or markdown_gen)")
)
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 }}
* ` + "`{{ $index }}`" + ` -- {{ range $words }} {{- if IsColonNotation . -}} {{ . }} ` + "`{{ . }}`" + ` {{- else }} {{ CodepointLinkMarkdown . }} {{- end }}{{- end }}
{{- end }}
`,
}