Added mymeType.gold

This commit is contained in:
David Paz 2017-07-11 11:13:49 +02:00
parent ea819f58c2
commit b2fe3f69ce
6 changed files with 441 additions and 479 deletions

View File

@ -47,10 +47,7 @@ func main() {
} }
if relativePath == "." { if relativePath == "." {
var buff bytes.Buffer return printFileAnalysis(root)
printFile(root, &buff)
fmt.Print(buff.String())
return nil
} }
if f.IsDir() { if f.IsDir() {
@ -155,33 +152,36 @@ func printPercents(out map[string][]string, buff *bytes.Buffer) {
} }
} }
func printFile(file string, buff *bytes.Buffer) { func printFileAnalysis(file string) string {
content, err := ioutil.ReadFile(file) content, err := ioutil.ReadFile(file)
if err != nil { if err != nil {
fmt.Println(err) fmt.Println(err)
} }
totalLines, sloc := getLines(file, content) totalLines, linesOfCode := getLines(file, string(content))
fileType := getFileType(file, content) fileType := getFileType(file, content)
language := enry.GetLanguage(file, content) language := enry.GetLanguage(file, content)
mimeType := enry.GetMimeType(language) mimeType := enry.GetMimeType(language)
buff.WriteString(fmt.Sprintf("%s: %d lines (%d sloc)\n", filepath.Base(file), totalLines, sloc)) return fmt.Sprintf(
buff.WriteString(fmt.Sprintf(" type: %s\n", fileType)) `%s: %d lines (%d sloc)
buff.WriteString(fmt.Sprintf(" mime type: %s\n", mimeType)) type: %s
buff.WriteString(fmt.Sprintf(" language: %s\n", language)) mime_type: %s
language: %s
`,
filepath.Base(file), totalLines, linesOfCode, fileType, mimeType, language)
} }
func getLines(file string, content []byte) (int, int) { func getLines(file string, content string) (int, int) {
totalLines := bytes.Count(content, []byte("\n")) totalLines := strings.Count(content, "\n")
sloc := totalLines - strings.Count(string(content), "\n\n") linesOfCode := totalLines - strings.Count(content, "\n\n")
return totalLines, sloc return totalLines, linesOfCode
} }
func getFileType(file string, content []byte) string { func getFileType(file string, content []byte) string {
switch { switch {
case isImage(file): case enry.IsImage(file):
return "Image" return "Image"
case enry.IsBinary(content): case enry.IsBinary(content):
return "Binary" return "Binary"
@ -190,15 +190,6 @@ func getFileType(file string, content []byte) string {
} }
} }
func isImage(file string) bool {
index := strings.LastIndex(file, ".")
extension := file[index:]
if extension == ".png" || extension == ".jpg" || extension == ".jpeg" || extension == ".gif" {
return true
}
return false
}
func writeStringLn(s string, buff *bytes.Buffer) { func writeStringLn(s string, buff *bytes.Buffer) {
buff.WriteString(s) buff.WriteString(s)
buff.WriteByte('\n') buff.WriteByte('\n')

View File

@ -5,457 +5,200 @@ package data
// Extracted from github/linguist commit: d5c8db3fb91963c4b2762ca2ea2ff7cfac109f68 // Extracted from github/linguist commit: d5c8db3fb91963c4b2762ca2ea2ff7cfac109f68
var LanguagesMime = map[string]string{ var LanguagesMime = map[string]string{
"1C Enterprise": "", "AGS Script": "text/x-c++src",
"ABAP": "",
"ABNF": "",
"AGS Script": "text/x-c++src",
"AMPL": "",
"ANTLR": "",
"API Blueprint": "",
"APL": "text/apl", "APL": "text/apl",
"ASN.1": "text/x-ttcn-asn", "ASN.1": "text/x-ttcn-asn",
"ASP": "application/x-aspx", "ASP": "application/x-aspx",
"ATS": "",
"ActionScript": "",
"Ada": "",
"Agda": "",
"Alloy": "",
"Alpine Abuild": "text/x-sh", "Alpine Abuild": "text/x-sh",
"Ant Build System": "application/xml", "Ant Build System": "application/xml",
"ApacheConf": "",
"Apex": "text/x-java", "Apex": "text/x-java",
"Apollo Guidance Computer": "", "Arduino": "text/x-c++src",
"AppleScript": "",
"Arc": "",
"Arduino": "text/x-c++src",
"AsciiDoc": "",
"AspectJ": "",
"Assembly": "",
"Augeas": "",
"AutoHotkey": "",
"AutoIt": "",
"Awk": "",
"Batchfile": "",
"Befunge": "",
"Bison": "",
"BitBake": "",
"Blade": "",
"BlitzBasic": "",
"BlitzMax": "",
"Bluespec": "",
"Boo": "",
"Brainfuck": "text/x-brainfuck", "Brainfuck": "text/x-brainfuck",
"Brightscript": "",
"Bro": "",
"C": "text/x-csrc", "C": "text/x-csrc",
"C#": "text/x-csharp", "C#": "text/x-csharp",
"C++": "text/x-c++src", "C++": "text/x-c++src",
"C-ObjDump": "",
"C2hs Haskell": "text/x-haskell", "C2hs Haskell": "text/x-haskell",
"CLIPS": "",
"CMake": "text/x-cmake", "CMake": "text/x-cmake",
"COBOL": "text/x-cobol", "COBOL": "text/x-cobol",
"COLLADA": "text/xml", "COLLADA": "text/xml",
"CSON": "text/x-coffeescript", "CSON": "text/x-coffeescript",
"CSS": "text/css", "CSS": "text/css",
"CSV": "",
"CWeb": "",
"Cap'n Proto": "",
"CartoCSS": "",
"Ceylon": "",
"Chapel": "",
"Charity": "",
"ChucK": "text/x-java", "ChucK": "text/x-java",
"Cirru": "",
"Clarion": "",
"Clean": "",
"Click": "",
"Clojure": "text/x-clojure", "Clojure": "text/x-clojure",
"Closure Templates": "text/x-soy", "Closure Templates": "text/x-soy",
"CoffeeScript": "text/x-coffeescript", "CoffeeScript": "text/x-coffeescript",
"ColdFusion": "",
"ColdFusion CFC": "",
"Common Lisp": "text/x-common-lisp", "Common Lisp": "text/x-common-lisp",
"Component Pascal": "text/x-pascal", "Component Pascal": "text/x-pascal",
"Cool": "",
"Coq": "",
"Cpp-ObjDump": "",
"Creole": "",
"Crystal": "text/x-crystal", "Crystal": "text/x-crystal",
"Csound": "", "Cuda": "text/x-c++src",
"Csound Document": "",
"Csound Score": "",
"Cuda": "text/x-c++src",
"Cycript": "text/javascript", "Cycript": "text/javascript",
"Cython": "text/x-cython", "Cython": "text/x-cython",
"D": "text/x-d", "D": "text/x-d",
"D-ObjDump": "",
"DIGITAL Command Language": "",
"DM": "",
"DNS Zone": "",
"DTrace": "text/x-csrc", "DTrace": "text/x-csrc",
"Darcs Patch": "",
"Dart": "application/dart", "Dart": "application/dart",
"Diff": "text/x-diff", "Diff": "text/x-diff",
"Dockerfile": "text/x-dockerfile", "Dockerfile": "text/x-dockerfile",
"Dogescript": "",
"Dylan": "text/x-dylan", "Dylan": "text/x-dylan",
"E": "",
"EBNF": "text/x-ebnf", "EBNF": "text/x-ebnf",
"ECL": "text/x-ecl", "ECL": "text/x-ecl",
"ECLiPSe": "",
"EJS": "",
"EQ": "text/x-csharp", "EQ": "text/x-csharp",
"Eagle": "text/xml", "Eagle": "text/xml",
"Easybuild": "text/x-python", "Easybuild": "text/x-python",
"Ecere Projects": "application/json", "Ecere Projects": "application/json",
"Eiffel": "text/x-eiffel", "Eiffel": "text/x-eiffel",
"Elixir": "",
"Elm": "text/x-elm", "Elm": "text/x-elm",
"Emacs Lisp": "text/x-common-lisp", "Emacs Lisp": "text/x-common-lisp",
"EmberScript": "text/x-coffeescript", "EmberScript": "text/x-coffeescript",
"Erlang": "text/x-erlang", "Erlang": "text/x-erlang",
"F#": "text/x-fsharp", "F#": "text/x-fsharp",
"FLUX": "",
"Factor": "text/x-factor", "Factor": "text/x-factor",
"Fancy": "",
"Fantom": "",
"Filebench WML": "",
"Filterscript": "",
"Formatted": "",
"Forth": "text/x-forth", "Forth": "text/x-forth",
"Fortran": "text/x-fortran", "Fortran": "text/x-fortran",
"FreeMarker": "",
"Frege": "",
"G-code": "",
"GAMS": "",
"GAP": "",
"GCC Machine Description": "text/x-common-lisp", "GCC Machine Description": "text/x-common-lisp",
"GDB": "",
"GDScript": "",
"GLSL": "",
"GN": "text/x-python", "GN": "text/x-python",
"Game Maker Language": "text/x-c++src", "Game Maker Language": "text/x-c++src",
"Genie": "",
"Genshi": "text/xml", "Genshi": "text/xml",
"Gentoo Ebuild": "text/x-sh", "Gentoo Ebuild": "text/x-sh",
"Gentoo Eclass": "text/x-sh", "Gentoo Eclass": "text/x-sh",
"Gettext Catalog": "",
"Gherkin": "",
"Glyph": "text/x-tcl", "Glyph": "text/x-tcl",
"Gnuplot": "",
"Go": "text/x-go", "Go": "text/x-go",
"Golo": "",
"Gosu": "",
"Grace": "",
"Gradle": "",
"Grammatical Framework": "text/x-haskell", "Grammatical Framework": "text/x-haskell",
"Graph Modeling Language": "",
"GraphQL": "",
"Graphviz (DOT)": "",
"Groovy": "text/x-groovy", "Groovy": "text/x-groovy",
"Groovy Server Pages": "application/x-jsp", "Groovy Server Pages": "application/x-jsp",
"HCL": "text/x-ruby", "HCL": "text/x-ruby",
"HLSL": "",
"HTML": "text/html", "HTML": "text/html",
"HTML+Django": "text/x-django", "HTML+Django": "text/x-django",
"HTML+ECR": "text/html", "HTML+ECR": "text/html",
"HTML+EEX": "text/html", "HTML+EEX": "text/html",
"HTML+ERB": "application/x-erb", "HTML+ERB": "application/x-erb",
"HTML+PHP": "application/x-httpd-php", "HTML+PHP": "application/x-httpd-php",
"HTTP": "message/http", "HTTP": "message/http",
"Hack": "application/x-httpd-php", "Hack": "application/x-httpd-php",
"Haml": "text/x-haml", "Haml": "text/x-haml",
"Handlebars": "",
"Harbour": "",
"Haskell": "text/x-haskell", "Haskell": "text/x-haskell",
"Haxe": "text/x-haxe", "Haxe": "text/x-haxe",
"Hy": "",
"HyPhy": "",
"IDL": "text/x-idl", "IDL": "text/x-idl",
"IGOR Pro": "",
"INI": "text/x-properties", "INI": "text/x-properties",
"IRC log": "text/mirc", "IRC log": "text/mirc",
"Idris": "",
"Inform 7": "",
"Inno Setup": "",
"Io": "",
"Ioke": "",
"Isabelle": "",
"Isabelle ROOT": "",
"J": "",
"JFlex": "",
"JSON": "application/json", "JSON": "application/json",
"JSON5": "application/json", "JSON5": "application/json",
"JSONLD": "",
"JSONiq": "application/json", "JSONiq": "application/json",
"JSX": "text/jsx", "JSX": "text/jsx",
"Jasmin": "",
"Java": "text/x-java", "Java": "text/x-java",
"Java Server Pages": "application/x-jsp", "Java Server Pages": "application/x-jsp",
"JavaScript": "text/javascript", "JavaScript": "text/javascript",
"Jison": "",
"Jison Lex": "",
"Jolie": "",
"Julia": "text/x-julia", "Julia": "text/x-julia",
"Jupyter Notebook": "application/json", "Jupyter Notebook": "application/json",
"KRL": "",
"KiCad": "",
"Kit": "text/html", "Kit": "text/html",
"Kotlin": "text/x-kotlin", "Kotlin": "text/x-kotlin",
"LFE": "text/x-common-lisp", "LFE": "text/x-common-lisp",
"LLVM": "",
"LOLCODE": "",
"LSL": "",
"LabVIEW": "text/xml", "LabVIEW": "text/xml",
"Lasso": "",
"Latte": "text/x-smarty", "Latte": "text/x-smarty",
"Lean": "",
"Less": "text/css", "Less": "text/css",
"Lex": "",
"LilyPond": "",
"Limbo": "",
"Linker Script": "",
"Linux Kernel Module": "",
"Liquid": "",
"Literate Agda": "",
"Literate CoffeeScript": "",
"Literate Haskell": "text/x-literate-haskell", "Literate Haskell": "text/x-literate-haskell",
"LiveScript": "text/x-livescript", "LiveScript": "text/x-livescript",
"Logos": "",
"Logtalk": "",
"LookML": "text/x-yaml", "LookML": "text/x-yaml",
"LoomScript": "",
"Lua": "text/x-lua", "Lua": "text/x-lua",
"M": "text/x-mumps", "M": "text/x-mumps",
"M4": "",
"M4Sugar": "",
"MAXScript": "",
"MQL4": "",
"MQL5": "",
"MTML": "text/html", "MTML": "text/html",
"MUF": "text/x-forth", "MUF": "text/x-forth",
"Makefile": "text/x-cmake", "Makefile": "text/x-cmake",
"Mako": "",
"Markdown": "text/x-gfm", "Markdown": "text/x-gfm",
"Marko": "text/html", "Marko": "text/html",
"Mask": "",
"Mathematica": "text/x-mathematica", "Mathematica": "text/x-mathematica",
"Matlab": "text/x-octave", "Matlab": "text/x-octave",
"Maven POM": "text/xml", "Maven POM": "text/xml",
"Max": "application/json", "Max": "application/json",
"MediaWiki": "", "Metal": "text/x-c++src",
"Mercury": "",
"Meson": "",
"Metal": "text/x-c++src",
"MiniD": "",
"Mirah": "text/x-ruby", "Mirah": "text/x-ruby",
"Modelica": "text/x-modelica", "Modelica": "text/x-modelica",
"Modula-2": "",
"Module Management System": "",
"Monkey": "",
"Moocode": "",
"MoonScript": "",
"Myghty": "",
"NCL": "",
"NL": "",
"NSIS": "text/x-nsis", "NSIS": "text/x-nsis",
"Nemerle": "",
"NetLinx": "",
"NetLinx+ERB": "",
"NetLogo": "text/x-common-lisp", "NetLogo": "text/x-common-lisp",
"NewLisp": "text/x-common-lisp", "NewLisp": "text/x-common-lisp",
"Nginx": "text/x-nginx-conf", "Nginx": "text/x-nginx-conf",
"Nim": "",
"Ninja": "",
"Nit": "",
"Nix": "",
"Nu": "text/x-scheme", "Nu": "text/x-scheme",
"NumPy": "text/x-python", "NumPy": "text/x-python",
"OCaml": "text/x-ocaml", "OCaml": "text/x-ocaml",
"ObjDump": "",
"Objective-C": "text/x-objectivec", "Objective-C": "text/x-objectivec",
"Objective-C++": "text/x-objectivec", "Objective-C++": "text/x-objectivec",
"Objective-J": "",
"Omgrofl": "",
"Opa": "",
"Opal": "",
"OpenCL": "text/x-csrc", "OpenCL": "text/x-csrc",
"OpenEdge ABL": "",
"OpenRC runscript": "text/x-sh", "OpenRC runscript": "text/x-sh",
"OpenSCAD": "",
"OpenType Feature File": "",
"Org": "",
"Ox": "",
"Oxygene": "",
"Oz": "text/x-oz", "Oz": "text/x-oz",
"P4": "",
"PAWN": "",
"PHP": "application/x-httpd-php", "PHP": "application/x-httpd-php",
"PLSQL": "text/x-plsql", "PLSQL": "text/x-plsql",
"PLpgSQL": "text/x-sql", "PLpgSQL": "text/x-sql",
"POV-Ray SDL": "",
"Pan": "",
"Papyrus": "",
"Parrot": "",
"Parrot Assembly": "",
"Parrot Internal Representation": "",
"Pascal": "text/x-pascal", "Pascal": "text/x-pascal",
"Pep8": "",
"Perl": "text/x-perl", "Perl": "text/x-perl",
"Perl 6": "text/x-perl", "Perl 6": "text/x-perl",
"Pic": "text/troff", "Pic": "text/troff",
"Pickle": "",
"PicoLisp": "",
"PigLatin": "",
"Pike": "",
"Pod": "text/x-perl", "Pod": "text/x-perl",
"PogoScript": "",
"Pony": "",
"PostScript": "",
"PowerBuilder": "",
"PowerShell": "application/x-powershell", "PowerShell": "application/x-powershell",
"Processing": "",
"Prolog": "",
"Propeller Spin": "",
"Protocol Buffer": "text/x-protobuf", "Protocol Buffer": "text/x-protobuf",
"Public Key": "application/pgp", "Public Key": "application/pgp",
"Pug": "text/x-pug", "Pug": "text/x-pug",
"Puppet": "text/x-puppet", "Puppet": "text/x-puppet",
"Pure Data": "",
"PureBasic": "",
"PureScript": "text/x-haskell", "PureScript": "text/x-haskell",
"Python": "text/x-python", "Python": "text/x-python",
"Python console": "",
"Python traceback": "",
"QML": "",
"QMake": "",
"R": "text/x-rsrc", "R": "text/x-rsrc",
"RAML": "text/x-yaml", "RAML": "text/x-yaml",
"RDoc": "",
"REALbasic": "",
"REXX": "",
"RHTML": "application/x-erb", "RHTML": "application/x-erb",
"RMarkdown": "text/x-gfm", "RMarkdown": "text/x-gfm",
"RPM Spec": "text/x-rpm-spec", "RPM Spec": "text/x-rpm-spec",
"RUNOFF": "",
"Racket": "",
"Ragel": "",
"Rascal": "",
"Raw token data": "",
"Reason": "text/x-rustsrc", "Reason": "text/x-rustsrc",
"Rebol": "",
"Red": "",
"Redcode": "",
"Regular Expression": "",
"Ren'Py": "",
"RenderScript": "",
"Ring": "",
"RobotFramework": "",
"Roff": "text/troff", "Roff": "text/troff",
"Rouge": "text/x-clojure", "Rouge": "text/x-clojure",
"Ruby": "text/x-ruby", "Ruby": "text/x-ruby",
"Rust": "text/x-rustsrc", "Rust": "text/x-rustsrc",
"SAS": "text/x-sas", "SAS": "text/x-sas",
"SCSS": "text/x-scss", "SCSS": "text/x-scss",
"SMT": "",
"SPARQL": "application/sparql-query", "SPARQL": "application/sparql-query",
"SQF": "",
"SQL": "text/x-sql", "SQL": "text/x-sql",
"SQLPL": "text/x-sql", "SQLPL": "text/x-sql",
"SRecode Template": "text/x-common-lisp", "SRecode Template": "text/x-common-lisp",
"STON": "",
"SVG": "text/xml", "SVG": "text/xml",
"Sage": "text/x-python", "Sage": "text/x-python",
"SaltStack": "text/x-yaml", "SaltStack": "text/x-yaml",
"Sass": "text/x-sass", "Sass": "text/x-sass",
"Scala": "text/x-scala", "Scala": "text/x-scala",
"Scaml": "",
"Scheme": "text/x-scheme", "Scheme": "text/x-scheme",
"Scilab": "",
"Self": "",
"ShaderLab": "",
"Shell": "text/x-sh", "Shell": "text/x-sh",
"ShellSession": "text/x-sh", "ShellSession": "text/x-sh",
"Shen": "",
"Slash": "",
"Slim": "text/x-slim", "Slim": "text/x-slim",
"Smali": "",
"Smalltalk": "text/x-stsrc", "Smalltalk": "text/x-stsrc",
"Smarty": "text/x-smarty", "Smarty": "text/x-smarty",
"SourcePawn": "", "Squirrel": "text/x-c++src",
"Spline Font Database": "",
"Squirrel": "text/x-c++src",
"Stan": "",
"Standard ML": "text/x-ocaml", "Standard ML": "text/x-ocaml",
"Stata": "",
"Stylus": "",
"SubRip Text": "",
"Sublime Text Config": "text/javascript", "Sublime Text Config": "text/javascript",
"SuperCollider": "",
"Swift": "text/x-swift", "Swift": "text/x-swift",
"SystemVerilog": "text/x-systemverilog", "SystemVerilog": "text/x-systemverilog",
"TI Program": "",
"TLA": "",
"TOML": "text/x-toml", "TOML": "text/x-toml",
"TXL": "",
"Tcl": "text/x-tcl", "Tcl": "text/x-tcl",
"Tcsh": "text/x-sh", "Tcsh": "text/x-sh",
"TeX": "text/x-stex", "TeX": "text/x-stex",
"Tea": "",
"Terra": "text/x-lua", "Terra": "text/x-lua",
"Text": "",
"Textile": "text/x-textile", "Textile": "text/x-textile",
"Thrift": "",
"Turing": "",
"Turtle": "text/turtle", "Turtle": "text/turtle",
"Twig": "text/x-twig", "Twig": "text/x-twig",
"Type Language": "",
"TypeScript": "application/typescript", "TypeScript": "application/typescript",
"Unified Parallel C": "text/x-csrc", "Unified Parallel C": "text/x-csrc",
"Unity3D Asset": "text/x-yaml", "Unity3D Asset": "text/x-yaml",
"Unix Assembly": "",
"Uno": "text/x-csharp", "Uno": "text/x-csharp",
"UnrealScript": "text/x-java", "UnrealScript": "text/x-java",
"UrWeb": "",
"VCL": "",
"VHDL": "text/x-vhdl", "VHDL": "text/x-vhdl",
"Vala": "",
"Verilog": "text/x-verilog", "Verilog": "text/x-verilog",
"Vim script": "",
"Visual Basic": "text/x-vb", "Visual Basic": "text/x-vb",
"Volt": "text/x-d", "Volt": "text/x-d",
"Vue": "",
"Wavefront Material": "",
"Wavefront Object": "",
"Web Ontology Language": "",
"WebAssembly": "text/x-common-lisp", "WebAssembly": "text/x-common-lisp",
"WebIDL": "text/x-webidl", "WebIDL": "text/x-webidl",
"World of Warcraft Addon Data": "",
"X10": "",
"XC": "text/x-csrc", "XC": "text/x-csrc",
"XCompose": "",
"XML": "text/xml", "XML": "text/xml",
"XPages": "text/xml", "XPages": "text/xml",
"XProc": "text/xml", "XProc": "text/xml",
"XQuery": "application/xquery", "XQuery": "application/xquery",
"XS": "text/x-csrc", "XS": "text/x-csrc",
"XSLT": "text/xml", "XSLT": "text/xml",
"Xojo": "",
"Xtend": "",
"YAML": "text/x-yaml", "YAML": "text/x-yaml",
"YANG": "",
"Yacc": "",
"Zephir": "",
"Zimpl": "",
"desktop": "",
"eC": "",
"edn": "text/x-clojure", "edn": "text/x-clojure",
"fish": "",
"mupad": "",
"nesC": "",
"ooc": "",
"reStructuredText": "text/x-rst", "reStructuredText": "text/x-rst",
"wisp": "text/x-clojure", "wisp": "text/x-clojure",
"xBase": "",
} }

View File

@ -70,6 +70,11 @@ const (
commitGold = "test_files/commit.gold" commitGold = "test_files/commit.gold"
commitTestTmplPath = "../assets/commit.go.tmpl" commitTestTmplPath = "../assets/commit.go.tmpl"
commitTestTmplName = "commit.go.tmpl" commitTestTmplName = "commit.go.tmpl"
// mime test
mimeTypeGold = "test_files/mimeType.gold"
mimeTypeTestTmplPath = "../assets/mimeType.go.tmpl"
mimeTypeTestTmplName = "mimeType.go.tmpl"
) )
type GeneratorTestSuite struct { type GeneratorTestSuite struct {
@ -218,6 +223,16 @@ func (s *GeneratorTestSuite) TestGenerationFiles() {
generate: Commit, generate: Commit,
wantOut: commitGold, wantOut: commitGold,
}, },
{
name: "MimeType()",
fileToParse: filepath.Join(s.tmpLinguist, languagesFile),
samplesDir: "",
tmplPath: mimeTypeTestTmplPath,
tmplName: mimeTypeTestTmplName,
commit: commit,
generate: MimeType,
wantOut: mimeTypeGold,
},
} }
for _, test := range tests { for _, test := range tests {
@ -227,7 +242,6 @@ func (s *GeneratorTestSuite) TestGenerationFiles() {
outPath, err := ioutil.TempFile("/tmp", "generator-test-") outPath, err := ioutil.TempFile("/tmp", "generator-test-")
assert.NoError(s.T(), err) assert.NoError(s.T(), err)
defer os.Remove(outPath.Name()) defer os.Remove(outPath.Name())
err = test.generate(test.fileToParse, test.samplesDir, outPath.Name(), test.tmplPath, test.tmplName, test.commit) err = test.generate(test.fileToParse, test.samplesDir, outPath.Name(), test.tmplPath, test.tmplName, test.commit)
assert.NoError(s.T(), err) assert.NoError(s.T(), err)
out, err := ioutil.ReadFile(outPath.Name()) out, err := ioutil.ReadFile(outPath.Name())

View File

@ -2,9 +2,9 @@ package generator
import ( import (
"bytes" "bytes"
"html/template"
"io" "io"
"io/ioutil" "io/ioutil"
"text/template"
yaml "gopkg.in/yaml.v2" yaml "gopkg.in/yaml.v2"
) )
@ -33,8 +33,10 @@ func MimeType(fileToParse, samplesDir, outPath, tmplPath, tmplName, commit strin
func buildLanguageMimeMap(languages map[string]*languageInfo) map[string]string { func buildLanguageMimeMap(languages map[string]*languageInfo) map[string]string {
langMimeMap := make(map[string]string) langMimeMap := make(map[string]string)
for lang, info := range languages { for lang, info := range languages {
if len(info.MimeType) != 0 {
langMimeMap[lang] = info.MimeType langMimeMap[lang] = info.MimeType
} }
}
return langMimeMap return langMimeMap
} }

View File

@ -0,0 +1,203 @@
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: b6460f8ed6b249281ada099ca28bd8f1230b8892
var LanguagesMime = map[string]string{
"AGS Script": "text/x-c++src",
"APL": "text/apl",
"ASN.1": "text/x-ttcn-asn",
"ASP": "application/x-aspx",
"Alpine Abuild": "text/x-sh",
"Ant Build System": "application/xml",
"Apex": "text/x-java",
"Arduino": "text/x-c++src",
"Brainfuck": "text/x-brainfuck",
"C": "text/x-csrc",
"C#": "text/x-csharp",
"C++": "text/x-c++src",
"C2hs Haskell": "text/x-haskell",
"CMake": "text/x-cmake",
"COBOL": "text/x-cobol",
"COLLADA": "text/xml",
"CSON": "text/x-coffeescript",
"CSS": "text/css",
"ChucK": "text/x-java",
"Clojure": "text/x-clojure",
"Closure Templates": "text/x-soy",
"CoffeeScript": "text/x-coffeescript",
"Common Lisp": "text/x-common-lisp",
"Component Pascal": "text/x-pascal",
"Crystal": "text/x-crystal",
"Cuda": "text/x-c++src",
"Cycript": "text/javascript",
"Cython": "text/x-cython",
"D": "text/x-d",
"DTrace": "text/x-csrc",
"Dart": "application/dart",
"Diff": "text/x-diff",
"Dockerfile": "text/x-dockerfile",
"Dylan": "text/x-dylan",
"EBNF": "text/x-ebnf",
"ECL": "text/x-ecl",
"EQ": "text/x-csharp",
"Eagle": "text/xml",
"Ecere Projects": "application/json",
"Eiffel": "text/x-eiffel",
"Elm": "text/x-elm",
"Emacs Lisp": "text/x-common-lisp",
"EmberScript": "text/x-coffeescript",
"Erlang": "text/x-erlang",
"F#": "text/x-fsharp",
"Factor": "text/x-factor",
"Forth": "text/x-forth",
"Fortran": "text/x-fortran",
"GCC Machine Description": "text/x-common-lisp",
"GN": "text/x-python",
"Game Maker Language": "text/x-c++src",
"Genshi": "text/xml",
"Gentoo Ebuild": "text/x-sh",
"Gentoo Eclass": "text/x-sh",
"Glyph": "text/x-tcl",
"Go": "text/x-go",
"Grammatical Framework": "text/x-haskell",
"Groovy": "text/x-groovy",
"Groovy Server Pages": "application/x-jsp",
"HCL": "text/x-ruby",
"HTML": "text/html",
"HTML+Django": "text/x-django",
"HTML+ECR": "text/html",
"HTML+EEX": "text/html",
"HTML+ERB": "application/x-erb",
"HTML+PHP": "application/x-httpd-php",
"HTTP": "message/http",
"Hack": "application/x-httpd-php",
"Haml": "text/x-haml",
"Haskell": "text/x-haskell",
"Haxe": "text/x-haxe",
"IDL": "text/x-idl",
"INI": "text/x-properties",
"IRC log": "text/mirc",
"JSON": "application/json",
"JSON5": "application/json",
"JSONiq": "application/json",
"JSX": "text/jsx",
"Java": "text/x-java",
"Java Server Pages": "application/x-jsp",
"JavaScript": "text/javascript",
"Julia": "text/x-julia",
"Jupyter Notebook": "application/json",
"Kit": "text/html",
"Kotlin": "text/x-kotlin",
"LFE": "text/x-common-lisp",
"LabVIEW": "text/xml",
"Latte": "text/x-smarty",
"Less": "text/css",
"Literate Haskell": "text/x-literate-haskell",
"LiveScript": "text/x-livescript",
"LookML": "text/x-yaml",
"Lua": "text/x-lua",
"M": "text/x-mumps",
"MTML": "text/html",
"MUF": "text/x-forth",
"Makefile": "text/x-cmake",
"Markdown": "text/x-gfm",
"Marko": "text/html",
"Mathematica": "text/x-mathematica",
"Matlab": "text/x-octave",
"Maven POM": "text/xml",
"Max": "application/json",
"Metal": "text/x-c++src",
"Mirah": "text/x-ruby",
"Modelica": "text/x-modelica",
"NSIS": "text/x-nsis",
"NetLogo": "text/x-common-lisp",
"NewLisp": "text/x-common-lisp",
"Nginx": "text/x-nginx-conf",
"Nu": "text/x-scheme",
"NumPy": "text/x-python",
"OCaml": "text/x-ocaml",
"Objective-C": "text/x-objectivec",
"Objective-C++": "text/x-objectivec",
"OpenCL": "text/x-csrc",
"OpenRC runscript": "text/x-sh",
"Oz": "text/x-oz",
"PHP": "application/x-httpd-php",
"PLSQL": "text/x-plsql",
"PLpgSQL": "text/x-sql",
"Pascal": "text/x-pascal",
"Perl": "text/x-perl",
"Perl6": "text/x-perl",
"Pic": "text/troff",
"Pod": "text/x-perl",
"PowerShell": "application/x-powershell",
"Protocol Buffer": "text/x-protobuf",
"Public Key": "application/pgp",
"Pug": "text/x-pug",
"Puppet": "text/x-puppet",
"PureScript": "text/x-haskell",
"Python": "text/x-python",
"R": "text/x-rsrc",
"RAML": "text/x-yaml",
"RHTML": "application/x-erb",
"RMarkdown": "text/x-gfm",
"RPM Spec": "text/x-rpm-spec",
"Reason": "text/x-rustsrc",
"Roff": "text/troff",
"Rouge": "text/x-clojure",
"Ruby": "text/x-ruby",
"Rust": "text/x-rustsrc",
"SAS": "text/x-sas",
"SCSS": "text/x-scss",
"SPARQL": "application/sparql-query",
"SQL": "text/x-sql",
"SQLPL": "text/x-sql",
"SRecode Template": "text/x-common-lisp",
"SVG": "text/xml",
"Sage": "text/x-python",
"SaltStack": "text/x-yaml",
"Sass": "text/x-sass",
"Scala": "text/x-scala",
"Scheme": "text/x-scheme",
"Shell": "text/x-sh",
"ShellSession": "text/x-sh",
"Slim": "text/x-slim",
"Smalltalk": "text/x-stsrc",
"Smarty": "text/x-smarty",
"Squirrel": "text/x-c++src",
"Standard ML": "text/x-ocaml",
"Sublime Text Config": "text/javascript",
"Swift": "text/x-swift",
"SystemVerilog": "text/x-systemverilog",
"TOML": "text/x-toml",
"Tcl": "text/x-tcl",
"Tcsh": "text/x-sh",
"TeX": "text/x-stex",
"Terra": "text/x-lua",
"Textile": "text/x-textile",
"Turtle": "text/turtle",
"Twig": "text/x-twig",
"TypeScript": "application/typescript",
"Unified Parallel C": "text/x-csrc",
"Unity3D Asset": "text/x-yaml",
"Uno": "text/x-csharp",
"UnrealScript": "text/x-java",
"VHDL": "text/x-vhdl",
"Verilog": "text/x-verilog",
"Visual Basic": "text/x-vb",
"Volt": "text/x-d",
"WebAssembly": "text/x-common-lisp",
"WebIDL": "text/x-webidl",
"XC": "text/x-csrc",
"XML": "text/xml",
"XPages": "text/xml",
"XProc": "text/xml",
"XQuery": "application/xquery",
"XS": "text/x-csrc",
"XSLT": "text/xml",
"YAML": "text/x-yaml",
"edn": "text/x-clojure",
"reStructuredText": "text/x-rst",
"wisp": "text/x-clojure",
}

View File

@ -53,6 +53,15 @@ func IsDocumentation(path string) bool {
return data.DocumentationMatchers.Match(path) return data.DocumentationMatchers.Match(path)
} }
func IsImage(file string) bool {
index := strings.LastIndex(file, ".")
extension := file[index:]
if extension == ".png" || extension == ".jpg" || extension == ".jpeg" || extension == ".gif" {
return true
}
return false
}
func GetMimeType(language string) string { func GetMimeType(language string) string {
if mime, ok := data.LanguagesMime[language]; ok { if mime, ok := data.LanguagesMime[language]; ok {
return mime return mime