From 4398cda9a5a4dbca30551a656d6e4816e11f7034 Mon Sep 17 00:00:00 2001 From: Xidorn Quan Date: Fri, 1 Mar 2013 16:15:56 +0800 Subject: [PATCH] Detect minified CSS files --- lib/linguist/generated.rb | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/lib/linguist/generated.rb b/lib/linguist/generated.rb index 534ed798..4bbea954 100644 --- a/lib/linguist/generated.rb +++ b/lib/linguist/generated.rb @@ -53,6 +53,7 @@ module Linguist def generated? name == 'Gemfile.lock' || minified_javascript? || + minified_css? || compiled_coffeescript? || xcode_project_file? || generated_net_docfile? || @@ -85,6 +86,21 @@ module Linguist 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' + if lines.any? + (lines.inject(0) { |n, l| n += l.length } / lines.length) > 100 + else + false + end + end + # Internal: Is the blob of JS generated by CoffeeScript? # # CoffeeScript is meant to output JS that would be difficult to