img-lint 0.0.6

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 3ff40d7655dee58b777c342aa642c40667eb0684
4
+ data.tar.gz: 4db1488a433af5766342eec9aafd294bd2a0dcaa
5
+ SHA512:
6
+ metadata.gz: 4564a5591f77e2c9171960dd34118e1ce3e5049d2d1d4bd699fa7c96697be7c025be7317f81e6deb8b6894ba93f65bd287a1a2fa9a85a037102dab00372377bb
7
+ data.tar.gz: 94508c881a2c24e43cb0f09d5c44a208b5c5f8f768757ee87ad54c2b098279352c92a79f96533d6d45d81602feb7616db5f8e2b58fa3b2c0a8006f9a2f41d906
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2017 Anatoli Makarevich
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in
13
+ all copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
+ THE SOFTWARE.
@@ -0,0 +1,31 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "img_lint"
4
+ require "img_lint/config"
5
+ require "img_lint/linter"
6
+ require "optparse"
7
+
8
+ options = {}
9
+ OptionParser.new do |opts|
10
+ opts.banner = "Usage: img-lint [options]"
11
+
12
+ opts.on("-p", "--path PATH", "Path to a folder with images") do |v|
13
+ options["path"] = v
14
+ end
15
+
16
+ opts.on("-m", "--max-size MAX_SIZE", "Max image size allowed, '150' by default (150Kb)") do |v|
17
+ options["max_file_size"] = v.to_i
18
+ end
19
+
20
+ opts.on("-f", "--format IMAGE_FORMATS", "Image formats, 'jpg,png,gif' by default") do |v|
21
+ options["image_formats"] = v
22
+ end
23
+ end.parse!
24
+
25
+ config = IMGLint::Config.load
26
+ config.merge!(options)
27
+
28
+ path = config.delete("path")
29
+
30
+ linter = IMGLint::Linter.new(config: config)
31
+ linter.lint(path: path)
@@ -0,0 +1,2 @@
1
+ max_file_size: 150 # Kb
2
+ image_formats: "jpg,png,gif"
@@ -0,0 +1,4 @@
1
+ require "img_lint/constants"
2
+ require "img_lint/linter"
3
+ require "img_lint/version"
4
+ require "img_lint/config"
@@ -0,0 +1,23 @@
1
+ require "yaml"
2
+
3
+ module IMGLint
4
+ class Config
5
+ FILE_NAME = ".img-lint.yml"
6
+ DEFAULT_FILE = File.join(IMG_LINT_HOME, "config", "default.yml")
7
+
8
+ class << self
9
+ def load
10
+ user_config = File.exist?(user_file) ? YAML.load(File.read(user_file)) : {}
11
+ default_config = YAML.load(File.read(DEFAULT_FILE))
12
+
13
+ default_config.merge(user_config)
14
+ end
15
+
16
+ private
17
+
18
+ def user_file
19
+ File.join(Dir.pwd, FILE_NAME)
20
+ end
21
+ end
22
+ end
23
+ end
@@ -0,0 +1,5 @@
1
+ # frozen_string_literal: true
2
+
3
+ module IMGLint
4
+ IMG_LINT_HOME = File.realpath(File.join(File.dirname(__FILE__), '..', '..')).freeze
5
+ end
@@ -0,0 +1,35 @@
1
+ module IMGLint
2
+ class Linter
3
+ attr_accessor :config
4
+
5
+ def initialize(config: {})
6
+ self.config = IMGLint::Config.load.merge(config)
7
+ end
8
+
9
+ def lint(path: Dir.pwd, verbose: true)
10
+ path ||= Dir.pwd
11
+
12
+ max_file_size = config["max_file_size"].to_i
13
+
14
+ images = Dir.glob(%(#{path}/**/*.{#{config["image_formats"]}}))
15
+
16
+ puts "No images found in #{path}" if images.empty?
17
+
18
+ fat_images = images.select do |file|
19
+ File.new(file).size > max_file_size * 1024
20
+ end
21
+
22
+ if fat_images.size > 0 && verbose
23
+ puts "Suspicious images:"
24
+
25
+ fat_images.each do |image|
26
+ file_size = File.new(image).size / 1024
27
+
28
+ puts [image, "#{file_size}Kb"].join("\t")
29
+ end
30
+ end
31
+
32
+ fat_images
33
+ end
34
+ end
35
+ end
@@ -0,0 +1,5 @@
1
+ # frozen_string_literal: true
2
+
3
+ module IMGLint
4
+ VERSION = "0.0.6"
5
+ end
metadata ADDED
@@ -0,0 +1,95 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: img-lint
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.6
5
+ platform: ruby
6
+ authors:
7
+ - Anatoli Makarevich
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2018-03-07 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: bundler
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '1.12'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '1.12'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rake
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '12.3'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '12.3'
41
+ - !ruby/object:Gem::Dependency
42
+ name: rspec
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '3.0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '3.0'
55
+ description: img-lint detects big images in your project
56
+ email:
57
+ - makaroni4@gmail.com
58
+ executables:
59
+ - img-lint
60
+ extensions: []
61
+ extra_rdoc_files: []
62
+ files:
63
+ - LICENSE.txt
64
+ - bin/img-lint
65
+ - config/default.yml
66
+ - lib/img_lint.rb
67
+ - lib/img_lint/config.rb
68
+ - lib/img_lint/constants.rb
69
+ - lib/img_lint/linter.rb
70
+ - lib/img_lint/version.rb
71
+ homepage: https://github.com/makaroni4/img-lint
72
+ licenses:
73
+ - MIT
74
+ metadata: {}
75
+ post_install_message:
76
+ rdoc_options: []
77
+ require_paths:
78
+ - lib
79
+ required_ruby_version: !ruby/object:Gem::Requirement
80
+ requirements:
81
+ - - ">="
82
+ - !ruby/object:Gem::Version
83
+ version: '0'
84
+ required_rubygems_version: !ruby/object:Gem::Requirement
85
+ requirements:
86
+ - - ">="
87
+ - !ruby/object:Gem::Version
88
+ version: '0'
89
+ requirements: []
90
+ rubyforge_project:
91
+ rubygems_version: 2.2.5
92
+ signing_key:
93
+ specification_version: 4
94
+ summary: IMG linter
95
+ test_files: []