diff --git a/Gemfile b/Gemfile index 851fabc2..3df9dcfc 100644 --- a/Gemfile +++ b/Gemfile @@ -1,2 +1,7 @@ source 'https://rubygems.org' gemspec + +if RUBY_VERSION < "1.9.3" + # escape_utils 1.0.0 requires 1.9.3 and above + gem "escape_utils", "0.3.2" +end diff --git a/Rakefile b/Rakefile index 08ce419b..0b3d16a4 100644 --- a/Rakefile +++ b/Rakefile @@ -1,5 +1,7 @@ require 'rake/clean' require 'rake/testtask' +require 'yaml' +require 'json' task :default => :test @@ -13,6 +15,13 @@ task :samples do File.open('lib/linguist/samples.json', 'w') { |io| io.write json } end +task :build_gem do + languages = YAML.load_file("lib/linguist/languages.yml") + File.write("lib/linguist/languages.json", JSON.dump(languages)) + `gem build github-linguist.gemspec` + File.delete("lib/linguist/languages.json") +end + namespace :classifier do LIMIT = 1_000 diff --git a/github-linguist.gemspec b/github-linguist.gemspec index 33d9fed1..26bded1b 100644 --- a/github-linguist.gemspec +++ b/github-linguist.gemspec @@ -1,6 +1,6 @@ Gem::Specification.new do |s| s.name = 'github-linguist' - s.version = '2.9.8' + s.version = '2.10.0' s.summary = "GitHub Language detection" s.authors = "GitHub" @@ -10,10 +10,10 @@ Gem::Specification.new do |s| s.executables << 'linguist' s.add_dependency 'charlock_holmes', '~> 0.6.6' - s.add_dependency 'escape_utils', '~> 0.3.1' + s.add_dependency 'escape_utils', '>= 0.3.1' s.add_dependency 'mime-types', '~> 1.19' - s.add_dependency 'pygments.rb', '~> 0.5.2' - + s.add_dependency 'pygments.rb', '~> 0.5.4' + s.add_development_dependency 'json' s.add_development_dependency 'mocha' s.add_development_dependency 'rake' diff --git a/lib/linguist/language.rb b/lib/linguist/language.rb index a8dc8f9f..69d20bc0 100644 --- a/lib/linguist/language.rb +++ b/lib/linguist/language.rb @@ -1,6 +1,10 @@ require 'escape_utils' require 'pygments' require 'yaml' +begin + require 'json' +rescue LoadError +end require 'linguist/classifier' require 'linguist/samples' @@ -455,7 +459,16 @@ module Linguist filenames = Samples::DATA['filenames'] popular = YAML.load_file(File.expand_path("../popular.yml", __FILE__)) - YAML.load_file(File.expand_path("../languages.yml", __FILE__)).each do |name, options| + languages_yml = File.expand_path("../languages.yml", __FILE__) + languages_json = File.expand_path("../languages.json", __FILE__) + + if File.exist?(languages_json) && defined?(JSON) + languages = JSON.load(File.read(languages_json)) + else + languages = YAML.load_file(languages_yml) + end + + languages.each do |name, options| options['extensions'] ||= [] options['filenames'] ||= [] diff --git a/lib/linguist/languages.yml b/lib/linguist/languages.yml index c963d2cd..ea20d55b 100644 --- a/lib/linguist/languages.yml +++ b/lib/linguist/languages.yml @@ -70,6 +70,7 @@ Ada: Agda: type: programming + color: "#467C91" primary_extension: .agda ApacheConf: @@ -384,7 +385,7 @@ D-ObjDump: DM: type: programming color: "#075ff1" - lexer: Text only + lexer: C++ primary_extension: .dm aliases: - byond @@ -752,6 +753,8 @@ JSON: - .sublime_session - .sublime-settings - .sublime-workspace + filenames: + - composer.lock Jade: group: HTML @@ -947,15 +950,17 @@ Matlab: Max: type: programming color: "#ce279c" - lexer: Text only + lexer: JSON aliases: - max/msp - maxmsp search_term: max/msp - primary_extension: .mxt + primary_extension: .maxpat extensions: - .maxhelp - - .maxpat + - .maxproj + - .mxt + - .pat MiniD: # Legacy searchable: false @@ -1478,6 +1483,7 @@ Tcsh: TeX: type: markup + color: "#3D6117" ace_mode: latex aliases: - latex @@ -1545,6 +1551,14 @@ VHDL: lexer: vhdl color: "#543978" primary_extension: .vhdl + extensions: + - .vhd + - .vhf + - .vhi + - .vho + - .vhs + - .vht + - .vhw Vala: type: programming @@ -1616,6 +1630,7 @@ XML: - .grxml - .jelly - .kml + - .launch - .mxml - .plist - .pluginspec @@ -1625,6 +1640,7 @@ XML: - .rdf - .rss - .scxml + - .srdf - .svg - .tmCommand - .tmLanguage @@ -1633,12 +1649,14 @@ XML: - .tmTheme - .tml - .ui + - .urdf - .vxml - .wsdl - .wxi - .wxl - .wxs - .x3d + - .xacro - .xaml - .xlf - .xliff @@ -1691,6 +1709,7 @@ YAML: primary_extension: .yml extensions: - .reek + - .rviz - .yaml eC: diff --git a/lib/linguist/samples.json b/lib/linguist/samples.json index 7f0f7682..1c37ea3b 100644 --- a/lib/linguist/samples.json +++ b/lib/linguist/samples.json @@ -152,9 +152,7 @@ ".script!" ], "JSON": [ - ".json", - ".maxhelp", - ".maxpat" + ".json" ], "Julia": [ ".jl" @@ -208,6 +206,8 @@ ".m" ], "Max": [ + ".maxhelp", + ".maxpat", ".mxt" ], "Monkey": [ @@ -23186,10 +23186,10 @@ "logger": 2 }, "JSON": { - "{": 143, - "}": 143, - "[": 165, - "]": 165, + "{": 17, + "}": 17, + "[": 2, + "]": 2, "true": 3 }, "Julia": { @@ -28521,6 +28521,10 @@ "contents.colheaders": 1 }, "Max": { + "{": 126, + "}": 126, + "[": 163, + "]": 163, "max": 1, "v2": 1, ";": 39, @@ -43668,7 +43672,7 @@ "Jade": 3, "Java": 8987, "JavaScript": 76934, - "JSON": 619, + "JSON": 41, "Julia": 247, "Kotlin": 155, "KRL": 25, @@ -43685,7 +43689,7 @@ "Makefile": 50, "Markdown": 1, "Matlab": 11942, - "Max": 136, + "Max": 714, "Monkey": 207, "MoonScript": 1718, "Nemerle": 17, @@ -43795,7 +43799,7 @@ "Jade": 1, "Java": 6, "JavaScript": 20, - "JSON": 5, + "JSON": 3, "Julia": 1, "Kotlin": 1, "KRL": 1, @@ -43812,7 +43816,7 @@ "Makefile": 2, "Markdown": 1, "Matlab": 39, - "Max": 1, + "Max": 3, "Monkey": 1, "MoonScript": 1, "Nemerle": 1, @@ -43877,5 +43881,5 @@ "Xtend": 2, "YAML": 1 }, - "md5": "d77910fe214f3654d7538485c7388f89" + "md5": "647da23cd1eb02653f50ff9bfbb6e70d" } \ No newline at end of file diff --git a/lib/linguist/samples.rb b/lib/linguist/samples.rb index d9099385..c623d7d5 100644 --- a/lib/linguist/samples.rb +++ b/lib/linguist/samples.rb @@ -1,4 +1,8 @@ -require 'yaml' +begin + require 'json' +rescue LoadError + require 'yaml' +end require 'linguist/md5' require 'linguist/classifier' @@ -14,7 +18,8 @@ module Linguist # Hash of serialized samples object if File.exist?(PATH) - DATA = YAML.load_file(PATH) + serializer = defined?(JSON) ? JSON : YAML + DATA = serializer.load(File.read(PATH)) end # Public: Iterate over each sample. diff --git a/samples/JSON/Hello.maxhelp b/samples/Max/Hello.maxhelp similarity index 100% rename from samples/JSON/Hello.maxhelp rename to samples/Max/Hello.maxhelp diff --git a/samples/JSON/Hello.maxpat b/samples/Max/Hello.maxpat similarity index 100% rename from samples/JSON/Hello.maxpat rename to samples/Max/Hello.maxpat