view_models 1.5.5 → 1.5.6

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
data/TODO.textile ADDED
@@ -0,0 +1,4 @@
1
+ h1. Next up
2
+
3
+ * Explore possibilities to include Modules in hierarchical rendering.
4
+ * Encapsule the rather bloated hierarchical rendering in a HierarchicalRendering object that mediates the whole rendering process.
data/VERSION.yml CHANGED
@@ -1,4 +1,4 @@
1
1
  ---
2
2
  :minor: 5
3
- :patch: 5
3
+ :patch: 6
4
4
  :major: 1
@@ -0,0 +1,32 @@
1
+ h1. module ModulesInRenderHierarchy
2
+
3
+ Why would we need that?
4
+
5
+ h2. Situation
6
+
7
+ We have a music platform. There we have public profiles, and private profiles. And of each type a band, and a venue profile.
8
+
9
+ Public / Private have different functionality, and also Band / Venue.
10
+
11
+ The chose class structure looks like this:
12
+
13
+ @Public::Base < Project@, @Private::Base < Project@
14
+ @Public::Band < Public::Base@, @Public::Venue < Public::Base@, @Private::Band < Private::Base@, @Private::Venue < Private::Base@
15
+
16
+ To not have duplicate code, we include the functionality for Bands and Venues by using @include BandFunctionality@ and @include VenueFunctionality@.
17
+
18
+ h2. Problem
19
+
20
+ When rendering using the hierarchical rendering, we look up the templates as follows:
21
+
22
+ (For ViewModels::Public::Band#render_as :example, :format => :html)
23
+ # @views/view_models/public/band/_example.html.erb@
24
+ # @views/view_models/public/base/_example.html.erb@
25
+ # @views/view_models/project/_example.html.erb@
26
+
27
+ So the example template is taken from the @public/band@ directory. Why not from a @functionality/band@ directory (assuming the module is named @Functionality::Band@). The reason for this is that the current (v1.5.4) hierarchical rendering process uses superclass, which hops over Modules, rather than using ancestors, which wouldn't.
28
+
29
+ h2. Solution
30
+
31
+ #. Either override superclass, with all associated problems
32
+ #. Or refit the whole hierarchical rendering into a HierarchicalRendering Class. (Preferred)
@@ -0,0 +1,21 @@
1
+ module ModulesInRenderHierarchy
2
+
3
+ def self.included klass
4
+ klass.extend ClassMethods
5
+ klass.metaclass.alias_method_chain :include, :superclass_override
6
+ end
7
+
8
+ module ClassMethods
9
+ def include_with_superclass_override mod
10
+ original_superclass = superclass
11
+ self.send :include_without_superclass_override, mod
12
+ mod.metaclass.send :define_method, :superclass do
13
+ original_superclass
14
+ end
15
+ metaclass.send :define_method, :superclass do
16
+ mod
17
+ end
18
+ end
19
+ end
20
+
21
+ end
@@ -93,7 +93,7 @@ module ViewModels
93
93
  #
94
94
  # TODO Think about raising the MissingTemplateError here.
95
95
  #
96
- def next
96
+ def next_in_render_hierarchy
97
97
  superclass
98
98
  end
99
99
 
@@ -121,7 +121,7 @@ module ViewModels
121
121
  def template_path view, options
122
122
  raise_template_error_with options.error_message if inheritance_chain_ends?
123
123
 
124
- template_path_from(view, options) || self.next.template_path(view, options)
124
+ template_path_from(view, options) || self.next_in_render_hierarchy.template_path(view, options)
125
125
  end
126
126
 
127
127
  # Accesses the view to find a suitable template path.
data/rails/init.rb CHANGED
@@ -1,3 +1,5 @@
1
+ # require 'experimental/modules_in_render_hierarchy'
2
+
1
3
  require 'extensions/active_record'
2
4
  require 'extensions/model_reader'
3
5
 
@@ -12,7 +14,5 @@ require 'helpers/view'
12
14
  require 'helpers/rails'
13
15
  require 'helpers/collection'
14
16
 
15
- #
16
- # ActionController::Base.send :helper, ViewModels::Helpers::Rails
17
17
  ActionController::Base.send :include, ViewModels::Helpers::Rails
18
18
  ActionView::Base.send :include, ViewModels::Helpers::Rails
@@ -1,5 +1,7 @@
1
1
  require File.join(File.dirname(__FILE__), '../spec_helper')
2
2
 
3
+ # require File.join(File.dirname(__FILE__), '../../lib/experimental/modules_in_render_hierarchy')
4
+
3
5
  require File.join(File.dirname(__FILE__), 'models/subclass')
4
6
  require File.join(File.dirname(__FILE__), 'models/sub_subclass')
5
7
 
@@ -10,6 +12,7 @@ require 'view_models/base'
10
12
  require File.join(File.dirname(__FILE__), 'view_models/project')
11
13
  require File.join(File.dirname(__FILE__), 'view_models/subclass')
12
14
  require File.join(File.dirname(__FILE__), 'view_models/sub_subclass')
15
+ require File.join(File.dirname(__FILE__), 'view_models/module_for_rendering')
13
16
 
14
17
  require 'action_controller'
15
18
  require 'action_controller/test_process'
@@ -46,6 +49,18 @@ describe 'Integration' do
46
49
 
47
50
  before(:all) { puts "\n#{self.send(:description_args)[0]}:" }
48
51
 
52
+ # context 'experimental inclusion of module in render hierarchy' do
53
+ # before(:each) do
54
+ # ViewModels::Base.send :include, ModulesInRenderHierarchy
55
+ # @view_model.class.send :include, ModuleForRendering
56
+ # end
57
+ # describe 'render_as' do
58
+ # it 'should description' do
59
+ # @view_model.render_as(:not_found_in_sub_subclass_but_in_module).should == '_not_found_in_sub_subclass_but_in_module.erb'
60
+ # end
61
+ # end
62
+ # end
63
+
49
64
  describe 'ActiveRecord Extensions' do
50
65
  before(:each) do
51
66
  @view_model.extend ViewModels::Extensions::ActiveRecord
@@ -0,0 +1,7 @@
1
+ module ModuleForRendering
2
+
3
+ def module_method
4
+ "Hello!"
5
+ end
6
+
7
+ end
@@ -0,0 +1 @@
1
+ _not_found_in_sub_subclass_but_in_module.erb
metadata CHANGED
@@ -5,8 +5,8 @@ version: !ruby/object:Gem::Version
5
5
  segments:
6
6
  - 1
7
7
  - 5
8
- - 5
9
- version: 1.5.5
8
+ - 6
9
+ version: 1.5.6
10
10
  platform: ruby
11
11
  authors:
12
12
  - Florian Hanke
@@ -17,7 +17,7 @@ autorequire:
17
17
  bindir: bin
18
18
  cert_chain: []
19
19
 
20
- date: 2010-03-03 00:00:00 +01:00
20
+ date: 2010-03-04 00:00:00 +01:00
21
21
  default_executable:
22
22
  dependencies:
23
23
  - !ruby/object:Gem::Dependency
@@ -61,6 +61,7 @@ files:
61
61
  - MIT-LICENSE
62
62
  - README.textile
63
63
  - Rakefile
64
+ - TODO.textile
64
65
  - VERSION.yml
65
66
  - generators/view_models/USAGE
66
67
  - generators/view_models/templates/README
@@ -78,6 +79,8 @@ files:
78
79
  - generators/view_models/templates/views/view_models/collection/_table.html.haml
79
80
  - generators/view_models/templates/views/view_models/collection/_table.text.erb
80
81
  - generators/view_models/view_models_generator.rb
82
+ - lib/experimental/README.textile
83
+ - lib/experimental/modules_in_render_hierarchy.rb
81
84
  - lib/extensions/active_record.rb
82
85
  - lib/extensions/model_reader.rb
83
86
  - lib/extensions/view.rb
@@ -94,6 +97,7 @@ files:
94
97
  - spec/integration/integration_spec.rb
95
98
  - spec/integration/models/sub_subclass.rb
96
99
  - spec/integration/models/subclass.rb
100
+ - spec/integration/view_models/module_for_rendering.rb
97
101
  - spec/integration/view_models/project.rb
98
102
  - spec/integration/view_models/sub_subclass.rb
99
103
  - spec/integration/view_models/subclass.rb
@@ -101,6 +105,7 @@ files:
101
105
  - spec/integration/views/view_models/collection/_collection.text.erb
102
106
  - spec/integration/views/view_models/collection/_list.html.erb
103
107
  - spec/integration/views/view_models/collection/_list.text.erb
108
+ - spec/integration/views/view_models/module_for_rendering/_not_found_in_sub_subclass_but_in_module.erb
104
109
  - spec/integration/views/view_models/sub_subclass/_capture_in_template.erb
105
110
  - spec/integration/views/view_models/sub_subclass/_capture_in_view_model.erb
106
111
  - spec/integration/views/view_models/sub_subclass/_collection_example.html.erb
@@ -169,6 +174,7 @@ test_files:
169
174
  - spec/integration/integration_spec.rb
170
175
  - spec/integration/models/sub_subclass.rb
171
176
  - spec/integration/models/subclass.rb
177
+ - spec/integration/view_models/module_for_rendering.rb
172
178
  - spec/integration/view_models/project.rb
173
179
  - spec/integration/view_models/sub_subclass.rb
174
180
  - spec/integration/view_models/subclass.rb