Now generates mime file

This commit is contained in:
David Paz 2017-07-10 12:50:52 +02:00
parent 5df52d50a6
commit 125c802582
4 changed files with 13 additions and 2 deletions

View File

@ -162,12 +162,12 @@ func printFile(file string, buff *bytes.Buffer) {
} }
totalLines, sloc := getLines(file, content) totalLines, sloc := getLines(file, content)
fileType := getFileType(file, content) fileType := getFileType(file, content)
//mime type left
language := enry.GetLanguage(file, content) language := enry.GetLanguage(file, content)
mimeType := enry.GetMimeType(language)
buff.WriteString(fmt.Sprintf("%s: %d lines (%d sloc)\n", filepath.Base(file), totalLines, sloc)) buff.WriteString(fmt.Sprintf("%s: %d lines (%d sloc)\n", filepath.Base(file), totalLines, sloc))
buff.WriteString(fmt.Sprintf(" type: %s\n", fileType)) buff.WriteString(fmt.Sprintf(" type: %s\n", fileType))
buff.WriteString(fmt.Sprint(" mime type: \n")) buff.WriteString(fmt.Sprintf(" mime type: %s\n", mimeType))
buff.WriteString(fmt.Sprintf(" language: %s\n", language)) buff.WriteString(fmt.Sprintf(" language: %s\n", language))
} }

View File

@ -8,6 +8,7 @@ type languageInfo struct {
Extensions []string `yaml:"extensions,omitempty,flow"` Extensions []string `yaml:"extensions,omitempty,flow"`
Interpreters []string `yaml:"interpreters,omitempty,flow"` Interpreters []string `yaml:"interpreters,omitempty,flow"`
Filenames []string `yaml:"filenames,omitempty,flow"` Filenames []string `yaml:"filenames,omitempty,flow"`
MimeType string `yaml:"codemirror_mime_type,omitempty,flow"`
} }
func getAlphabeticalOrderedKeys(languages map[string]*languageInfo) []string { func getAlphabeticalOrderedKeys(languages map[string]*languageInfo) []string {

View File

@ -67,6 +67,11 @@ const (
commitTmplPath = "internal/code-generator/assets/commit.go.tmpl" commitTmplPath = "internal/code-generator/assets/commit.go.tmpl"
commitTmpl = "commit.go.tmpl" commitTmpl = "commit.go.tmpl"
// mime.go generation
mimeFile = "data/mime.go"
mimeTmplPath = "internal/code-generator/assets/mime.go.tmpl"
mimeTmpl = "mime.go.tmpl"
commitPath = ".linguist/.git/HEAD" commitPath = ".linguist/.git/HEAD"
) )
@ -97,6 +102,7 @@ func main() {
&generatorFiles{generator.Aliases, languagesYAML, "", aliasesFile, aliasesTmplPath, aliasesTmpl, commit}, &generatorFiles{generator.Aliases, languagesYAML, "", aliasesFile, aliasesTmplPath, aliasesTmpl, commit},
&generatorFiles{generator.Frequencies, "", samplesDir, frequenciesFile, frequenciesTmplPath, frequenciesTmpl, commit}, &generatorFiles{generator.Frequencies, "", samplesDir, frequenciesFile, frequenciesTmplPath, frequenciesTmpl, commit},
&generatorFiles{generator.Commit, "", "", commitFile, commitTmplPath, commitTmpl, commit}, &generatorFiles{generator.Commit, "", "", commitFile, commitTmplPath, commitTmpl, commit},
&generatorFiles{generator.Mime, languagesYAML, "", mimeFile, mimeTmplPath, mimeTmpl, commit},
} }
for _, file := range fileList { for _, file := range fileList {

View File

@ -53,6 +53,10 @@ func IsDocumentation(path string) bool {
return data.DocumentationMatchers.Match(path) return data.DocumentationMatchers.Match(path)
} }
func GetMimeType(file string) string {
return data.LanguagesMime[file]
}
const sniffLen = 8000 const sniffLen = 8000
// IsBinary detects if data is a binary value based on: // IsBinary detects if data is a binary value based on: