提交 f6153f74 编写于 作者: W wycats

Merge remote branch 'drogus/engines'

...@@ -21,7 +21,7 @@ class Railtie < Rails::Railtie ...@@ -21,7 +21,7 @@ class Railtie < Rails::Railtie
ActiveSupport.on_load(:action_mailer) do ActiveSupport.on_load(:action_mailer) do
include AbstractController::UrlFor include AbstractController::UrlFor
extend ::AbstractController::Railties::RoutesHelpers.with(app.routes) extend ::AbstractController::Railties::RoutesHelpers.with(app.routes)
include app.routes.mounted_helpers(:app) include app.routes.mounted_helpers
options.each { |k,v| send("#{k}=", v) } options.each { |k,v| send("#{k}=", v) }
end end
end end
......
...@@ -27,7 +27,7 @@ class Railtie < Rails::Railtie ...@@ -27,7 +27,7 @@ class Railtie < Rails::Railtie
options.page_cache_directory ||= paths.public.to_a.first options.page_cache_directory ||= paths.public.to_a.first
ActiveSupport.on_load(:action_controller) do ActiveSupport.on_load(:action_controller) do
include app.routes.mounted_helpers(:app) include app.routes.mounted_helpers
extend ::AbstractController::Railties::RoutesHelpers.with(app.routes) extend ::AbstractController::Railties::RoutesHelpers.with(app.routes)
extend ::ActionController::Railties::Paths.with(app) extend ::ActionController::Railties::Paths.with(app)
options.each { |k,v| send("#{k}=", v) } options.each { |k,v| send("#{k}=", v) }
......
...@@ -262,7 +262,7 @@ def install_helpers(destinations = [ActionController::Base, ActionView::Base], r ...@@ -262,7 +262,7 @@ def install_helpers(destinations = [ActionController::Base, ActionView::Base], r
module MountedHelpers module MountedHelpers
end end
def mounted_helpers(name = nil) def mounted_helpers(name = :main_app)
define_mounted_helper(name) if name define_mounted_helper(name) if name
MountedHelpers MountedHelpers
end end
......
...@@ -72,7 +72,7 @@ def klass.name; self end ...@@ -72,7 +72,7 @@ def klass.name; self end
class ::InsideEngineGeneratingController < ActionController::Base class ::InsideEngineGeneratingController < ActionController::Base
include BlogEngine.routes.url_helpers include BlogEngine.routes.url_helpers
include RailsApplication.routes.mounted_helpers(:app) include RailsApplication.routes.mounted_helpers
def index def index
render :text => posts_path render :text => posts_path
...@@ -83,9 +83,9 @@ def show ...@@ -83,9 +83,9 @@ def show
end end
def url_to_application def url_to_application
path = app.url_for( :controller => "outside_engine_generating", path = main_app.url_for(:controller => "outside_engine_generating",
:action => "index", :action => "index",
:only_path => true) :only_path => true)
render :text => path render :text => path
end end
......
...@@ -23,6 +23,7 @@ def initialize(*) ...@@ -23,6 +23,7 @@ def initialize(*)
@session_options = {} @session_options = {}
@time_zone = "UTC" @time_zone = "UTC"
@middleware = app_middleware @middleware = app_middleware
@asset_path = '/'
end end
def asset_path=(value) def asset_path=(value)
......
...@@ -61,7 +61,7 @@ def notify ...@@ -61,7 +61,7 @@ def notify
require "#{app_path}/config/environment" require "#{app_path}/config/environment"
assert Foo.method_defined?(:foo_path) assert Foo.method_defined?(:foo_path)
assert Foo.method_defined?(:app) assert Foo.method_defined?(:main_app)
assert_equal ["notify"], Foo.action_methods assert_equal ["notify"], Foo.action_methods
end end
......
...@@ -203,7 +203,7 @@ def baz ...@@ -203,7 +203,7 @@ def baz
assert_equal 'bar', last_response.body assert_equal 'bar', last_response.body
app_file 'config/routes.rb', <<-RUBY app_file 'config/routes.rb', <<-RUBY
AppTemplate::Application.routes.draw do |map| AppTemplate::Application.routes.draw do
match 'foo', :to => 'foo#baz' match 'foo', :to => 'foo#baz'
end end
RUBY RUBY
......
...@@ -281,6 +281,34 @@ def index ...@@ -281,6 +281,34 @@ def index
assert_equal expected, stripped_body assert_equal expected, stripped_body
end end
test "default application's asset_path" do
@plugin.write "config/routes.rb", <<-RUBY
Bukkits::Engine.routes.draw do
match "/foo" => "foo#index"
end
RUBY
@plugin.write "app/controllers/foo_controller.rb", <<-RUBY
class FooController < ActionController::Base
def index
end
end
RUBY
@plugin.write "app/views/foo/index.html.erb", <<-RUBY
<%= compute_public_path("/foo", "") %>
RUBY
boot_rails
env = Rack::MockRequest.env_for("/foo")
response = Bukkits::Engine.call(env)
stripped_body = response[2].body.strip
expected = "/bukkits/foo"
assert_equal expected, stripped_body
end
test "engine's files are served via ActionDispatch::Static" do test "engine's files are served via ActionDispatch::Static" do
add_to_config "config.serve_static_assets = true" add_to_config "config.serve_static_assets = true"
...@@ -437,7 +465,7 @@ def from_app ...@@ -437,7 +465,7 @@ def from_app
end end
def routes_helpers_in_view def routes_helpers_in_view
render :inline => "<%= foo_path %>, <%= app.bar_path %>" render :inline => "<%= foo_path %>, <%= main_app.bar_path %>"
end end
def polymorphic_path_without_namespace def polymorphic_path_without_namespace
......
...@@ -70,14 +70,14 @@ def index ...@@ -70,14 +70,14 @@ def index
end end
def generate_application_route def generate_application_route
path = app.url_for(:controller => "/main", path = main_app.url_for(:controller => "/main",
:action => "index", :action => "index",
:only_path => true) :only_path => true)
render :text => path render :text => path
end end
def application_route_in_view def application_route_in_view
render :inline => "<%= app.root_path %>" render :inline => "<%= main_app.root_path %>"
end end
end end
end end
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册