Bring in @upsuper's css generated check

This commit is contained in:
Ted Nyman
2013-08-05 23:00:04 -07:00
4 changed files with 7196 additions and 8 deletions

View File

@@ -52,7 +52,7 @@ module Linguist
# Return true or false
def generated?
name == 'Gemfile.lock' ||
minified_javascript? ||
minified_files? ||
compiled_coffeescript? ||
xcode_project_file? ||
generated_parser? ||
@@ -71,16 +71,16 @@ 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 it contains more than 5% spaces.
# 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
def minified_files?
return unless ['.js', '.css'].include? extname
if data && data.length > 200
(data.each_char.count{ |c| c <= ' ' } / data.length.to_f) < 0.05
else
false
end

6307
samples/CSS/bootstrap.css vendored Normal file

File diff suppressed because it is too large Load Diff

873
samples/CSS/bootstrap.min.css vendored Normal file

File diff suppressed because one or more lines are too long

View File

@@ -197,6 +197,14 @@ class TestBlob < Test::Unit::TestCase
assert blob("C++/protocol-buffer.pb.cc").generated?
assert blob("Java/ProtocolBuffer.java").generated?
assert blob("Python/protocol_buffer_pb2.py").generated?
# Minified CSS
assert !blob("CSS/bootstrap.css").generated?
assert blob("CSS/bootstrap.min.css").generated?
# Cython-generated C/C++
assert blob("C/sgd_fast.c").generated?
assert blob("C++/wrapper_inner.cpp").generated?
end
def test_vendored