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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: c53d944af22030c23943ecc9142cbfb47a22a5ba
4
- data.tar.gz: e1811a3b570a8ddace3e6b1c386e705b144cf555
3
+ metadata.gz: fdec71cd996f8f302c5fd9bef4554d1189c7ad61
4
+ data.tar.gz: e1ae03616bbb61da3a4f261b359d22df1eba153f
5
5
  SHA512:
6
- metadata.gz: 6ad4150bb797dac36ccb364b08baa39eef9ab86be178fa88c2f5eeecdf467456f5d7b1c98c703b227747d188bf8ecb840a2733677ca3401d09996d840dcbc8ef
7
- data.tar.gz: 98ba3b7ebf9cbc9e066e7d11f5ed3456c65afd52ccc663e0deb70dd0bf972667d90683419719bf36ce7acd2c9a0abfb4f5c26707989f15b76b84252ab42ceee4
6
+ metadata.gz: 349138a21b9189f7bad9bc7c7dfdf51247b666344b0ffdd025b96b3f14d0c954e866edf314694b04521a4836121024bfb626bde56612a02ec9517824af819a64
7
+ data.tar.gz: 8e1b9e818b8f3ce2f4405829309de29758449e927b1d4d26068d245d74964ad33440d8ed0ebd96f70a82394656999c5a9287638ebda389703662908142092efc
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.4.3
1
+ 0.4.4
@@ -7,51 +7,71 @@ module Rack
7
7
  class Pagelime
8
8
  include Rack::Utils
9
9
 
10
- TOGGLE_PROCESSING_ENV_KEY = "pagelime.toggle_processing"
11
- ROUTE_RESPONSES = {
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(env)
18
- env[TOGGLE_PROCESSING_ENV_KEY] = "on"
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(env)
22
- env[TOGGLE_PROCESSING_ENV_KEY] = "off"
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?(env)
23
+ def processing_enabled_for_request?(req)
26
24
  config_option = ::Pagelime.config.toggle_processing
27
- config_option = env[TOGGLE_PROCESSING_ENV_KEY] if config_option == "per_request"
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[TOGGLE_PROCESSING_ENV_KEY]}, evaluated as: #{config_option})"
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 handle_publish_callback(env)
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"}, StringIO.new(ROUTE_RESPONSES["after_publish_callback"])]
67
+ [200, {"Content-Type" => "text/html"}, ["cache cleared"]]
46
68
  end
47
69
 
48
- def handle_status_check(env)
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"}, StringIO.new(ROUTE_RESPONSES["index"])]
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
- status, headers, response = @app.call(env)
71
-
72
- req = Rack::Request.new(env)
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
- ::Pagelime.logger.debug "enabled? (#{processing_enabled_for_request?(env)}) status (#{status == 200}) headers (#{headers["Content-Type"] != nil}) html (#{headers["Content-Type"]}) class (#{headers["Content-Type"].class})"
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}
@@ -5,7 +5,7 @@
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = "pagelime-rack"
8
- s.version = "0.4.3"
8
+ s.version = "0.4.4"
9
9
 
10
10
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
11
  s.authors = ["Emil Anticevic", "Joel Van Horn"]
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: pagelime-rack
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.4.3
4
+ version: 0.4.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - Emil Anticevic