rack-rewrite 1.4.1 → 1.5.0

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: 1d85860482ab49561638787391c367e8144173e8
4
- data.tar.gz: 93e9dcb2b6c38c85e38dc0bd07938929fb010a5c
3
+ metadata.gz: 9b433927615a0c3d699ee348e2442d5e2d3f3bed
4
+ data.tar.gz: 8b8f88d6bd02f4149e37a7d3956045fa795a467f
5
5
  SHA512:
6
- metadata.gz: e5532f91f14dcfb454f4392ff15bf482a7f0e129695183579498c545aa8a89bcad7facc38ce81e3de9eed2e9954e62d2b3413e631784c04924e178a274374ef5
7
- data.tar.gz: 20faa15a94a838718c64702436b030885b1b8595753e430958a9ca86176f77313b37383ec4ee4bc220a141b3e695dfa0a123529f9f61630a62d2f432322a17ac
6
+ metadata.gz: cfd596b1093d843050fe96bf3d6737c821d20a10d3371b17dc23a70c28e78cb55ddbeebe059f8842ad976170426c8cba5da8e215e21cd175165c7794c1dedd23
7
+ data.tar.gz: 45b9edc5712be185b07cbcbc81dceab6e0053370510c2c381f3ba95f10b72e0aaed2708cfb2cf4cbfe0d4ce6ac4734bd8741f2fd2f1cc1baa8bb53e414a52192
data/README.markdown CHANGED
@@ -14,6 +14,7 @@ can get away with rack-rewrite instead of writing Apache mod_rewrite rules.
14
14
  ### Sample rackup file
15
15
 
16
16
  ```ruby
17
+ # config.ru
17
18
  gem 'rack-rewrite', '~> 1.2.1'
18
19
  require 'rack/rewrite'
19
20
  use Rack::Rewrite do
@@ -27,6 +28,7 @@ end
27
28
  ### Sample usage in a rails app
28
29
 
29
30
  ```ruby
31
+ # config/application.rb
30
32
  config.middleware.insert_before(Rack::Lock, Rack::Rewrite) do
31
33
  rewrite '/wiki/John_Trupiano', '/john'
32
34
  r301 '/wiki/Yair_Flicker', '/yair'
@@ -215,9 +217,9 @@ Recall that rules are interpreted from top to bottom. So you can install
215
217
  "default" rewrite rules if you like. [2] is a sample default rule that
216
218
  will redirect all other requests to the wiki to a google search.
217
219
 
218
- ### :send_file, :x_send_file
220
+ ### :send_file, :x_send_file, :send_data
219
221
 
220
- Calls to #send_file and #x_send_file also have the same signature as #rewrite.
222
+ Calls to #send_file and #x_send_file and #send_data also have the same signature as #rewrite.
221
223
  If the rule matches, the 'to' parameter is interpreted as a path to a file
222
224
  to be rendered instead of passing the application call up the rack stack.
223
225
 
@@ -228,6 +230,9 @@ send_file /*/, 'public/spammers.htm', :if => Proc.new { |rack_env|
228
230
  x_send_file /^blog\/.*/, 'public/blog_offline.htm', :if => Proc.new { |rack_env|
229
231
  File.exists?('public/blog_offline.htm')
230
232
  }
233
+ send_data /^blog\/.*/, 'public/blog_offline.png', :if => Proc.new { |rack_env|
234
+ File.exists?('public/blog_offline.htm')
235
+ }
231
236
  ```
232
237
 
233
238
  ## Options Parameter
@@ -359,24 +364,24 @@ string to /today.html
359
364
  rack-rewrite can also be driven by external loaders. Bundled with this library is a loader for YAML files.
360
365
 
361
366
  ```
362
- config.middleware.insert_before(Rack::Lock, Rack::Rewrite,
363
- :klass => Rack::Rewrite::YamlRuleSet,
367
+ config.middleware.insert_before(Rack::Lock, Rack::Rewrite,
368
+ :klass => Rack::Rewrite::YamlRuleSet,
364
369
  :options => {:file_name => @file_name})
365
370
  ```
366
371
 
367
372
  Using syntax like
368
373
 
369
374
  ```
370
- -
375
+ -
371
376
  method: r301
372
377
  from: !ruby/regexp '/(.*)/print'
373
378
  to : '$1/printer_friendly'
374
- options :
379
+ options :
375
380
  host : 'example.com'
376
381
  ```
377
382
 
378
- Any class can be used here as long as:
379
-
383
+ Any class can be used here as long as:
384
+
380
385
  - the class take an options hash
381
386
  - `#rules` returns an array of `Rack::Rewrite::Rule` instances
382
387
 
data/VERSION CHANGED
@@ -1 +1 @@
1
- 1.4.1
1
+ 1.5.0
@@ -90,6 +90,13 @@ module Rack
90
90
  add_rule :x_send_file, *args
91
91
  end
92
92
 
93
+ # Creates a rule taht will render the raw data if matched
94
+ # send_data /*/, 'public/system/maintenance.html',
95
+ # :if => Proc.new { File.exists?('public/system/maintenance.html') }
96
+ def send_data(*args)
97
+ add_rule :send_data, *args
98
+ end
99
+
93
100
  private
94
101
  def add_rule(method, from, to, options = {}) #:nodoc:
95
102
  @rules << Rule.new(method.to_sym, from, to, options)
@@ -160,6 +167,11 @@ module Rack
160
167
  'Content-Length' => ::File.size(interpreted_to).to_s,
161
168
  'Content-Type' => Rack::Mime.mime_type(::File.extname(interpreted_to))
162
169
  }.merge!(additional_headers), []]
170
+ when :send_data
171
+ [status, {
172
+ 'Content-Type' => interpreted_to.bytesize,
173
+ 'Content-Type' => 'text/html',
174
+ }.merge!(additional_headers), [interpreted_to]]
163
175
  else
164
176
  raise Exception.new("Unsupported rule: #{self.rule_type}")
165
177
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rack-rewrite
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.4.1
4
+ version: 1.5.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Travis Jeffery
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2013-11-07 00:00:00.000000000 Z
12
+ date: 2014-01-09 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: bundler