mirror of
https://github.com/ralsina/tartrazine.git
synced 2024-11-10 13:32:24 +00:00
Added pending untracked files
This commit is contained in:
parent
25e12e9c03
commit
632422db69
11
internal/code-generator/assets/mime.go.tmpl
Normal file
11
internal/code-generator/assets/mime.go.tmpl
Normal file
@ -0,0 +1,11 @@
|
||||
package data
|
||||
|
||||
// CODE GENERATED AUTOMATICALLY WITH gopkg.in/src-d/enry.v1/internal/code-generator
|
||||
// THIS FILE SHOULD NOT BE EDITED BY HAND
|
||||
// Extracted from github/linguist commit: {{ getCommit }}
|
||||
|
||||
var LanguagesMime = map[string]string{
|
||||
{{range $language, $mime := . -}}
|
||||
"{{$language}}": "{{$mime -}}",
|
||||
{{end -}}
|
||||
}
|
53
internal/code-generator/generator/mime.go
Normal file
53
internal/code-generator/generator/mime.go
Normal file
@ -0,0 +1,53 @@
|
||||
package generator
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"html/template"
|
||||
"io"
|
||||
"io/ioutil"
|
||||
|
||||
yaml "gopkg.in/yaml.v2"
|
||||
)
|
||||
|
||||
func Mime(fileToParse, samplesDir, outPath, tmplPath, tmplName, commit string) error {
|
||||
data, err := ioutil.ReadFile(fileToParse)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
languages := make(map[string]*languageInfo)
|
||||
if err := yaml.Unmarshal(data, &languages); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
langMimeMap := buildLanguageMimeMap(languages)
|
||||
|
||||
buf := &bytes.Buffer{}
|
||||
if err := executeMimeTemplate(buf, langMimeMap, tmplPath, tmplName, commit); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
return formatedWrite(outPath, buf.Bytes())
|
||||
}
|
||||
|
||||
func buildLanguageMimeMap(languages map[string]*languageInfo) map[string]string {
|
||||
langMimeMap := make(map[string]string)
|
||||
for lang, info := range languages {
|
||||
langMimeMap[lang] = info.MimeType
|
||||
}
|
||||
|
||||
return langMimeMap
|
||||
}
|
||||
|
||||
func executeMimeTemplate(out io.Writer, langMimeMap map[string]string, tmplPath, tmplName, commit string) error {
|
||||
fmap := template.FuncMap{
|
||||
"getCommit": func() string { return commit },
|
||||
}
|
||||
|
||||
t := template.Must(template.New(tmplName).Funcs(fmap).ParseFiles(tmplPath))
|
||||
if err := t.Execute(out, langMimeMap); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
Loading…
Reference in New Issue
Block a user