pagelime-rack 0.4.0 → 0.4.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/VERSION +1 -1
- data/lib/rack/pagelime.rb +59 -60
- data/pagelime-rack.gemspec +1 -1
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: e6f9dea9eac27aa1acd84261c8e8bfcef985bb67
|
4
|
+
data.tar.gz: e389bcd63e7e2f2aede5e5620662e46d258e312f
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 32a04b8649cfcfd7b4b4ec723ca3ba94f41ba53137bd25fc0c1bd0e067ae94e9791493beab954fbee7ec9c7992ededa5f56500a53342589656d115c8dd1aabaf
|
7
|
+
data.tar.gz: 224bb4ccb38b5fdd3f37e224ee806975fbd1c8a166908e788cb88146468b5ce149d39381f71327451d2e04083b70fb257e390d0e6c0338db5a3cae4eb6d0ed9d
|
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.4.
|
1
|
+
0.4.1
|
data/lib/rack/pagelime.rb
CHANGED
@@ -8,6 +8,10 @@ module Rack
|
|
8
8
|
include Rack::Utils
|
9
9
|
|
10
10
|
TOGGLE_PROCESSING_ENV_KEY = "pagelime.toggle_processing"
|
11
|
+
ROUTE_RESPONSES = {
|
12
|
+
"index" => "working",
|
13
|
+
"after_publish_callback" => "cache cleared"
|
14
|
+
}
|
11
15
|
|
12
16
|
module ClassMethods
|
13
17
|
def enable_processing_for_request(env)
|
@@ -26,6 +30,30 @@ module Rack
|
|
26
30
|
|
27
31
|
return config_option == "on"
|
28
32
|
end
|
33
|
+
|
34
|
+
# responses
|
35
|
+
|
36
|
+
def handle_publish_callback(env)
|
37
|
+
|
38
|
+
req = Rack::Request.new(env)
|
39
|
+
|
40
|
+
::Pagelime.logger.debug "PAGELIME CMS RACK PLUGIN: Route for publish callback called!"
|
41
|
+
|
42
|
+
::Pagelime.cache.clear_page(req.params["path"].to_s)
|
43
|
+
::Pagelime.cache.clear_shared
|
44
|
+
|
45
|
+
[200, {"Content-Type" => "text/html"}, StringIO.new(ROUTE_RESPONSES["after_publish_callback"])]
|
46
|
+
end
|
47
|
+
|
48
|
+
def handle_status_check(env)
|
49
|
+
|
50
|
+
req = Rack::Request.new(env)
|
51
|
+
|
52
|
+
::Pagelime.logger.debug "PAGELIME CMS RACK PLUGIN: Route for index called!"
|
53
|
+
|
54
|
+
[200, {"Content-Type" => "text/html"}, StringIO.new(ROUTE_RESPONSES["index"])]
|
55
|
+
end
|
56
|
+
|
29
57
|
end
|
30
58
|
|
31
59
|
include ClassMethods
|
@@ -51,10 +79,10 @@ module Rack
|
|
51
79
|
case action
|
52
80
|
# handle publish callback
|
53
81
|
when "after_publish_callback"
|
54
|
-
resp = handle_publish_callback(status, headers, response, env)
|
82
|
+
resp = handle_publish_callback(status, headers, response, env, "after_publish_callback")
|
55
83
|
# handle "index"
|
56
84
|
when ""
|
57
|
-
resp = handle_status_check(status, headers, response, env)
|
85
|
+
resp = handle_status_check(status, headers, response, env, "index")
|
58
86
|
else
|
59
87
|
::Pagelime.logger.debug "PAGELIME CMS RACK PLUGIN: Unable to route action! (URL prefix: #{::Pagelime.config.url_path}, Request path: #{req.path})"
|
60
88
|
end
|
@@ -63,69 +91,40 @@ module Rack
|
|
63
91
|
end
|
64
92
|
|
65
93
|
# only process original output if routing wasn't handled
|
66
|
-
resp
|
67
|
-
|
68
|
-
resp
|
69
|
-
end
|
70
|
-
|
71
|
-
# responses
|
72
|
-
|
73
|
-
def handle_publish_callback(status, headers, response, env)
|
74
|
-
|
75
|
-
req = Rack::Request.new(env)
|
76
|
-
|
77
|
-
::Pagelime.logger.debug "PAGELIME CMS RACK PLUGIN: Route for publish callback called!"
|
78
|
-
|
79
|
-
::Pagelime.cache.clear_page(req.params["path"].to_s)
|
80
|
-
::Pagelime.cache.clear_shared
|
81
|
-
|
82
|
-
[200, {"Content-Type" => "text/html"}, ["cache cleared"]]
|
83
|
-
end
|
84
|
-
|
85
|
-
def handle_status_check(status, headers, response, env)
|
86
|
-
|
87
|
-
req = Rack::Request.new(env)
|
88
|
-
|
89
|
-
::Pagelime.logger.debug "PAGELIME CMS RACK PLUGIN: Route for index called!"
|
94
|
+
unless resp
|
90
95
|
|
91
|
-
|
92
|
-
|
93
|
-
|
94
|
-
|
95
|
-
|
96
|
-
|
97
|
-
|
98
|
-
|
99
|
-
|
100
|
-
::Pagelime.logger.debug "PAGELIME CMS RACK PLUGIN: Headers: #{headers}"
|
101
|
-
::Pagelime.logger.debug "PAGELIME CMS RACK PLUGIN: Status: #{status}"
|
102
|
-
::Pagelime.logger.debug "PAGELIME CMS RACK PLUGIN: Response: #{response}"
|
103
|
-
|
104
|
-
if processing_enabled_for_request?(env) && status == 200 &&
|
105
|
-
headers["content-type"] && headers["content-type"].include?("text/html")
|
96
|
+
::Pagelime.logger.debug "PAGELIME CMS RACK PLUGIN: Headers: #{headers}"
|
97
|
+
::Pagelime.logger.debug "PAGELIME CMS RACK PLUGIN: Status: #{status}"
|
98
|
+
::Pagelime.logger.debug "PAGELIME CMS RACK PLUGIN: Response: #{response}"
|
99
|
+
|
100
|
+
if processing_enabled_for_request?(env) && status == 200 &&
|
101
|
+
headers["content-type"] && headers["content-type"].include?("text/html")
|
102
|
+
|
103
|
+
body_content = StringIO.new(response)
|
104
|
+
#response.each{|part| body_content << part}
|
106
105
|
|
107
|
-
|
108
|
-
|
106
|
+
::Pagelime.logger.debug "PAGELIME CMS RACK PLUGIN: Processing For Path: #{req.path}"
|
107
|
+
::Pagelime.logger.debug "PAGELIME CMS RACK PLUGIN: Processing Body (size:#{body_content.length})"
|
108
|
+
|
109
|
+
body = ::Pagelime.process_page(body_content, req.path)
|
110
|
+
|
111
|
+
headers['content-length'] = body.length.to_s
|
112
|
+
|
113
|
+
body = [body]
|
114
|
+
|
115
|
+
else
|
116
|
+
|
117
|
+
::Pagelime.logger.debug "PAGELIME CMS RACK PLUGIN: Not touching this request"
|
118
|
+
|
119
|
+
body = response
|
120
|
+
|
121
|
+
end
|
122
|
+
|
123
|
+
resp = [status, headers, body]
|
109
124
|
|
110
|
-
::Pagelime.logger.debug "PAGELIME CMS RACK PLUGIN: Processing For Path: #{req.path}"
|
111
|
-
::Pagelime.logger.debug "PAGELIME CMS RACK PLUGIN: Processing Body (size:#{body_content.length})"
|
112
|
-
|
113
|
-
body = ::Pagelime.process_page(body_content, req.path)
|
114
|
-
|
115
|
-
headers['content-length'] = body.length.to_s
|
116
|
-
|
117
|
-
body = [body]
|
118
|
-
|
119
|
-
else
|
120
|
-
|
121
|
-
::Pagelime.logger.debug "PAGELIME CMS RACK PLUGIN: Not touching this request"
|
122
|
-
|
123
|
-
body = response
|
124
|
-
|
125
125
|
end
|
126
126
|
|
127
|
-
|
128
|
-
|
127
|
+
resp
|
129
128
|
end
|
130
129
|
|
131
130
|
end
|
data/pagelime-rack.gemspec
CHANGED