mirror of
https://github.com/ralsina/tartrazine.git
synced 2025-06-19 06:33:06 -03:00
Return group color if language has none
This commit is contained in:
@ -24,7 +24,7 @@ func Colors(fileToParse, samplesDir, outPath, tmplPath, tmplName, commit string)
|
||||
langColorMap := buildLanguageColorMap(languages)
|
||||
|
||||
buf := &bytes.Buffer{}
|
||||
if err := executeMimeTemplate(buf, langColorMap, tmplPath, tmplName, commit); err != nil {
|
||||
if err := executeColorTemplate(buf, langColorMap, tmplPath, tmplName, commit); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
|
@ -88,6 +88,11 @@ var (
|
||||
colorsGold = filepath.Join(testDir, "colors.gold")
|
||||
colorsTestTmplPath = filepath.Join(assetsDir, "colors.go.tmpl")
|
||||
colorsTestTmplName = "colors.go.tmpl"
|
||||
|
||||
// colors test
|
||||
groupsGold = filepath.Join(testDir, "groups.gold")
|
||||
groupsTestTmplPath = filepath.Join(assetsDir, "groups.go.tmpl")
|
||||
groupsTestTmplName = "groups.go.tmpl"
|
||||
)
|
||||
|
||||
type GeneratorTestSuite struct {
|
||||
@ -261,6 +266,16 @@ func (s *GeneratorTestSuite) SetupSuite() {
|
||||
generate: Colors,
|
||||
wantOut: colorsGold,
|
||||
},
|
||||
{
|
||||
name: "Groups()",
|
||||
fileToParse: filepath.Join(s.tmpLinguist, languagesFile),
|
||||
samplesDir: "",
|
||||
tmplPath: groupsTestTmplPath,
|
||||
tmplName: groupsTestTmplName,
|
||||
commit: commit,
|
||||
generate: Groups,
|
||||
wantOut: groupsGold,
|
||||
},
|
||||
}
|
||||
}
|
||||
|
||||
|
47
internal/code-generator/generator/groups.go
Normal file
47
internal/code-generator/generator/groups.go
Normal file
@ -0,0 +1,47 @@
|
||||
package generator
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"io"
|
||||
"io/ioutil"
|
||||
|
||||
"gopkg.in/yaml.v2"
|
||||
)
|
||||
|
||||
// Groups generates a map in Go with language name -> group name.
|
||||
// It is of generator.File type.
|
||||
func Groups(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
|
||||
}
|
||||
|
||||
langGroupMap := buildLanguageGroupMap(languages)
|
||||
|
||||
buf := &bytes.Buffer{}
|
||||
if err := executeGroupTemplate(buf, langGroupMap, tmplPath, tmplName, commit); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
return formatedWrite(outPath, buf.Bytes())
|
||||
}
|
||||
|
||||
func buildLanguageGroupMap(languages map[string]*languageInfo) map[string]string {
|
||||
langGroupMap := make(map[string]string)
|
||||
for lang, info := range languages {
|
||||
if len(info.Group) != 0 {
|
||||
langGroupMap[lang] = info.Group
|
||||
}
|
||||
}
|
||||
|
||||
return langGroupMap
|
||||
}
|
||||
|
||||
func executeGroupTemplate(out io.Writer, langColorMap map[string]string, tmplPath, tmplName, commit string) error {
|
||||
return executeTemplate(out, tmplName, tmplPath, commit, nil, langColorMap)
|
||||
}
|
@ -5,6 +5,7 @@ import "sort"
|
||||
type languageInfo struct {
|
||||
Type string `yaml:"type,omitempty"`
|
||||
Color string `yaml:"color,omitempty"`
|
||||
Group string `yaml:"group,omitempty"`
|
||||
Aliases []string `yaml:"aliases,omitempty"`
|
||||
Extensions []string `yaml:"extensions,omitempty,flow"`
|
||||
Interpreters []string `yaml:"interpreters,omitempty,flow"`
|
||||
|
89
internal/code-generator/generator/test_files/groups.gold
Normal file
89
internal/code-generator/generator/test_files/groups.gold
Normal file
@ -0,0 +1,89 @@
|
||||
// Code generated by github.com/go-enry/go-enry/v2/internal/code-generator DO NOT EDIT.
|
||||
// Extracted from github/linguist commit: 40992ba7f86889f80dfed3ba95e11e1082200bad
|
||||
|
||||
package data
|
||||
|
||||
var LanguagesGroup = map[string]string{
|
||||
"Alpine Abuild": "Shell",
|
||||
"Apollo Guidance Computer": "Assembly",
|
||||
"BibTeX": "TeX",
|
||||
"Bison": "Yacc",
|
||||
"Blade": "HTML",
|
||||
"C2hs Haskell": "Haskell",
|
||||
"Closure Templates": "HTML",
|
||||
"ColdFusion CFC": "ColdFusion",
|
||||
"Cython": "Python",
|
||||
"ECLiPSe": "prolog",
|
||||
"EJS": "HTML",
|
||||
"Easybuild": "Python",
|
||||
"Ecere Projects": "JavaScript",
|
||||
"EditorConfig": "INI",
|
||||
"Filterscript": "RenderScript",
|
||||
"Gentoo Ebuild": "Shell",
|
||||
"Gentoo Eclass": "Shell",
|
||||
"Git Attributes": "INI",
|
||||
"Git Config": "INI",
|
||||
"Groovy Server Pages": "Groovy",
|
||||
"HTML+Django": "HTML",
|
||||
"HTML+ECR": "HTML",
|
||||
"HTML+EEX": "HTML",
|
||||
"HTML+ERB": "HTML",
|
||||
"HTML+PHP": "HTML",
|
||||
"HTML+Razor": "HTML",
|
||||
"Haml": "HTML",
|
||||
"Handlebars": "HTML",
|
||||
"Ignore List": "INI",
|
||||
"Isabelle ROOT": "Isabelle",
|
||||
"JFlex": "Lex",
|
||||
"JSON with Comments": "JSON",
|
||||
"JSX": "JavaScript",
|
||||
"Java Server Pages": "Java",
|
||||
"JavaScript+ERB": "JavaScript",
|
||||
"Jison": "Yacc",
|
||||
"Jison Lex": "Lex",
|
||||
"Latte": "HTML",
|
||||
"Less": "CSS",
|
||||
"Literate Agda": "Agda",
|
||||
"Literate CoffeeScript": "CoffeeScript",
|
||||
"Literate Haskell": "Haskell",
|
||||
"M4Sugar": "M4",
|
||||
"MUF": "Forth",
|
||||
"Marko": "HTML",
|
||||
"Motorola 68K Assembly": "Assembly",
|
||||
"NPM Config": "INI",
|
||||
"NumPy": "Python",
|
||||
"OpenCL": "C",
|
||||
"OpenRC runscript": "Shell",
|
||||
"Parrot Assembly": "Parrot",
|
||||
"Parrot Internal Representation": "Parrot",
|
||||
"Pic": "Roff",
|
||||
"PostCSS": "CSS",
|
||||
"Pug": "HTML",
|
||||
"Python console": "Python",
|
||||
"Python traceback": "Python",
|
||||
"RHTML": "HTML",
|
||||
"Readline Config": "INI",
|
||||
"Roff Manpage": "Roff",
|
||||
"SCSS": "CSS",
|
||||
"SSH Config": "INI",
|
||||
"STON": "Smalltalk",
|
||||
"Sage": "Python",
|
||||
"Sass": "CSS",
|
||||
"Scaml": "HTML",
|
||||
"Slim": "HTML",
|
||||
"Stylus": "CSS",
|
||||
"SugarSS": "CSS",
|
||||
"Svelte": "HTML",
|
||||
"TSX": "TypeScript",
|
||||
"Tcsh": "Shell",
|
||||
"Twig": "HTML",
|
||||
"Unified Parallel C": "C",
|
||||
"Unix Assembly": "Assembly",
|
||||
"Wget Config": "INI",
|
||||
"X BitMap": "C",
|
||||
"X PixMap": "C",
|
||||
"XML Property List": "XML",
|
||||
"cURL Config": "INI",
|
||||
"fish": "Shell",
|
||||
"nanorc": "INI",
|
||||
}
|
Reference in New Issue
Block a user