image_optim_rails 0.1.0 → 0.2.0

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.
checksums.yaml CHANGED
@@ -1,7 +1,15 @@
1
1
  ---
2
- SHA1:
3
- metadata.gz: 0a27fab3ec29968a0f1461aa69f5d1f3238d2a05
4
- data.tar.gz: 14e3da57b4023c649e9ed3a4874ab5621174c545
2
+ !binary "U0hBMQ==":
3
+ metadata.gz: !binary |-
4
+ NzY1ZDA5MDRkZGQxN2ExYmRlOGE4MzUxZWZlNjZiNmRiY2QxMDlkYg==
5
+ data.tar.gz: !binary |-
6
+ YjFiYzEwZDY1ZWNhMzExM2E3OGZhZDg0MGRjODVhOWRiOTE5M2E2Yg==
5
7
  SHA512:
6
- metadata.gz: ff3b6c95266bbb357df1faab872a7427af1eea240f5d29eeedfd99b8f9b0fbcea8efd01049643c266b6a7822b3c6898ca8c1c8cb97007bd463cee098e4b6b6fe
7
- data.tar.gz: 5a0cc79969ee1ea39c78246e6a9b7f66b6846985749f6e7ffb39a275ed8fc8cd1f14469abee011dd841221e04c33b9b824b4067ddd7d184ef1fe0d5a5d80670e
8
+ metadata.gz: !binary |-
9
+ OTY4ZDFkZWNkYmMxZWQzYTRmNWE4YjlkMTliYzk3ZmVmOGJkNGZlM2Q2NTlj
10
+ ZTJmZjJjMDc1ZjkwYTk2MmFkZGU1MWQ5YmNjOWYzMmE2MWQ0MjgxODZmOGI4
11
+ ZWMzNDE5MDNjNDI4MDYyOGYyY2NkMTIzMjM2MDRhOWViYzNlYWU=
12
+ data.tar.gz: !binary |-
13
+ YjYzNDVmMjMxYzM5N2NmOWYwYzFiY2MxNzk0NWY4NTYyMGU4MWE0YjdhNjcw
14
+ ZmM0YTdiODE1OTNhZDVmZTM2MWEwMGFiMWFkYWY0YzQxYWNmZTI3MTY2NWEz
15
+ NTU1MWJkNTE1NWYyYjlmZDM0MzA0ZDI5ZjUxZmFjMDlhMGRiZDM=
@@ -0,0 +1,11 @@
1
+ # ChangeLog
2
+
3
+ ## unreleased
4
+
5
+ ## v0.2.0 (2016-10-03)
6
+
7
+ * Use railsy config paths `config/image_optim.yml` and `config/image_optim/#{RAILS_ENV}.yml` and cache to `tmp/cache/image_optim` by default [@toy](https://github.com/toy)
8
+
9
+ ## v0.1.0 (2016-08-14)
10
+
11
+ * Extracted from [image_optim gem](https://github.com/toy/image_optim) [toy/image_optim#127](https://github.com/toy/image_optim/issues/127) [@toy](https://github.com/toy)
data/README.markdown CHANGED
@@ -15,13 +15,13 @@ Options and instructions for getting binaries can be found in [image_optim readm
15
15
  Add to your `Gemfile`:
16
16
 
17
17
  ```ruby
18
- gem 'image_optim'
18
+ gem 'image_optim_rails'
19
19
  ```
20
20
 
21
21
  With [`image_optim_pack`](https://github.com/toy/image_optim_pack):
22
22
 
23
23
  ```ruby
24
- gem 'image_optim'
24
+ gem 'image_optim_rails'
25
25
  gem 'image_optim_pack'
26
26
  ```
27
27
 
@@ -34,11 +34,18 @@ You can provide options for image_optim used for preprocessor through config:
34
34
  ```ruby
35
35
  config.assets.image_optim.nice = 20
36
36
  config.assets.image_optim.svgo = false
37
+ config.assets.image_optim.gifsicle.careful = true
37
38
  ```
38
39
 
39
- Check available options in [options section of image_optim](https://github.com/toy/image_optim#options).
40
+ Or through config files `config/image_optim.yml` and `config/image_optim/#{RAILS_ENV}.yml`.
40
41
 
41
- Image optimization can be time consuming, so depending on your deployment process you may prefer to optimize original asset files.
42
+ Caching is enabled by default in directory `tmp/cache/image_optim`.
43
+
44
+ Check all available options in [options section of image_optim](https://github.com/toy/image_optim#options).
45
+
46
+ ## ChangeLog
47
+
48
+ In separate file [CHANGELOG.markdown](CHANGELOG.markdown).
42
49
 
43
50
  ## Copyright
44
51
 
@@ -2,7 +2,7 @@
2
2
 
3
3
  Gem::Specification.new do |s|
4
4
  s.name = 'image_optim_rails'
5
- s.version = '0.1.0'
5
+ s.version = '0.2.0'
6
6
  s.summary = %q{Optimize image assets using image_optim}
7
7
  s.homepage = "http://github.com/toy/#{s.name}"
8
8
  s.authors = ['Ivan Kuchin']
@@ -18,6 +18,7 @@ class ImageOptim
18
18
  hash[key] = ActiveSupport::OrderedOptions.new
19
19
  end
20
20
  end
21
+ app.config.assets.image_optim.merge!(default_options)
21
22
  end
22
23
 
23
24
  initializer 'image_optim.initializer' do |app|
@@ -41,12 +42,22 @@ class ImageOptim
41
42
 
42
43
  def options(app)
43
44
  if app.config.assets.image_optim == true
44
- {}
45
+ default_options
45
46
  else
46
- app.config.assets.image_optim || {}
47
+ app.config.assets.image_optim || default_options
47
48
  end
48
49
  end
49
50
 
51
+ def default_options
52
+ {
53
+ :config_paths => [
54
+ 'config/image_optim.yml',
55
+ "config/image_optim/#{Rails.env}.yml",
56
+ ],
57
+ :cache_dir => 'tmp/cache/image_optim',
58
+ }
59
+ end
60
+
50
61
  def optimize_image_data(data)
51
62
  @image_optim.optimize_image_data(data) || data
52
63
  end
@@ -63,20 +63,35 @@ describe 'ImageOptim::Railtie' do
63
63
  end
64
64
 
65
65
  describe 'options' do
66
- it 'initializes with empty hash by default' do
67
- expect(ImageOptim).to receive(:new).with({})
66
+ let(:default_options) do
67
+ {
68
+ :config_paths => [
69
+ 'config/image_optim.yml',
70
+ 'config/image_optim/xxx.yml',
71
+ ],
72
+ :cache_dir => 'tmp/cache/image_optim',
73
+ }
74
+ end
75
+
76
+ before do
77
+ allow(Rails).to receive(:env).
78
+ and_return(ActiveSupport::StringInquirer.new('xxx'))
79
+ end
80
+
81
+ it 'initializes with defaults' do
82
+ expect(ImageOptim).to receive(:new).with(default_options)
68
83
  init_rails_app
69
84
  end
70
85
 
71
- it 'initializes with empty hash if config.assets.image_optim is true' do
72
- expect(ImageOptim).to receive(:new).with({})
86
+ it 'initializes with defaults if config.assets.image_optim is true' do
87
+ expect(ImageOptim).to receive(:new).with(default_options)
73
88
  init_rails_app do |config|
74
89
  config.assets.image_optim = true
75
90
  end
76
91
  end
77
92
 
78
- it 'initializes with empty hash if config.assets.image_optim is nil' do
79
- expect(ImageOptim).to receive(:new).with({})
93
+ it 'initializes with defaults if config.assets.image_optim is nil' do
94
+ expect(ImageOptim).to receive(:new).with(default_options)
80
95
  init_rails_app do |config|
81
96
  config.assets.image_optim = nil
82
97
  end
@@ -92,7 +107,7 @@ describe 'ImageOptim::Railtie' do
92
107
 
93
108
  it 'is possible to set individual options' do
94
109
  hash = {:config_paths => 'config/image_optim.yml'}
95
- expect(ImageOptim).to receive(:new).with(hash)
110
+ expect(ImageOptim).to receive(:new).with(default_options.merge(hash))
96
111
  init_rails_app do |config|
97
112
  config.assets.image_optim.config_paths = 'config/image_optim.yml'
98
113
  end
@@ -100,7 +115,7 @@ describe 'ImageOptim::Railtie' do
100
115
 
101
116
  it 'is possible to set individual worker options' do
102
117
  hash = {:advpng => {:level => 3}}
103
- expect(ImageOptim).to receive(:new).with(hash)
118
+ expect(ImageOptim).to receive(:new).with(default_options.merge(hash))
104
119
  init_rails_app do |config|
105
120
  expect(config.assets.image_optim.advpng).to eq({})
106
121
  config.assets.image_optim.advpng.level = 3
@@ -108,7 +123,7 @@ describe 'ImageOptim::Railtie' do
108
123
  end
109
124
 
110
125
  it 'is not possible to set unknown worker options' do
111
- expect(ImageOptim).to receive(:new).with({})
126
+ expect(ImageOptim).to receive(:new).with(default_options)
112
127
  init_rails_app do |config|
113
128
  expect(config.assets.image_optim.unknown).to eq(nil)
114
129
  expect do
data/spec/spec_helper.rb CHANGED
@@ -46,12 +46,11 @@ def mepp(image_a, image_b)
46
46
  2>&1
47
47
  ].join(' ')
48
48
  output = ImageOptim::Cmd.capture(command)
49
- if [0, 1].include?($CHILD_STATUS.exitstatus)
50
- num_r = '\d+(?:\.\d+(?:[eE][-+]?\d+)?)?'
51
- output[/\((#{num_r}), #{num_r}\)/, 1].to_f
52
- else
49
+ unless [0, 1].include?($CHILD_STATUS.exitstatus)
53
50
  fail "compare #{image_a} with #{image_b} failed with `#{output}`"
54
51
  end
52
+ num_r = '\d+(?:\.\d+(?:[eE][-+]?\d+)?)?'
53
+ output[/\((#{num_r}), #{num_r}\)/, 1].to_f
55
54
  end
56
55
 
57
56
  RSpec::Matchers.define :be_smaller_than do |expected|
metadata CHANGED
@@ -1,114 +1,101 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: image_optim_rails
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Ivan Kuchin
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2016-08-14 00:00:00.000000000 Z
11
+ date: 2016-10-02 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: image_optim
15
15
  requirement: !ruby/object:Gem::Requirement
16
16
  requirements:
17
- - - "~>"
17
+ - - ~>
18
18
  - !ruby/object:Gem::Version
19
19
  version: 0.24.0
20
20
  type: :runtime
21
21
  prerelease: false
22
22
  version_requirements: !ruby/object:Gem::Requirement
23
23
  requirements:
24
- - - "~>"
24
+ - - ~>
25
25
  - !ruby/object:Gem::Version
26
26
  version: 0.24.0
27
27
  - !ruby/object:Gem::Dependency
28
28
  name: rails
29
29
  requirement: !ruby/object:Gem::Requirement
30
30
  requirements:
31
- - - ">="
31
+ - - ! '>='
32
32
  - !ruby/object:Gem::Version
33
33
  version: '0'
34
34
  type: :runtime
35
35
  prerelease: false
36
36
  version_requirements: !ruby/object:Gem::Requirement
37
37
  requirements:
38
- - - ">="
38
+ - - ! '>='
39
39
  - !ruby/object:Gem::Version
40
40
  version: '0'
41
41
  - !ruby/object:Gem::Dependency
42
42
  name: sprockets
43
43
  requirement: !ruby/object:Gem::Requirement
44
44
  requirements:
45
- - - ">="
45
+ - - ! '>='
46
46
  - !ruby/object:Gem::Version
47
47
  version: '0'
48
48
  type: :runtime
49
49
  prerelease: false
50
50
  version_requirements: !ruby/object:Gem::Requirement
51
51
  requirements:
52
- - - ">="
52
+ - - ! '>='
53
53
  - !ruby/object:Gem::Version
54
54
  version: '0'
55
55
  - !ruby/object:Gem::Dependency
56
56
  name: image_optim_pack
57
57
  requirement: !ruby/object:Gem::Requirement
58
58
  requirements:
59
- - - "~>"
59
+ - - ~>
60
60
  - !ruby/object:Gem::Version
61
61
  version: '0.2'
62
- - - ">="
62
+ - - ! '>='
63
63
  - !ruby/object:Gem::Version
64
64
  version: 0.2.2
65
65
  type: :development
66
66
  prerelease: false
67
67
  version_requirements: !ruby/object:Gem::Requirement
68
68
  requirements:
69
- - - "~>"
69
+ - - ~>
70
70
  - !ruby/object:Gem::Version
71
71
  version: '0.2'
72
- - - ">="
72
+ - - ! '>='
73
73
  - !ruby/object:Gem::Version
74
74
  version: 0.2.2
75
75
  - !ruby/object:Gem::Dependency
76
76
  name: rspec
77
77
  requirement: !ruby/object:Gem::Requirement
78
78
  requirements:
79
- - - "~>"
79
+ - - ~>
80
80
  - !ruby/object:Gem::Version
81
81
  version: '3.0'
82
82
  type: :development
83
83
  prerelease: false
84
84
  version_requirements: !ruby/object:Gem::Requirement
85
85
  requirements:
86
- - - "~>"
86
+ - - ~>
87
87
  - !ruby/object:Gem::Version
88
88
  version: '3.0'
89
- - !ruby/object:Gem::Dependency
90
- name: rubocop
91
- requirement: !ruby/object:Gem::Requirement
92
- requirements:
93
- - - "~>"
94
- - !ruby/object:Gem::Version
95
- version: '0.37'
96
- type: :development
97
- prerelease: false
98
- version_requirements: !ruby/object:Gem::Requirement
99
- requirements:
100
- - - "~>"
101
- - !ruby/object:Gem::Version
102
- version: '0.37'
103
89
  description:
104
90
  email:
105
91
  executables: []
106
92
  extensions: []
107
93
  extra_rdoc_files: []
108
94
  files:
109
- - ".gitignore"
110
- - ".rubocop.yml"
111
- - ".travis.yml"
95
+ - .gitignore
96
+ - .rubocop.yml
97
+ - .travis.yml
98
+ - CHANGELOG.markdown
112
99
  - Gemfile
113
100
  - LICENSE.txt
114
101
  - README.markdown
@@ -127,12 +114,12 @@ require_paths:
127
114
  - lib
128
115
  required_ruby_version: !ruby/object:Gem::Requirement
129
116
  requirements:
130
- - - ">="
117
+ - - ! '>='
131
118
  - !ruby/object:Gem::Version
132
119
  version: '0'
133
120
  required_rubygems_version: !ruby/object:Gem::Requirement
134
121
  requirements:
135
- - - ">="
122
+ - - ! '>='
136
123
  - !ruby/object:Gem::Version
137
124
  version: '0'
138
125
  requirements: []
@@ -144,3 +131,4 @@ summary: Optimize image assets using image_optim
144
131
  test_files:
145
132
  - spec/image_optim/railtie_spec.rb
146
133
  - spec/spec_helper.rb
134
+ has_rdoc: