pagelime-rack 0.4.3 → 0.4.4
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 +45 -45
- 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: fdec71cd996f8f302c5fd9bef4554d1189c7ad61
|
4
|
+
data.tar.gz: e1ae03616bbb61da3a4f261b359d22df1eba153f
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 349138a21b9189f7bad9bc7c7dfdf51247b666344b0ffdd025b96b3f14d0c954e866edf314694b04521a4836121024bfb626bde56612a02ec9517824af819a64
|
7
|
+
data.tar.gz: 8e1b9e818b8f3ce2f4405829309de29758449e927b1d4d26068d245d74964ad33440d8ed0ebd96f70a82394656999c5a9287638ebda389703662908142092efc
|
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.4.
|
1
|
+
0.4.4
|
data/lib/rack/pagelime.rb
CHANGED
@@ -7,51 +7,71 @@ module Rack
|
|
7
7
|
class Pagelime
|
8
8
|
include Rack::Utils
|
9
9
|
|
10
|
-
|
11
|
-
|
12
|
-
"index" => "working",
|
13
|
-
"after_publish_callback" => "cache cleared"
|
10
|
+
ENV_KEYS = {
|
11
|
+
:toggle_processing => "pagelime.toggle_processing"
|
14
12
|
}
|
15
13
|
|
16
14
|
module ClassMethods
|
17
|
-
def enable_processing_for_request(
|
18
|
-
env[
|
15
|
+
def enable_processing_for_request(req)
|
16
|
+
req.env[ENV_KEYS[:toggle_processing]] = "on"
|
19
17
|
end
|
20
18
|
|
21
|
-
def disable_processing_for_request(
|
22
|
-
env[
|
19
|
+
def disable_processing_for_request(req)
|
20
|
+
req.env[ENV_KEYS[:toggle_processing]] = "off"
|
23
21
|
end
|
24
22
|
|
25
|
-
def processing_enabled_for_request?(
|
23
|
+
def processing_enabled_for_request?(req)
|
26
24
|
config_option = ::Pagelime.config.toggle_processing
|
27
|
-
config_option = env[
|
25
|
+
config_option = req.env[ENV_KEYS[:toggle_processing]] if config_option == "per_request"
|
28
26
|
|
29
|
-
::Pagelime.logger.debug "PAGELIME CMS RACK PLUGIN: Procesing enabled for request? (config: #{::Pagelime.config.toggle_processing}, env: #{env[
|
27
|
+
::Pagelime.logger.debug "PAGELIME CMS RACK PLUGIN: Procesing enabled for request? (config: #{::Pagelime.config.toggle_processing}, env: #{req.env[ENV_KEYS[:toggle_processing]]}, evaluated as: #{config_option})"
|
30
28
|
|
31
29
|
return config_option == "on"
|
32
30
|
end
|
33
31
|
|
34
32
|
# responses
|
35
33
|
|
36
|
-
def
|
34
|
+
def handle_route(req)
|
35
|
+
if req.get?
|
36
|
+
path = req.path.gsub(/\A\/+|\/+\Z/, "")
|
37
|
+
prefix = ::Pagelime.config.url_path.gsub(/\A\/+|\/+\Z/, "")
|
38
|
+
action = path["#{prefix}/".size..-1].to_s
|
39
|
+
|
40
|
+
# hijack response if a pagelime route, otherwise process output if so required
|
41
|
+
if path.start_with?("#{prefix}/") || path == prefix
|
42
|
+
case action
|
43
|
+
# handle publish callback
|
44
|
+
when "after_publish_callback"
|
45
|
+
resp = handle_publish_callback(req)
|
46
|
+
# handle "index"
|
47
|
+
when ""
|
48
|
+
resp = handle_status_check(req)
|
49
|
+
else
|
50
|
+
::Pagelime.logger.debug "PAGELIME CMS RACK PLUGIN: Unable to route action! (URL prefix: #{::Pagelime.config.url_path}, Request path: #{req.path})"
|
51
|
+
end
|
52
|
+
else
|
53
|
+
::Pagelime.logger.debug "PAGELIME CMS RACK PLUGIN: Unable to route prefix! (URL prefix: #{::Pagelime.config.url_path}, Request path: #{req.path})"
|
54
|
+
end
|
55
|
+
end
|
56
|
+
|
57
|
+
resp
|
58
|
+
end
|
59
|
+
|
60
|
+
def handle_publish_callback(req)
|
37
61
|
|
38
|
-
req = Rack::Request.new(env)
|
39
|
-
|
40
62
|
::Pagelime.logger.debug "PAGELIME CMS RACK PLUGIN: Route for publish callback called!"
|
41
63
|
|
42
64
|
::Pagelime.cache.clear_page(req.params["path"].to_s)
|
43
65
|
::Pagelime.cache.clear_shared
|
44
66
|
|
45
|
-
[200, {"Content-Type" => "text/html"},
|
67
|
+
[200, {"Content-Type" => "text/html"}, ["cache cleared"]]
|
46
68
|
end
|
47
69
|
|
48
|
-
def handle_status_check(
|
70
|
+
def handle_status_check(req)
|
49
71
|
|
50
|
-
req = Rack::Request.new(env)
|
51
|
-
|
52
72
|
::Pagelime.logger.debug "PAGELIME CMS RACK PLUGIN: Route for index called!"
|
53
73
|
|
54
|
-
[200, {"Content-Type" => "text/html"},
|
74
|
+
[200, {"Content-Type" => "text/html"}, ["working"]]
|
55
75
|
end
|
56
76
|
|
57
77
|
end
|
@@ -67,40 +87,20 @@ module Rack
|
|
67
87
|
|
68
88
|
def call(env)
|
69
89
|
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
path = req.path.gsub(/\A\/+|\/+\Z/, "")
|
74
|
-
prefix = ::Pagelime.config.url_path.gsub(/\A\/+|\/+\Z/, "")
|
75
|
-
action = path["#{prefix}/".size..-1].to_s
|
76
|
-
|
77
|
-
# hijack response if a pagelime route, otherwise process output if so required
|
78
|
-
if path.start_with?("#{prefix}/") || path == prefix
|
79
|
-
case action
|
80
|
-
# handle publish callback
|
81
|
-
when "after_publish_callback"
|
82
|
-
resp = handle_publish_callback(env)
|
83
|
-
# handle "index"
|
84
|
-
when ""
|
85
|
-
resp = handle_status_check(env)
|
86
|
-
else
|
87
|
-
::Pagelime.logger.debug "PAGELIME CMS RACK PLUGIN: Unable to route action! (URL prefix: #{::Pagelime.config.url_path}, Request path: #{req.path})"
|
88
|
-
end
|
89
|
-
else
|
90
|
-
::Pagelime.logger.debug "PAGELIME CMS RACK PLUGIN: Unable to route prefix! (URL prefix: #{::Pagelime.config.url_path}, Request path: #{req.path})"
|
91
|
-
end
|
90
|
+
app_resp = @app.call(env)
|
91
|
+
req = Rack::Request.new(env)
|
92
|
+
resp = handle_route(req)
|
92
93
|
|
93
94
|
# only process original output if routing wasn't handled
|
94
95
|
unless resp
|
96
|
+
|
97
|
+
status, headers, response = app_resp
|
95
98
|
|
96
99
|
::Pagelime.logger.debug "PAGELIME CMS RACK PLUGIN: Headers: #{headers}"
|
97
100
|
::Pagelime.logger.debug "PAGELIME CMS RACK PLUGIN: Status: #{status.inspect}"
|
98
101
|
::Pagelime.logger.debug "PAGELIME CMS RACK PLUGIN: Response: #{response}"
|
99
102
|
|
100
|
-
|
101
|
-
|
102
|
-
if processing_enabled_for_request?(env) && status == 200 &&
|
103
|
-
headers["Content-Type"] != nil && headers["Content-Type"].include?("text/html")
|
103
|
+
if status == 200 && headers["Content-Type"].to_s.include?("text/html") && processing_enabled_for_request?(req)
|
104
104
|
|
105
105
|
html = ""
|
106
106
|
response.each{|part| html << part}
|
data/pagelime-rack.gemspec
CHANGED