ettu 4.0.1 → 4.1.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 +4 -4
- data/README.md +13 -18
- data/ROADMAP.md +1 -1
- data/lib/ettu/configuration.rb +15 -7
- data/lib/ettu/fresh_when.rb +8 -8
- data/lib/ettu/version.rb +1 -1
- data/lib/ettu.rb +2 -14
- data/spec/ettu_spec.rb +41 -32
- data/spec/fixtures.rb +10 -1
- data/spec/fresh_when_spec.rb +2 -2
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 77b8d4f4b477b8edc976372932b5e5c84c75635c
|
4
|
+
data.tar.gz: 9505d69bf31f7ea30f4db5912aabd803a86a7863
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
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
|
49
|
-
|
50
|
-
|
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
|
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,
|
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:
|
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,
|
92
|
+
fresh_when @product, assets: false, view: false
|
98
93
|
|
99
94
|
### What about Rails' default `fresh_when`?
|
100
95
|
|
data/ROADMAP.md
CHANGED
data/lib/ettu/configuration.rb
CHANGED
@@ -13,9 +13,7 @@ class Ettu
|
|
13
13
|
private
|
14
14
|
|
15
15
|
def set_defaults
|
16
|
-
self.
|
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
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
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
|
|
data/lib/ettu/fresh_when.rb
CHANGED
@@ -3,18 +3,18 @@ class Ettu
|
|
3
3
|
extend ActiveSupport::Concern
|
4
4
|
|
5
5
|
included do
|
6
|
-
|
6
|
+
alias_method_chain :fresh_when, :ettu
|
7
|
+
end
|
7
8
|
|
8
|
-
|
9
|
-
ettu = ettu_instance(record_or_options, additional_options, self)
|
9
|
+
private
|
10
10
|
|
11
|
-
|
11
|
+
def fresh_when_with_ettu(record_or_options, additional_options = {})
|
12
|
+
ettu = ettu_instance(record_or_options, additional_options, self)
|
12
13
|
|
13
|
-
|
14
|
-
end
|
15
|
-
end
|
14
|
+
ettu_params = {etag: ettu.etags, last_modified: ettu.last_modified}
|
16
15
|
|
17
|
-
|
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
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
|
-
|
13
|
-
|
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.
|
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
|
73
|
-
expect(ettu.
|
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 = [
|
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(
|
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
|
data/spec/fresh_when_spec.rb
CHANGED
@@ -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(:
|
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(:
|
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
|
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-
|
11
|
+
date: 2013-07-09 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rails
|