From 751b6be46481d7f149c909e63096b96c37b3d68f Mon Sep 17 00:00:00 2001 From: Marcel Molina Date: Thu, 12 Jan 2006 07:16:23 +0000 Subject: Allow auto-discovery of third party template library layouts. git-svn-id: http://svn-commit.rubyonrails.org/rails/trunk@3397 5ecf4fe2-1ee6-0310-87b1-e25e094e27de --- actionpack/CHANGELOG | 2 + actionpack/lib/action_controller/layout.rb | 4 +- actionpack/test/controller/layout_test.rb | 61 ++++++++++++++++++++++ .../test/fixtures/layout_tests/layouts/item.rhtml | 1 + .../layout_tests/layouts/layout_test.rhtml | 1 + .../layouts/third_party_template_library.mab | 1 + .../test/fixtures/layout_tests/views/hello.rhtml | 1 + 7 files changed, 69 insertions(+), 2 deletions(-) create mode 100644 actionpack/test/controller/layout_test.rb create mode 100644 actionpack/test/fixtures/layout_tests/layouts/item.rhtml create mode 100644 actionpack/test/fixtures/layout_tests/layouts/layout_test.rhtml create mode 100644 actionpack/test/fixtures/layout_tests/layouts/third_party_template_library.mab create mode 100644 actionpack/test/fixtures/layout_tests/views/hello.rhtml (limited to 'actionpack') diff --git a/actionpack/CHANGELOG b/actionpack/CHANGELOG index 2a2a088f27..5cd6a4dd3e 100644 --- a/actionpack/CHANGELOG +++ b/actionpack/CHANGELOG @@ -1,5 +1,7 @@ *SVN* +* Allow auto-discovery of third party template library layouts. [Marcel Molina Jr.] + * Have the form builder output radio button, not check box, when calling the radio button helper. #3331 [LouisStAmour@gmail.com] * Added assignment of the Autocompleter object created by JavaScriptMacroHelper#auto_complete_field to a local javascript variables [DHH] diff --git a/actionpack/lib/action_controller/layout.rb b/actionpack/lib/action_controller/layout.rb index 3ec125f088..4b396bb0d4 100644 --- a/actionpack/lib/action_controller/layout.rb +++ b/actionpack/lib/action_controller/layout.rb @@ -174,11 +174,11 @@ module ActionController #:nodoc: private def inherited(child) inherited_without_layout(child) - child.layout(child.controller_name) unless layout_list.grep(/^#{child.controller_name}\.r(?:x|ht)ml$/).empty? + child.layout(child.controller_name) unless layout_list.grep(/^#{child.controller_name}\.[a-z][0-9a-z]*$/).empty? end def layout_list - Dir.glob("#{template_root}/layouts/*.r{x,ht}ml").map { |layout| File.basename(layout) } + Dir.glob("#{template_root}/layouts/*.*").map { |layout| File.basename(layout) } end def add_layout_conditions(conditions) diff --git a/actionpack/test/controller/layout_test.rb b/actionpack/test/controller/layout_test.rb new file mode 100644 index 0000000000..57eb1f73b1 --- /dev/null +++ b/actionpack/test/controller/layout_test.rb @@ -0,0 +1,61 @@ +require File.dirname(__FILE__) + '/../abstract_unit' + +# The template_root must be set on Base and not LayoutTest so that LayoutTest's inherited method has access to +# the template_root when looking for a layout +ActionController::Base.template_root = File.dirname(__FILE__) + '/../fixtures/layout_tests/' + +class LayoutTest < ActionController::Base + def self.controller_path; 'views' end +end + +# Restore template root to be unset +ActionController::Base.template_root = nil + +class ProductController < LayoutTest +end + +class ItemController < LayoutTest +end + +class ThirdPartyTemplateLibraryController < LayoutTest +end + +class MabView + def initialize(view) + end + + def render(text, locals = {}) + text + end +end + +ActionView::Base::register_template_handler :mab, MabView + +class LayoutAutoDiscoveryTest < Test::Unit::TestCase + def setup + @request = ActionController::TestRequest.new + @response = ActionController::TestResponse.new + + @request.host = "www.nextangle.com" + end + + def test_application_layout_is_default_when_no_controller_match + @controller = ProductController.new + get :hello + assert_equal 'layout_test.rhtml hello.rhtml', @response.body + end + + def test_controller_name_layout_name_match + @controller = ItemController.new + get :hello + assert_equal 'item.rhtml hello.rhtml', @response.body + end + + def test_third_party_template_library_auto_discovers_layout + @controller = ThirdPartyTemplateLibraryController.new + get :hello + assert_equal 'layouts/third_party_template_library', @controller.active_layout + assert_equal 'Mab', @response.body + end + +end \ No newline at end of file diff --git a/actionpack/test/fixtures/layout_tests/layouts/item.rhtml b/actionpack/test/fixtures/layout_tests/layouts/item.rhtml new file mode 100644 index 0000000000..1bc7cbda06 --- /dev/null +++ b/actionpack/test/fixtures/layout_tests/layouts/item.rhtml @@ -0,0 +1 @@ +item.rhtml <%= yield %> \ No newline at end of file diff --git a/actionpack/test/fixtures/layout_tests/layouts/layout_test.rhtml b/actionpack/test/fixtures/layout_tests/layouts/layout_test.rhtml new file mode 100644 index 0000000000..c0f2642b40 --- /dev/null +++ b/actionpack/test/fixtures/layout_tests/layouts/layout_test.rhtml @@ -0,0 +1 @@ +layout_test.rhtml <%= yield %> \ No newline at end of file diff --git a/actionpack/test/fixtures/layout_tests/layouts/third_party_template_library.mab b/actionpack/test/fixtures/layout_tests/layouts/third_party_template_library.mab new file mode 100644 index 0000000000..018abfb0ac --- /dev/null +++ b/actionpack/test/fixtures/layout_tests/layouts/third_party_template_library.mab @@ -0,0 +1 @@ +Mab \ No newline at end of file diff --git a/actionpack/test/fixtures/layout_tests/views/hello.rhtml b/actionpack/test/fixtures/layout_tests/views/hello.rhtml new file mode 100644 index 0000000000..bbccf0913e --- /dev/null +++ b/actionpack/test/fixtures/layout_tests/views/hello.rhtml @@ -0,0 +1 @@ +hello.rhtml \ No newline at end of file -- cgit v1.2.3