From 806369ce7f5a2307e66194ca6f0ba161ae74d579 Mon Sep 17 00:00:00 2001 From: Xidorn Quan Date: Fri, 1 Mar 2013 20:50:49 +0800 Subject: [PATCH] Merge minified files detecting methods. --- lib/linguist/generated.rb | 29 +++++++---------------------- 1 file changed, 7 insertions(+), 22 deletions(-) diff --git a/lib/linguist/generated.rb b/lib/linguist/generated.rb index 4bbea954..ebf24a9f 100644 --- a/lib/linguist/generated.rb +++ b/lib/linguist/generated.rb @@ -52,8 +52,7 @@ module Linguist # Return true or false def generated? name == 'Gemfile.lock' || - minified_javascript? || - minified_css? || + minified_files? || compiled_coffeescript? || xcode_project_file? || generated_net_docfile? || @@ -71,29 +70,15 @@ module Linguist ['.xib', '.nib', '.storyboard', '.pbxproj', '.xcworkspacedata', '.xcuserstate'].include?(extname) end - # Internal: Is the blob minified JS? + # Internal: Is the blob minified files? # - # Consider JS minified if the average line length is - # greater then 100c. + # Consider a file minified if the average line length is + # greater then 100c. Currently only JS and CSS files are + # detected by this method. # # Returns true or false. - def minified_javascript? - return unless extname == '.js' - if lines.any? - (lines.inject(0) { |n, l| n += l.length } / lines.length) > 100 - else - false - end - end - - # Internal: Is the blob minified CSS? - # - # Consider CSS minified if the average line length is - # greater than 100c. - # - # Returns true or false. - def minified_css? - return unless extname == '.css' + def minified_files? + return unless ['.js', '.css'].include? extname if lines.any? (lines.inject(0) { |n, l| n += l.length } / lines.length) > 100 else