lib/rouge/guessers/glob_mapping.rb in rouge-2.2.1 vs lib/rouge/guessers/glob_mapping.rb in rouge-3.0.0
- old
+ new
@@ -1,10 +1,12 @@
module Rouge
module Guessers
# This class allows for custom behavior
# with glob -> lexer name mappings
class GlobMapping < Guesser
+ include Util
+
def self.by_pairs(mapping, filename)
glob_map = {}
mapping.each do |(glob, lexer_name)|
lexer = Lexer.find(lexer_name)
@@ -27,20 +29,15 @@
def filter(lexers)
basename = File.basename(filename)
collect_best(lexers) do |lexer|
score = (@glob_map[lexer.name] || []).map do |pattern|
- if test_pattern(pattern, basename)
+ if test_glob(pattern, basename)
# specificity is better the fewer wildcards there are
-pattern.scan(/[*?\[]/).size
end
end.compact.min
end
- end
-
- private
- def test_pattern(pattern, path)
- File.fnmatch?(pattern, path, File::FNM_DOTMATCH | File::FNM_CASEFOLD)
end
end
end
end