ventilation 0.2.3 → 0.3.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.
- data/CHANGELOG.md +11 -1
- data/VERSION +1 -1
- data/lib/app/helpers/esi_helper.rb +37 -20
- data/lib/ventilation.rb +7 -0
- data/ventilation.gemspec +2 -2
- metadata +9 -3
data/CHANGELOG.md
CHANGED
@@ -1 +1,11 @@
|
|
1
|
-
|
1
|
+
Version 0.3.0 - 12/4/2010
|
2
|
+
-------------------------
|
3
|
+
* Optimize code for production esi.
|
4
|
+
* Add expire helper for setting cache control headers.
|
5
|
+
* Always use varnish if its available.
|
6
|
+
* Turn off esi resolution for environment except for development.
|
7
|
+
|
8
|
+
Version 0.2.3 - 12/3/2010
|
9
|
+
-------------------------
|
10
|
+
* Turn off esi resolution for staging by default.
|
11
|
+
* Fixes issue with urls without paths.
|
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.
|
1
|
+
0.3.0
|
@@ -6,17 +6,28 @@ require 'ventilation/deep_stack'
|
|
6
6
|
module Ventilation
|
7
7
|
module EsiHelper
|
8
8
|
|
9
|
-
# Render resource on the edge
|
10
9
|
def esi(resource, options = {})
|
11
|
-
env = ENV['RAILS_ENV']
|
12
|
-
|
13
|
-
# If we were passed a url...
|
14
10
|
if resource =~ URI.regexp
|
15
|
-
#
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
11
|
+
%%<esi:include src="#{resource}" />%
|
12
|
+
else
|
13
|
+
%%<esi:include src="#{url_for options.merge(:action => resource)}" />%
|
14
|
+
end
|
15
|
+
end
|
16
|
+
|
17
|
+
# Only enable ventilation esi resolutioon features in development.
|
18
|
+
if 'development' == ENV['RAILS_ENV']
|
19
|
+
|
20
|
+
alias :esi_tag :esi
|
21
|
+
|
22
|
+
# Render resource on the edge
|
23
|
+
def esi(resource, options = {})
|
24
|
+
|
25
|
+
# Use esi if supported.
|
26
|
+
return esi_tag(resource, options) if esi_supported?
|
27
|
+
|
28
|
+
# If we were passed a url...
|
29
|
+
if resource =~ URI.regexp
|
30
|
+
# ...fetch and render an external resource...
|
20
31
|
url = URI.parse(resource)
|
21
32
|
res = Net::HTTP.start(url.host, url.port) {|http|
|
22
33
|
path = url.path.blank? ? "/" : url.path
|
@@ -24,13 +35,8 @@ module Ventilation
|
|
24
35
|
http.get(path)
|
25
36
|
}
|
26
37
|
res.body
|
27
|
-
end
|
28
|
-
else
|
29
|
-
# ...otherwise render as an action.
|
30
|
-
case env
|
31
|
-
when 'production', 'staging'
|
32
|
-
%%<esi:include src="#{url_for url_options.merge(:action => resource)}" />%
|
33
38
|
else
|
39
|
+
# ...otherwise render as an action.
|
34
40
|
if controller = options[:controller]
|
35
41
|
controller = "#{controller.to_s.camelcase}Controller".constantize
|
36
42
|
else
|
@@ -51,10 +57,21 @@ module Ventilation
|
|
51
57
|
end
|
52
58
|
end
|
53
59
|
|
54
|
-
|
55
|
-
|
60
|
+
# Helper for setting expire headers.
|
61
|
+
#
|
62
|
+
# Examples:
|
63
|
+
# <%- expire 5.minutes -%>
|
64
|
+
# <%- expire 30.seconds -%>
|
65
|
+
def expire(duration)
|
66
|
+
headers['Cache-Control'] = 'max-age=#{duration.to_i}'
|
67
|
+
headers['Expires'] = duration.from_now.httpdate
|
68
|
+
end
|
69
|
+
|
70
|
+
private
|
71
|
+
def esi_supported?
|
72
|
+
# Enable esi if behind varnish.
|
73
|
+
request.env.has_key?('HTTP_X_VARNISH')
|
74
|
+
end
|
56
75
|
|
57
|
-
|
58
|
-
module ApplicationHelper
|
59
|
-
include Ventilation::EsiHelper
|
76
|
+
end
|
60
77
|
end
|
data/lib/ventilation.rb
CHANGED
data/ventilation.gemspec
CHANGED
@@ -5,11 +5,11 @@
|
|
5
5
|
|
6
6
|
Gem::Specification.new do |s|
|
7
7
|
s.name = %q{ventilation}
|
8
|
-
s.version = "0.
|
8
|
+
s.version = "0.3.0"
|
9
9
|
|
10
10
|
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
11
11
|
s.authors = ["Blake Taylor"]
|
12
|
-
s.date = %q{2010-12-
|
12
|
+
s.date = %q{2010-12-04}
|
13
13
|
s.description = %q{Helper methods for building esi tags, simplifies development bypassing the need for varnish.}
|
14
14
|
s.email = %q{btaylor@agoragames.com}
|
15
15
|
s.extra_rdoc_files = [
|
metadata
CHANGED
@@ -1,12 +1,13 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: ventilation
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
+
hash: 19
|
4
5
|
prerelease: false
|
5
6
|
segments:
|
6
7
|
- 0
|
7
|
-
- 2
|
8
8
|
- 3
|
9
|
-
|
9
|
+
- 0
|
10
|
+
version: 0.3.0
|
10
11
|
platform: ruby
|
11
12
|
authors:
|
12
13
|
- Blake Taylor
|
@@ -14,7 +15,7 @@ autorequire:
|
|
14
15
|
bindir: bin
|
15
16
|
cert_chain: []
|
16
17
|
|
17
|
-
date: 2010-12-
|
18
|
+
date: 2010-12-04 00:00:00 -05:00
|
18
19
|
default_executable:
|
19
20
|
dependencies:
|
20
21
|
- !ruby/object:Gem::Dependency
|
@@ -25,6 +26,7 @@ dependencies:
|
|
25
26
|
requirements:
|
26
27
|
- - ">="
|
27
28
|
- !ruby/object:Gem::Version
|
29
|
+
hash: 3
|
28
30
|
segments:
|
29
31
|
- 0
|
30
32
|
version: "0"
|
@@ -38,6 +40,7 @@ dependencies:
|
|
38
40
|
requirements:
|
39
41
|
- - ">="
|
40
42
|
- !ruby/object:Gem::Version
|
43
|
+
hash: 15
|
41
44
|
segments:
|
42
45
|
- 1
|
43
46
|
- 2
|
@@ -53,6 +56,7 @@ dependencies:
|
|
53
56
|
requirements:
|
54
57
|
- - ">="
|
55
58
|
- !ruby/object:Gem::Version
|
59
|
+
hash: 43
|
56
60
|
segments:
|
57
61
|
- 0
|
58
62
|
- 9
|
@@ -102,6 +106,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
102
106
|
requirements:
|
103
107
|
- - ">="
|
104
108
|
- !ruby/object:Gem::Version
|
109
|
+
hash: 3
|
105
110
|
segments:
|
106
111
|
- 0
|
107
112
|
version: "0"
|
@@ -110,6 +115,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
110
115
|
requirements:
|
111
116
|
- - ">="
|
112
117
|
- !ruby/object:Gem::Version
|
118
|
+
hash: 3
|
113
119
|
segments:
|
114
120
|
- 0
|
115
121
|
version: "0"
|