ettu 0.0.2 → 0.0.3
Sign up to get free protection for your applications and to get access to all the features.
- data/README.md +26 -3
- data/lib/ettu/ettu.rb +6 -8
- data/lib/ettu/fresh_when.rb +2 -1
- data/lib/ettu/railtie.rb +2 -2
- data/lib/ettu/version.rb +1 -1
- metadata +2 -2
data/README.md
CHANGED
@@ -7,9 +7,9 @@ yourself.
|
|
7
7
|
|
8
8
|
Ettu (loosely translated "And calculate you, too?") transparently
|
9
9
|
accounts for the current action's view code (JavaScript, CSS, templates)
|
10
|
-
using the same [asset
|
10
|
+
using the same [asset fingerprinting]
|
11
11
|
(http://guides.rubyonrails.org/asset_pipeline.html#what-is-fingerprinting-and-why-should-i-care-questionmark)
|
12
|
-
and Russian Doll [cache
|
12
|
+
and Russian Doll [template cache digesting]
|
13
13
|
(https://github.com/rails/cache_digests#readme) used by Rails. It does
|
14
14
|
all of this while allowing you to use the same syntax you're already
|
15
15
|
accustomed to. So keep doing what you're doing, and let Ettu worry about
|
@@ -25,6 +25,8 @@ And then execute:
|
|
25
25
|
|
26
26
|
$ bundle
|
27
27
|
|
28
|
+
And that's it. Ettu will be loaded on your next restart.
|
29
|
+
|
28
30
|
## Usage
|
29
31
|
|
30
32
|
Rails 4 ETags can be used in the following way:
|
@@ -74,7 +76,6 @@ value to `false`:
|
|
74
76
|
|
75
77
|
fresh_when @product, js: false, css: false, view: false
|
76
78
|
|
77
|
-
|
78
79
|
### What about Rails' default `fresh_when`?
|
79
80
|
|
80
81
|
Ettu tries its darndest to not interfere with Rails' default
|
@@ -82,6 +83,28 @@ implementation. Ettu makes sure to pass all the options you specify to
|
|
82
83
|
Rails (like the `public` option). It's even coded as a drop-in gem that
|
83
84
|
won't cause problems if it's not installed.
|
84
85
|
|
86
|
+
## RAILS_ENV=development Issues
|
87
|
+
|
88
|
+
Until [rails/rails#10791](https://github.com/rails/rails/pull/10791)
|
89
|
+
gets merged in, Ettu will not be able to detect changes in templates
|
90
|
+
while in the **development** environment. This is not an issue that
|
91
|
+
affects staging or production, because the template cache will be
|
92
|
+
recreated after each deploy.
|
93
|
+
|
94
|
+
In the mean time, you can monkey-patch around this:
|
95
|
+
|
96
|
+
```ruby
|
97
|
+
# config/environments/development.rb
|
98
|
+
class BlackHole < Hash
|
99
|
+
def []=(k, v); end
|
100
|
+
end
|
101
|
+
module ActionView
|
102
|
+
class Digestor
|
103
|
+
@@cache = BlackHole.new
|
104
|
+
end
|
105
|
+
end
|
106
|
+
```
|
107
|
+
|
85
108
|
## Contributing
|
86
109
|
|
87
110
|
1. Fork it
|
data/lib/ettu/ettu.rb
CHANGED
@@ -10,7 +10,7 @@ module Ettu
|
|
10
10
|
@record = record_or_options
|
11
11
|
@options = additional_options
|
12
12
|
end
|
13
|
-
@asset_etags =
|
13
|
+
@asset_etags = {}
|
14
14
|
end
|
15
15
|
|
16
16
|
def response_etag
|
@@ -21,8 +21,8 @@ module Ettu
|
|
21
21
|
@options.fetch(:last_modified, @record.try(:updated_at))
|
22
22
|
end
|
23
23
|
|
24
|
-
def view_etag(view)
|
25
|
-
@view_etag ||= view_digest(view)
|
24
|
+
def view_etag(view, format, lookup_context)
|
25
|
+
@view_etag ||= view_digest(view, format, lookup_context)
|
26
26
|
end
|
27
27
|
|
28
28
|
def asset_etag(asset)
|
@@ -43,14 +43,12 @@ module Ettu
|
|
43
43
|
|
44
44
|
# Jeremy Kemper
|
45
45
|
# https://gist.github.com/jeremy/4211803
|
46
|
-
def view_digest(view)
|
47
|
-
|
46
|
+
def view_digest(view, format, lookup_context)
|
47
|
+
ActionView::Digestor.digest(
|
48
48
|
view,
|
49
|
-
|
49
|
+
format,
|
50
50
|
lookup_context
|
51
51
|
)
|
52
|
-
rescue ActionView::MissingTemplate
|
53
|
-
'' # Ignore missing templates
|
54
52
|
end
|
55
53
|
|
56
54
|
# Jeremy Kemper
|
data/lib/ettu/fresh_when.rb
CHANGED
@@ -10,7 +10,8 @@ module Ettu
|
|
10
10
|
|
11
11
|
etags = [*ettu.response_etag]
|
12
12
|
if view = ettu.options.fetch(:view, "#{controller_name}/#{action_name}")
|
13
|
-
|
13
|
+
# TODO: This is ugly. How do we clean it up?
|
14
|
+
etags << ettu.view_etag(view, request.format.try(:to_sym), lookup_context)
|
14
15
|
end
|
15
16
|
if request.format.try(:html?)
|
16
17
|
etags << ettu.js_etag
|
data/lib/ettu/railtie.rb
CHANGED
@@ -1,10 +1,10 @@
|
|
1
1
|
module Ettu
|
2
|
-
class Railtie <
|
2
|
+
class Railtie < Rails::Railtie
|
3
3
|
initializer 'install' do
|
4
4
|
require 'ettu'
|
5
5
|
|
6
6
|
ActiveSupport.on_load :action_controller do
|
7
|
-
ActionController::Base.send :include,
|
7
|
+
ActionController::Base.send :include, FreshWhen
|
8
8
|
end
|
9
9
|
end
|
10
10
|
end
|
data/lib/ettu/version.rb
CHANGED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: ettu
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.3
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2013-06-
|
12
|
+
date: 2013-06-30 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: rails
|