|
1 | 1 | #-- |
| 2 | +# Copyright (c) 2012-2016 Karol Bucek, LTD. |
2 | 3 | # Copyright (c) 2010-2012 Engine Yard, Inc. |
3 | 4 | # Copyright (c) 2007-2009 Sun Microsystems, Inc. |
4 | 5 | # This source code is available under the MIT license. |
|
11 | 12 | module JRuby::Rack |
12 | 13 | class Railtie < ::Rails::Railtie |
13 | 14 |
|
14 | | - # settings Rails.public_path in an initializer seems "too" late @see #99 |
15 | 15 | config.before_configuration do |app| |
16 | | - paths, public = app.config.paths, Pathname.new(JRuby::Rack.public_path) |
| 16 | + paths = app.config.paths; public = JRuby::Rack.public_path |
17 | 17 | if paths.respond_to?(:'[]') && paths.respond_to?(:keys) |
18 | | - # Rails 3.1/3.2/4.0: paths["app/controllers"] style |
| 18 | + # Rails 3.1/3.2/4.x: paths["app/controllers"] style |
19 | 19 | old_public = Pathname.new(paths['public'].to_a.first) |
20 | 20 | javascripts = Pathname.new(paths['public/javascripts'].to_a.first) |
21 | 21 | stylesheets = Pathname.new(paths['public/stylesheets'].to_a.first) |
22 | | - paths['public'] = public.to_s |
| 22 | + paths['public'] = public.to_s; public = Pathname.new(public) |
23 | 23 | paths['public/javascripts'] = public.join(javascripts.relative_path_from(old_public)).to_s |
24 | 24 | paths['public/stylesheets'] = public.join(stylesheets.relative_path_from(old_public)).to_s |
25 | 25 | else |
26 | 26 | # Rails 3.0: old paths.app.controllers style |
27 | 27 | old_public = Pathname.new(paths.public.to_a.first) |
28 | 28 | javascripts = Pathname.new(paths.public.javascripts.to_a.first) |
29 | 29 | stylesheets = Pathname.new(paths.public.stylesheets.to_a.first) |
30 | | - paths.public = public.to_s |
| 30 | + paths.public = public.to_s; public = Pathname.new(public) |
31 | 31 | paths.public.javascripts = public.join(javascripts.relative_path_from(old_public)).to_s |
32 | 32 | paths.public.stylesheets = public.join(stylesheets.relative_path_from(old_public)).to_s |
33 | | - end |
| 33 | + end if public # nil if /public does not exist |
34 | 34 | end |
35 | 35 |
|
36 | 36 | # TODO prefix initializers with 'jruby_rack.' !? |
@@ -64,8 +64,8 @@ class Railtie < ::Rails::Railtie |
64 | 64 | # - when a *config.relative_url_root* is set we should not interfere ... |
65 | 65 | if ( env_url_root = ENV['RAILS_RELATIVE_URL_ROOT'] ) && |
66 | 66 | !( app.config.respond_to?(:relative_url_root) && app.config.relative_url_root ) |
67 | | - if ( config = app.config ).action_controller |
68 | | - config.action_controller.relative_url_root = env_url_root |
| 67 | + if action_controller = app.config.action_controller |
| 68 | + action_controller.relative_url_root = env_url_root |
69 | 69 | elsif defined?(ActionController::Base) && |
70 | 70 | ActionController::Base.respond_to?(:relative_url_root=) |
71 | 71 | # setting the config affects *ActionController::Base.relative_url_root* |
|
0 commit comments