public
Description: Ruby on Rails
Homepage: http://rubyonrails.org
Clone URL: git://github.com/rails/rails.git
Search Repo:
Added Rails.public_path to control where HTML and assets are expected to 
be loaded from (defaults to Rails.root + "/public") #11581 
[nicksieger]
dhh (author)
Sun Apr 13 15:33:27 -0700 2008
commit  420c4b3d8878156d04f45e47050ddc62ae00c68c
tree    e56d27d2078a7553b161a1088594e147e25ed2da
parent  be7fd8168aa4776dccfe2e670cb9451204449dd4
...
36
37
38
39
 
40
41
42
...
46
47
48
49
 
50
51
52
...
36
37
38
 
39
40
41
42
...
46
47
48
 
49
50
51
52
0
@@ -36,7 +36,7 @@
0
     # == Setting the cache directory
0
     #
0
     # The cache directory should be the document root for the web server and is set using Base.page_cache_directory = "/document/root".
0
- # For Rails, this directory has already been set to RAILS_ROOT + "/public".
0
+ # For Rails, this directory has already been set to Rails.public_path (which is usually set to RAILS_ROOT + "/public").
0
     #
0
     # == Setting the cache extension
0
     #
0
@@ -46,7 +46,7 @@
0
       def self.included(base) #:nodoc:
0
         base.extend(ClassMethods)
0
         base.class_eval do
0
- @@page_cache_directory = defined?(RAILS_ROOT) ? "#{RAILS_ROOT}/public" : ""
0
+ @@page_cache_directory = defined?(Rails.public_path) ? Rails.public_path : ""
0
           cattr_accessor :page_cache_directory
0
 
0
           @@page_cache_extension = '.html'
...
67
68
69
70
 
71
72
73
...
67
68
69
 
70
71
72
73
0
@@ -67,7 +67,7 @@
0
     end
0
 
0
     cattr_accessor :error_file_path
0
- self.error_file_path = "#{::RAILS_ROOT}/public" if defined? ::RAILS_ROOT
0
+ self.error_file_path = Rails.public_path if defined?(Rails.public_path)
0
 
0
     cattr_accessor :unprepared
0
     self.unprepared = true
...
153
154
155
156
 
157
158
159
...
153
154
155
 
156
157
158
159
0
@@ -153,7 +153,7 @@
0
       # If the file doesn't exist, the body of the response will be left empty.
0
       def render_optional_error_file(status_code)
0
         status = interpret_status(status_code)
0
- path = "#{RAILS_ROOT}/public/#{status[0,3]}.html"
0
+ path = "#{Rails.public_path}/#{status[0,3]}.html"
0
         if File.exist?(path)
0
           render :file => path, :status => status
0
         else
...
101
102
103
104
 
105
106
107
...
101
102
103
 
104
105
106
107
0
@@ -101,7 +101,7 @@
0
     # something like Live HTTP Headers for Firefox to verify that the cache is indeed working (and that the assets are not being
0
     # requested over and over).
0
     module AssetTagHelper
0
- ASSETS_DIR = defined?(RAILS_ROOT) ? "#{RAILS_ROOT}/public" : "public"
0
+ ASSETS_DIR = defined?(Rails.public_path) ? Rails.public_path : "public"
0
       JAVASCRIPTS_DIR = "#{ASSETS_DIR}/javascripts"
0
       STYLESHEETS_DIR = "#{ASSETS_DIR}/stylesheets"
0
       
...
305
306
307
308
 
 
 
309
310
311
...
313
314
315
316
 
 
 
317
318
319
...
391
392
393
394
 
 
 
 
 
 
 
 
 
 
 
 
 
395
396
397
...
399
400
401
402
 
403
404
405
...
305
306
307
 
308
309
310
311
312
313
...
315
316
317
 
318
319
320
321
322
323
...
395
396
397
 
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
...
415
416
417
 
418
419
420
421
0
@@ -305,7 +305,9 @@
0
   
0
   def test_not_implemented
0
     with_all_requests_local false do
0
- head :not_implemented
0
+ with_rails_public_path(".") do
0
+ head :not_implemented
0
+ end
0
     end
0
     assert_response :not_implemented
0
     assert_equal "GET, PUT", @response.headers['Allow']
0
@@ -313,7 +315,9 @@
0
 
0
   def test_method_not_allowed
0
     with_all_requests_local false do
0
- get :method_not_allowed
0
+ with_rails_public_path(".") do
0
+ get :method_not_allowed
0
+ end
0
     end
0
     assert_response :method_not_allowed
0
     assert_equal "GET, HEAD, PUT", @response.headers['Allow']
0
@@ -391,7 +395,19 @@
0
       @request.remote_addr = old_remote_addr
0
     end
0
 
0
- def with_rails_root(path = nil)
0
+ def with_rails_public_path(rails_root)
0
+ old_rails = Object.const_get(:Rails) rescue nil
0
+ mod = Object.const_set(:Rails, Module.new)
0
+ (class << mod; self; end).instance_eval do
0
+ define_method(:public_path) { "#{rails_root}/public" }
0
+ end
0
+ yield
0
+ ensure
0
+ Object.module_eval { remove_const(:Rails) } if defined?(Rails)
0
+ Object.const_set(:Rails, old_rails) if old_rails
0
+ end
0
+
0
+ def with_rails_root(path = nil,&block)
0
       old_rails_root = RAILS_ROOT if defined?(RAILS_ROOT)
0
       if path
0
         silence_warnings { Object.const_set(:RAILS_ROOT, path) }
0
@@ -399,7 +415,7 @@
0
         Object.remove_const(:RAILS_ROOT) rescue nil
0
       end
0
 
0
- yield
0
+ with_rails_public_path(path, &block)
0
 
0
     ensure
0
       if old_rails_root
...
1
2
 
 
3
4
5
...
1
2
3
4
5
6
7
0
@@ -1,5 +1,7 @@
0
 *SVN*
0
 
0
+* Added Rails.public_path to control where HTML and assets are expected to be loaded from (defaults to Rails.root + "/public") #11581 [nicksieger]
0
+
0
 * rake time:zones:local finds correct base utc offset for zones in the Southern Hemisphere [Geoff Buesing]
0
 
0
 * Don't require rails/gem_builder during rails initialization, it's only needed for the gems:build task. [rick]
...
38
39
40
 
 
 
 
 
 
 
 
41
42
43
...
38
39
40
41
42
43
44
45
46
47
48
49
50
51
0
@@ -38,6 +38,14 @@
0
     def cache
0
       RAILS_CACHE
0
     end
0
+
0
+ def public_path
0
+ @@public_path ||= File.join(self.root, "public")
0
+ end
0
+
0
+ def public_path=(path)
0
+ @@public_path = path
0
+ end
0
   end
0
   
0
   # The Initializer is responsible for processing the Rails configuration, such

Comments

    No one has commented yet.