Commit e40a294a65c9e58f19eeb619f29b06189bb6f7e2

Authored by AntonioTerceiro
1 parent e5065105

r249@sede: terceiro | 2007-07-29 19:24:09 -0300

ActionItem0: adding support for design inheritance 
 


git-svn-id: https://svn.colivre.coop.br/svn/noosfero/trunk@253 3f533792-8f58-4932-b0fe-aaf55b0a4547
vendor/plugins/design/README
@@ -48,6 +48,12 @@ The argument do +design_display_boxes()+ is the content you want to be the main @@ -48,6 +48,12 @@ The argument do +design_display_boxes()+ is the content you want to be the main
48 content. Almost always you'll want to pass +yield+ (the resulting content for 48 content. Almost always you'll want to pass +yield+ (the resulting content for
49 the current action) there, but you can pass anything you want. 49 the current action) there, but you can pass anything you want.
50 50
  51 +== Controller subclassing and design
  52 +
  53 +Designs are inherited through the inheritance tree. This way you can for
  54 +example declare the use of a design in ApplicationController and let the other
  55 +controllers abstract that fact that they are using design.
  56 +
51 == Storing design information in ActiveRecord models: +acts_as_design+ 57 == Storing design information in ActiveRecord models: +acts_as_design+
52 58
53 You can also use ActiveRecord objects 59 You can also use ActiveRecord objects
vendor/plugins/design/init.rb
@@ -16,7 +16,7 @@ class ActionController::Base @@ -16,7 +16,7 @@ class ActionController::Base
16 @design_plugin_config = config 16 @design_plugin_config = config
17 17
18 def self.design_plugin_config 18 def self.design_plugin_config
19 - @design_plugin_config 19 + @design_plugin_config || self.superclass.design_plugin_config
20 end 20 end
21 21
22 include Design 22 include Design
vendor/plugins/design/test/design_test.rb
@@ -52,8 +52,11 @@ class DesignTest < Test::Unit::TestCase @@ -52,8 +52,11 @@ class DesignTest < Test::Unit::TestCase
52 52
53 def test_subclass_controller_can_override_superclass_design_holder 53 def test_subclass_controller_can_override_superclass_design_holder
54 assert_equal 'sample_object', ProxyDesignHolderTestController.send(:design_plugin_config)[:holder] 54 assert_equal 'sample_object', ProxyDesignHolderTestController.send(:design_plugin_config)[:holder]
55 - assert_equal 'another_object', InheritanceDesignTestController.send(:design_plugin_config)[:holder] 55 + assert_equal 'another_object', InheritanceWithOverrideDesignTestController.send(:design_plugin_config)[:holder]
  56 + end
56 57
  58 + def test_subclass_should_inherit_supeclass_design
  59 + assert_equal 'sample_object', InheritanceDesignTestController.send(:design_plugin_config)[:holder]
57 end 60 end
58 61
59 end 62 end
vendor/plugins/design/test/test_helper.rb
@@ -60,10 +60,14 @@ class AnotherTestDesignHolder @@ -60,10 +60,14 @@ class AnotherTestDesignHolder
60 attr_accessor :template, :theme, :icon_theme, :boxes 60 attr_accessor :template, :theme, :icon_theme, :boxes
61 end 61 end
62 62
63 -class InheritanceDesignTestController < ProxyDesignHolderTestController 63 +class InheritanceWithOverrideDesignTestController < ProxyDesignHolderTestController
64 design :holder => 'another_object' 64 design :holder => 'another_object'
65 end 65 end
66 66
  67 +class InheritanceDesignTestController < ProxyDesignHolderTestController
  68 + # nothing
  69 +end
  70 +
67 class DesignEditorTestController < ActionController::Base 71 class DesignEditorTestController < ActionController::Base
68 design_editor :holder => 'sample_object' 72 design_editor :holder => 'sample_object'
69 def initialize 73 def initialize