ettu 4.0.1 → 4.1.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 5e7f2d1c82ca3de9107655ad10c97f35e61e889e
4
- data.tar.gz: 62f6065fcd7396e83cab33ff66832569e9893123
3
+ metadata.gz: 77b8d4f4b477b8edc976372932b5e5c84c75635c
4
+ data.tar.gz: 9505d69bf31f7ea30f4db5912aabd803a86a7863
5
5
  SHA512:
6
- metadata.gz: 157bffb71c9ebc1d95725b1e172873189132d492e84e5387936d95fb5a8930849bf902ccb73427a48d10ad6abd7447014e184863c84a4603984e7fd17332dfc2
7
- data.tar.gz: 7aefae5a7a637a7340cf55f4fc3d5564820ad0cb846f9077ef8ff17435792e24a031c9255bb92936ea801cc98088896d45323848c2cbe8d5a42936fbafc89b52
6
+ metadata.gz: 2e723799e1ba4d0aea18841debb13e044d8c053adeb1f2e26e06cabfc177873f71ad3927ffdb861df03747e4ead98712d60e590e47d47aa3cdad69f0d3d45af5
7
+ data.tar.gz: 196e27ab26d3ed7fad871478434303d7d2bdf07095d8be17634eaf75a614d084e40877c284119f16319747f8a311a3091db6ec47ecbb2dd04ce381e8f4ceb47e
data/README.md CHANGED
@@ -16,6 +16,12 @@ all of this while allowing you to use the same syntax you're already
16
16
  accustomed to. So keep doing what you're doing, and let Ettu worry about
17
17
  changes to your view code.
18
18
 
19
+ ### Rails 3
20
+
21
+ Have a Rails 3 project? The [v3 branch]
22
+ (https://github.com/cloudspace/ettu/tree/v3) (and 3.* releases) are set
23
+ up to support it.
24
+
19
25
  Installation
20
26
  ------------
21
27
 
@@ -45,10 +51,9 @@ end
45
51
  ```
46
52
 
47
53
  Ettu wants you to keep using either syntax, and let it worry about the
48
- view code. By default, it will add in the asset fingerprints of
49
- `application.js` and `application.css` along with the cache digest of
50
- the current action into the calculation for the final ETag sent to the
51
- browser.
54
+ view code. By default, it will add in the fingerprints of your
55
+ precompiled assets along with the cache digest of the current action
56
+ into the calculation for the final ETag sent to the browser.
52
57
 
53
58
  ### Configuring
54
59
 
@@ -67,34 +72,24 @@ Of course, you can override Ettu's default behavior:
67
72
  ```ruby
68
73
  # config/initializers/ettu.rb
69
74
  Ettu.configure do |config|
70
- # Set the default js file
71
- config.js = 'app.js'
72
- # Or don't account for javascript
73
- # config.js = false
74
-
75
- # Set the default css file
76
- config.css = 'style.css'
77
- # Or don't account for css
78
- # config.css = false
79
-
80
75
  # Add in extra assets to account for
81
- config.assets = ['first.js', 'second.css']
76
+ config.assets += ['first.js', 'second.css']
82
77
  end
83
78
  ```
84
79
 
85
80
  Or each can be passed on an individual basis:
86
81
 
87
- fresh_when @product, js: 'app.js', css: 'style.css', assets: 'super.css'
82
+ fresh_when @product, assets: 'super.css'
88
83
 
89
84
  Additionally, you can specify a different template to calculate with the
90
85
  `view` option:
91
86
 
92
- fresh_when @product, view: "products/index"
87
+ fresh_when @product, view: 'products/index'
93
88
 
94
89
  You can even stop Ettu from accounting for any of them by setting the
95
90
  value to `false`:
96
91
 
97
- fresh_when @product, js: false, css: false, view: false
92
+ fresh_when @product, assets: false, view: false
98
93
 
99
94
  ### What about Rails' default `fresh_when`?
100
95
 
data/ROADMAP.md CHANGED
@@ -6,4 +6,4 @@ Ettu Roadmap
6
6
  - Separate gem into branches
7
7
  - v3 branch will track Rails 3
8
8
  - v4 branch will track Rails 4
9
- - [ ] Default assets to those set in Rails.application.config.assets.precompile
9
+ - [x] Default assets to those set in Rails.application.config.assets
@@ -13,9 +13,7 @@ class Ettu
13
13
  private
14
14
 
15
15
  def set_defaults
16
- self.js = 'application.js'
17
- self.css = 'application.css'
18
- self.assets = []
16
+ self.assets = LateLoadAssets.new
19
17
 
20
18
  # Don't actually set view by default.
21
19
  # This'll allow #fetch to return the real default
@@ -23,10 +21,20 @@ class Ettu
23
21
  # self.view = "#{controller_name}/#{action_name}"
24
22
  delete :view if key? :view
25
23
 
26
- # Don't attempt to reset the template_digestor
27
- # if one has already been found
28
- unless self.template_digestor
29
- self.template_digestor = LateLoadTemplateDigestor.new(self)
24
+ self.template_digestor = LateLoadTemplateDigestor.new(self)
25
+ end
26
+
27
+ class LateLoadAssets
28
+ def initialize
29
+ @array = []
30
+ end
31
+
32
+ def to_a
33
+ ::ActionView::Base.assets_manifest.assets.keys + [*@array]
34
+ end
35
+
36
+ def method_missing(method, *args, &block)
37
+ @array.send method, *args, &block
30
38
  end
31
39
  end
32
40
 
@@ -3,18 +3,18 @@ class Ettu
3
3
  extend ActiveSupport::Concern
4
4
 
5
5
  included do
6
- alias_method :old_fresh_when, :fresh_when
6
+ alias_method_chain :fresh_when, :ettu
7
+ end
7
8
 
8
- def fresh_when(record_or_options, additional_options = {})
9
- ettu = ettu_instance(record_or_options, additional_options, self)
9
+ private
10
10
 
11
- ettu_params = {etag: ettu.etags, last_modified: ettu.last_modified}
11
+ def fresh_when_with_ettu(record_or_options, additional_options = {})
12
+ ettu = ettu_instance(record_or_options, additional_options, self)
12
13
 
13
- old_fresh_when nil, ettu.options.merge(ettu_params)
14
- end
15
- end
14
+ ettu_params = {etag: ettu.etags, last_modified: ettu.last_modified}
16
15
 
17
- private
16
+ fresh_when_without_ettu nil, ettu.options.merge(ettu_params)
17
+ end
18
18
 
19
19
  def ettu_instance(record_or_options, additional_options, controller)
20
20
  Ettu.new record_or_options, additional_options, controller
data/lib/ettu/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  class Ettu
2
- VERSION = '4.0.1'
2
+ VERSION = '4.1.0'
3
3
  end
data/lib/ettu.rb CHANGED
@@ -2,6 +2,7 @@ require 'active_support/concern'
2
2
  require 'active_support/ordered_options'
3
3
  require 'active_support/core_ext/object/blank'
4
4
  require 'active_support/core_ext/object/try'
5
+ require 'active_support/core_ext/module/aliasing'
5
6
 
6
7
  require 'ettu/version'
7
8
  require 'ettu/configuration'
@@ -32,11 +33,8 @@ class Ettu
32
33
  def etags
33
34
  etags = [*response_etag]
34
35
  etags << view_etag
35
- if @controller.request.format.try(:html?)
36
- etags << js_etag
37
- etags << css_etag
38
- end
39
36
  etags.concat asset_etags
37
+ etags.compact
40
38
  end
41
39
 
42
40
  def last_modified
@@ -53,16 +51,6 @@ class Ettu
53
51
  @view_etag ||= view_digest(view)
54
52
  end
55
53
 
56
- def js_etag
57
- js = @options.fetch(:js, @@config.js)
58
- asset_etag js
59
- end
60
-
61
- def css_etag
62
- css = @options.fetch(:css, @@config.css)
63
- asset_etag css
64
- end
65
-
66
54
  def asset_etags
67
55
  assets = @options.fetch(:assets, @@config.assets)
68
56
  [*assets].map { |asset| asset_etag(asset) }
data/spec/ettu_spec.rb CHANGED
@@ -4,21 +4,13 @@ describe Ettu do
4
4
  let(:controller) { Controller.new }
5
5
  let(:record) { Record.new(DateTime.now) }
6
6
  let(:hash) { { etag: record, last_modified: DateTime.now } }
7
- before(:all) do
8
- Ettu.configure { |config| config.template_digestor = Digestor }
9
- end
10
7
 
11
8
  context 'when supplied with options' do
12
- let(:hash) { { js: 'custom.js', css: 'custom.css', assets: 'first.ext', view: 'custom/action' } }
13
- subject(:ettu) { Ettu.new(hash, {}, controller) }
14
-
15
- it 'will use :js option over default' do
16
- expect(ettu.js_etag).to eq('custom.js.digest')
17
- end
18
-
19
- it 'will use :css option over default' do
20
- expect(ettu.css_etag).to eq('custom.css.digest')
9
+ before(:all) do
10
+ Ettu.configure { |config| config.template_digestor = Digestor }
21
11
  end
12
+ let(:hash) { { assets: 'first.ext', view: 'custom/action' } }
13
+ subject(:ettu) { Ettu.new(hash, {}, controller) }
22
14
 
23
15
  it 'will use :asset option over default' do
24
16
  expect(ettu.asset_etags).to eq(['first.ext.digest'])
@@ -31,26 +23,19 @@ describe Ettu do
31
23
 
32
24
  describe '.configure' do
33
25
  subject(:ettu) { Ettu.new(nil, {}, controller) }
26
+ before(:all) do
27
+ Ettu.configure { |config| config.template_digestor = Digestor }
28
+ end
34
29
  after(:all) { Ettu.configure { |config| config.reset } }
35
30
 
36
31
  context 'when no options are specified' do
37
32
  before(:all) do
38
33
  Ettu.configure do |config|
39
- config.js = 'custom.js'
40
- config.css = 'custom.css'
41
34
  config.assets = ['first.ext', 'second.ext']
42
35
  config.view = 'custom/view'
43
36
  end
44
37
  end
45
38
 
46
- it 'will use the default js file' do
47
- expect(ettu.js_etag).to eq('custom.js.digest')
48
- end
49
-
50
- it 'will use the default css file' do
51
- expect(ettu.css_etag).to eq('custom.css.digest')
52
- end
53
-
54
39
  it 'will use the default asset files' do
55
40
  expect(ettu.asset_etags).to eq(['first.ext.digest', 'second.ext.digest'])
56
41
  end
@@ -60,21 +45,31 @@ describe Ettu do
60
45
  end
61
46
  end
62
47
 
48
+ context 'can append additional assets' do
49
+ let(:configuration) { Ettu::Configuration.new }
50
+ let(:random_string) { RandomString.rand }
51
+
52
+ it 'with +=' do
53
+ configuration.assets += [random_string]
54
+ expect(configuration.assets).to include(random_string)
55
+ end
56
+
57
+ it 'with <<' do
58
+ configuration.assets << random_string
59
+ expect(configuration.assets).to include(random_string)
60
+ end
61
+ end
62
+
63
63
  context 'when setting default to false' do
64
64
  before(:all) do
65
65
  Ettu.configure do |config|
66
- config.js = false
67
- config.css = false
66
+ config.assets = false
68
67
  config.view = false
69
68
  end
70
69
  end
71
70
 
72
- it 'will disable js etag' do
73
- expect(ettu.js_etag).to eq(nil)
74
- end
75
-
76
- it 'will disable css etag' do
77
- expect(ettu.css_etag).to eq(nil)
71
+ it 'will disable asset etags' do
72
+ expect(ettu.asset_etags).to eq([nil])
78
73
  end
79
74
 
80
75
  it 'will disable view etags' do
@@ -84,13 +79,27 @@ describe Ettu do
84
79
  end
85
80
 
86
81
  describe '#etags' do
82
+ before(:all) do
83
+ Ettu.configure { |config| config.template_digestor = Digestor }
84
+ end
87
85
  let(:ettu) { Ettu.new(record, {}, controller) }
86
+
88
87
  it 'will collect all etags' do
89
- expected = [record, 'controller_name/action_name.digest', 'application.js.digest', 'application.css.digest']
88
+ expected = [
89
+ record, 'controller_name/action_name.digest',
90
+ 'application.js.manifest', 'application.css.manifest',
91
+ 'custom.js.manifest', 'custom.css.manifest',
92
+ 'first.ext.manifest', 'second.ext.manifest'
93
+ ]
90
94
  result = ettu.etags
91
- expect(ettu.etags).to include(*expected)
95
+ expect(result).to include(*expected)
92
96
  expect(expected).to include(*result)
93
97
  end
98
+
99
+ it 'will not allow nils' do
100
+ ettu = Ettu.new(nil, {assets: [nil, nil, nil]}, controller )
101
+ expect(ettu.etags).not_to include(nil)
102
+ end
94
103
  end
95
104
 
96
105
  context 'when given only a record' do
data/spec/fixtures.rb CHANGED
@@ -57,5 +57,14 @@ module ActionView
57
57
  end
58
58
  end
59
59
  end
60
- ActionView::Base.assets_manifest.assets = {}
60
+ ActionView::Base.assets_manifest.assets = Rails.application.assets.keys.reduce({}) do |hash, asset|
61
+ hash[asset] = asset.to_s + '.manifest'
62
+ hash
63
+ end
61
64
 
65
+ class RandomString
66
+ @@letters = ('a'..'z').to_a
67
+ def self.rand(length = 50)
68
+ (0...length).map{ @@letters.sample }.join
69
+ end
70
+ end
@@ -29,14 +29,14 @@ describe Ettu::FreshWhen do
29
29
  end
30
30
 
31
31
  it 'passes nil as the first argument to original fresh_when' do
32
- controller.should_receive(:old_fresh_when) do |r, h|
32
+ controller.should_receive(:fresh_when_without_ettu) do |r, h|
33
33
  r.nil?
34
34
  end
35
35
  controller.fresh_when record, hash
36
36
  end
37
37
 
38
38
  it 'passes extra options to original fresh_when' do
39
- controller.should_receive(:old_fresh_when) do |r, h|
39
+ controller.should_receive(:fresh_when_without_ettu) do |r, h|
40
40
  hash.each_pair.all? do |k, v|
41
41
  h[k] == v
42
42
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: ettu
3
3
  version: !ruby/object:Gem::Version
4
- version: 4.0.1
4
+ version: 4.1.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Justin Ridgewell
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2013-07-01 00:00:00.000000000 Z
11
+ date: 2013-07-09 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rails