view_models 2.0.1 → 3.0.0

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.
Files changed (157) hide show
  1. data/.bundle/config +2 -0
  2. data/.gitignore +8 -0
  3. data/.rspec +2 -0
  4. data/.rvmrc +1 -0
  5. data/.travis.yml +19 -0
  6. data/.yardoc/checksums +13 -0
  7. data/.yardoc/object_types +0 -0
  8. data/.yardoc/objects/root.dat +0 -0
  9. data/.yardoc/proxy_types +0 -0
  10. data/Appraisals +15 -0
  11. data/CHANGELOG +31 -0
  12. data/Gemfile +13 -0
  13. data/Gemfile.lock +174 -0
  14. data/MIT-LICENSE +20 -0
  15. data/README.textile +199 -0
  16. data/Rakefile +24 -0
  17. data/doc/ModulesInRenderHierarchy.html +186 -0
  18. data/doc/ModulesInRenderHierarchy/ClassMethods.html +188 -0
  19. data/doc/ViewModels.html +202 -0
  20. data/doc/ViewModels/Base.html +1342 -0
  21. data/doc/ViewModels/ContextExtractor.html +406 -0
  22. data/doc/ViewModels/Extensions.html +128 -0
  23. data/doc/ViewModels/Extensions/ModelReader.html +255 -0
  24. data/doc/ViewModels/Extensions/ModelReader/FilteredDelegationInstaller.html +908 -0
  25. data/doc/ViewModels/Extensions/ModelReader/Options.html +551 -0
  26. data/doc/ViewModels/Extensions/View.html +303 -0
  27. data/doc/ViewModels/Helpers.html +129 -0
  28. data/doc/ViewModels/Helpers/Mapping.html +562 -0
  29. data/doc/ViewModels/Helpers/Mapping/Collection.html +844 -0
  30. data/doc/ViewModels/Helpers/View.html +287 -0
  31. data/doc/ViewModels/PathStore.html +745 -0
  32. data/doc/ViewModels/RenderOptions.html +126 -0
  33. data/doc/ViewModels/RenderOptions/Base.html +1187 -0
  34. data/doc/ViewModels/RenderOptions/Partial.html +231 -0
  35. data/doc/ViewModels/RenderOptions/Template.html +231 -0
  36. data/doc/ViewModels/View.html +414 -0
  37. data/doc/ViewModelsGenerator.html +410 -0
  38. data/doc/_index.html +317 -0
  39. data/doc/class_list.html +53 -0
  40. data/doc/css/common.css +1 -0
  41. data/doc/css/full_list.css +57 -0
  42. data/doc/css/style.css +328 -0
  43. data/doc/file.README.html +113 -0
  44. data/doc/file_list.html +55 -0
  45. data/doc/frames.html +28 -0
  46. data/doc/index.html +113 -0
  47. data/doc/js/app.js +214 -0
  48. data/doc/js/full_list.js +173 -0
  49. data/doc/js/jquery.js +4 -0
  50. data/doc/method_list.html +628 -0
  51. data/doc/top-level-namespace.html +114 -0
  52. data/feature_support/testapp/app/controllers/heroes_controller.rb +6 -0
  53. data/feature_support/testapp/app/controllers/users_controller.rb +6 -0
  54. data/feature_support/testapp/app/helpers/application_helper.rb +8 -0
  55. data/feature_support/testapp/app/models/hero.rb +8 -0
  56. data/feature_support/testapp/app/models/user.rb +3 -0
  57. data/feature_support/testapp/app/view_models/hero.rb +8 -0
  58. data/feature_support/testapp/app/view_models/test.rb +8 -0
  59. data/feature_support/testapp/app/view_models/user.rb +14 -0
  60. data/feature_support/testapp/app/views/heroes/show.html.slim +6 -0
  61. data/feature_support/testapp/app/views/users/_box.html.slim +8 -0
  62. data/feature_support/testapp/app/views/users/show.html.slim +6 -0
  63. data/feature_support/testapp/config/application.rb +64 -0
  64. data/feature_support/testapp/config/cucumber.yml +8 -0
  65. data/feature_support/testapp/config/database.yml +28 -0
  66. data/feature_support/testapp/config/environments/cucumber.rb +11 -0
  67. data/feature_support/testapp/config/environments/test.rb +27 -0
  68. data/feature_support/testapp/config/routes.rb +4 -0
  69. data/feature_support/testapp/db/migrate/1_create_users.rb +13 -0
  70. data/feature_support/testapp/features/inheritance.feature +16 -0
  71. data/feature_support/testapp/features/step_definitions/testapp_steps.rb +16 -0
  72. data/feature_support/testapp/features/support/env.rb +13 -0
  73. data/feature_support/testapp/features/users.feature +15 -0
  74. data/feature_support/testapp/lib/tasks/cucumber.rake +31 -0
  75. data/feature_support/testapp/spec/factories/heroes.rb +7 -0
  76. data/feature_support/testapp/spec/factories/users.rb +7 -0
  77. data/features/rails_integration.feature +21 -0
  78. data/features/step_definitions/rails_steps.rb +112 -0
  79. data/features/support/env.rb +6 -0
  80. data/gemfiles/3.0.Gemfile +13 -0
  81. data/gemfiles/3.1.Gemfile +15 -0
  82. data/gemfiles/3.2.gemfile +15 -0
  83. data/lib/rails/generators/view_models/USAGE +6 -0
  84. data/lib/rails/generators/view_models/templates/views/_collection.html.erb +6 -0
  85. data/lib/{rails2/generators/view_models/templates/views/view_models/collection → rails/generators/view_models/templates/views}/_collection.html.haml +1 -2
  86. data/lib/rails/generators/view_models/templates/views/_collection.html.slim +6 -0
  87. data/lib/{rails2/generators/view_models/templates/views/_empty.html.haml → rails/generators/view_models/templates/views/_empty.html.erb} +0 -0
  88. data/lib/rails/generators/view_models/templates/views/_empty.html.haml +0 -0
  89. data/lib/rails/generators/view_models/templates/views/_empty.html.slim +0 -0
  90. data/lib/rails/generators/view_models/templates/views/_list.html.erb +6 -0
  91. data/lib/rails/generators/view_models/templates/views/_list.html.haml +4 -0
  92. data/lib/rails/generators/view_models/templates/views/_list.html.slim +5 -0
  93. data/lib/rails/generators/view_models/templates/views/_pagination.html.erb +18 -0
  94. data/lib/{rails2/generators/view_models/templates/views/view_models/collection → rails/generators/view_models/templates/views}/_pagination.html.haml +2 -2
  95. data/lib/rails/generators/view_models/templates/views/_pagination.html.slim +12 -0
  96. data/lib/rails/generators/view_models/templates/views/_table.html.erb +10 -0
  97. data/lib/{rails2/generators/view_models/templates/views/view_models/collection → rails/generators/view_models/templates/views}/_table.html.haml +0 -0
  98. data/lib/rails/generators/view_models/templates/views/_table.html.slim +5 -0
  99. data/lib/rails/generators/view_models/view_models_generator.rb +57 -0
  100. data/lib/view_models.rb +15 -5
  101. data/lib/{shared/lib/view_models → view_models}/base.rb +148 -37
  102. data/lib/{shared/lib/view_models → view_models}/context_extractor.rb +6 -2
  103. data/lib/{shared/lib/view_models → view_models}/extensions/model_reader.rb +27 -13
  104. data/lib/{rails2/lib → view_models}/extensions/view.rb +6 -1
  105. data/lib/view_models/helpers/collection.rb +113 -0
  106. data/lib/{shared/lib/view_models → view_models}/helpers/mapping.rb +12 -15
  107. data/lib/{rails2/lib → view_models}/helpers/view.rb +5 -1
  108. data/lib/{shared/lib/view_models → view_models}/path_store.rb +6 -1
  109. data/lib/{shared/lib/view_models → view_models}/render_options.rb +19 -4
  110. data/lib/view_models/version.rb +5 -0
  111. data/lib/{rails2/lib/view_models → view_models}/view.rb +7 -6
  112. data/spec/{rails2/lib → lib}/view_models/base_spec.rb +38 -5
  113. data/spec/{rails2/lib → lib/view_models}/extensions/model_reader_spec.rb +4 -4
  114. data/spec/{shared/lib → lib/view_models}/helpers/collection_spec.rb +21 -1
  115. data/spec/{shared/lib → lib/view_models}/helpers/mapping_spec.rb +6 -5
  116. data/spec/{rails2/lib → lib/view_models}/helpers/view_spec.rb +1 -1
  117. data/spec/lib/view_models/view_spec.rb +42 -0
  118. data/spec/spec_helper.rb +32 -0
  119. data/spec/spec_helper_extensions.rb +13 -0
  120. data/view_models.gemspec +36 -0
  121. metadata +411 -142
  122. data/lib/init.rb +0 -1
  123. data/lib/padrino/README.textile +0 -3
  124. data/lib/padrino/init.rb +0 -10
  125. data/lib/padrino/lib/helpers/collection.rb +0 -27
  126. data/lib/padrino/lib/padrino/view_models.rb +0 -19
  127. data/lib/padrino/lib/view_models/base.rb +0 -65
  128. data/lib/rails2/README.textile +0 -3
  129. data/lib/rails2/TODO.textile +0 -5
  130. data/lib/rails2/generators/view_models/USAGE +0 -6
  131. data/lib/rails2/generators/view_models/templates/README +0 -1
  132. data/lib/rails2/generators/view_models/templates/spec/view_model_spec.rb +0 -7
  133. data/lib/rails2/generators/view_models/templates/view_models/view_model.rb +0 -5
  134. data/lib/rails2/generators/view_models/templates/views/view_models/collection/_collection.html.erb +0 -1
  135. data/lib/rails2/generators/view_models/templates/views/view_models/collection/_collection.text.erb +0 -6
  136. data/lib/rails2/generators/view_models/templates/views/view_models/collection/_list.html.erb +0 -1
  137. data/lib/rails2/generators/view_models/templates/views/view_models/collection/_list.text.erb +0 -6
  138. data/lib/rails2/generators/view_models/templates/views/view_models/collection/_pagination.text.erb +0 -3
  139. data/lib/rails2/generators/view_models/templates/views/view_models/collection/_table.text.erb +0 -10
  140. data/lib/rails2/generators/view_models/view_models_generator.rb +0 -47
  141. data/lib/rails2/init.rb +0 -18
  142. data/lib/rails2/lib/experimental/README.textile +0 -32
  143. data/lib/rails2/lib/experimental/modules_in_render_hierarchy.rb +0 -21
  144. data/lib/rails2/lib/helpers/collection.rb +0 -27
  145. data/lib/rails2/lib/view_models.rb +0 -1
  146. data/lib/rails2/lib/view_models/base.rb +0 -99
  147. data/lib/shared/README.textile +0 -3
  148. data/lib/shared/init.rb +0 -11
  149. data/lib/shared/lib/view_models.rb +0 -4
  150. data/lib/shared/lib/view_models/extensions/active_record.rb +0 -27
  151. data/lib/shared/lib/view_models/helpers/collection.rb +0 -110
  152. data/spec/padrino/integration/integration_spec.rb +0 -287
  153. data/spec/padrino/lib/helpers/collection_spec.rb +0 -30
  154. data/spec/rails2/integration/integration_spec.rb +0 -279
  155. data/spec/rails2/lib/extensions/active_record_spec.rb +0 -31
  156. data/spec/rails2/lib/helpers/collection_spec.rb +0 -30
  157. data/spec/rails2/lib/view_models/view_spec.rb +0 -12
@@ -1 +0,0 @@
1
- require File.join(File.dirname(__FILE__), '/view_models')
@@ -1,3 +0,0 @@
1
- h1. View Models for Padrino
2
-
3
- This is the Padrino specific folder of the view models.
@@ -1,10 +0,0 @@
1
- this = File.dirname __FILE__
2
-
3
- require File.join(this, '/../shared/init')
4
-
5
- ViewModels::Helpers::Mapping
6
-
7
- require File.join(this, '/lib/view_models/base')
8
- require File.join(this, '/lib/helpers/collection')
9
-
10
- require File.join(this, '/lib/padrino/view_models')
@@ -1,27 +0,0 @@
1
- module ViewModels
2
- module Helpers
3
- module Mapping
4
-
5
- # The Collection view_model helper has the purpose of presenting presentable collections.
6
- # * Render as list
7
- # * Render as table
8
- # * Render as collection
9
- # * Render a pagination
10
- #
11
- class Collection
12
- private
13
-
14
- # Helper method that renders a partial in the context of the context instance.
15
- #
16
- # Example:
17
- # If the collection view_model helper has been instantiated in the context
18
- # of a controller, render will be called in the controller.
19
- #
20
- def render_partial name, locals
21
- @context.instance_eval { render "view_models/collection/_#{name}", :locals => locals }
22
- end
23
- end
24
-
25
- end
26
- end
27
- end
@@ -1,19 +0,0 @@
1
- module Padrino
2
- module ViewModels
3
-
4
- class << self
5
- def registered app
6
- app.send :include, ::ViewModels::Helpers::Mapping
7
-
8
- Padrino.set_load_paths File.join(app.root, "/view_models")
9
-
10
- Padrino.require_dependencies File.join(app.root, "/view_models.rb")
11
- # FIXME Needs to require in a specific order.
12
- #
13
- Padrino.require_dependencies File.join(app.root, "/view_models/**/*.rb")
14
- end
15
- alias :included :registered
16
- end
17
-
18
- end
19
- end
@@ -1,65 +0,0 @@
1
- # Base Module for Padrino ViewModels.
2
- #
3
- module ViewModels
4
-
5
- # Base class from which all view_models inherit.
6
- #
7
- class Base
8
-
9
- # Make helper and helper_method available
10
- #
11
- # TODO Rewrite Padrino style.
12
- #
13
- # include ActionController::Helpers
14
-
15
- class << self
16
-
17
- # Alias the context_method to the padrino-centric app_method.
18
- #
19
- alias app_method context_method
20
-
21
- # Sets the view format and tries to render the given options.
22
- #
23
- # Note: Also caches [path, name, format] => template path.
24
- #
25
- def render renderer, options
26
- # options.format! view
27
- renderer.instance_variable_set(:@_content_type, options.format || :html)
28
- path_store.cached options do
29
- path = template_path renderer, options
30
- options.file = path
31
- renderer.send :render, path.to_s, options.to_render_options
32
- end
33
- end
34
-
35
- # FIXME Need to use padrino register for this.
36
- #
37
- alias_method :register, :include
38
-
39
- protected
40
-
41
- # Accesses the view to find a suitable template path.
42
- #
43
- # Returns nil if a template cannot be found.
44
- #
45
- def template_path_from renderer, options
46
- template = renderer.send :resolve_template, tentative_template_path(options)
47
- # TODO!
48
- #
49
- template && template.first.to_s # was .path
50
- rescue Padrino::Rendering::TemplateNotFound => t
51
- nil
52
- end
53
-
54
- end
55
-
56
- alias app context
57
-
58
- protected
59
-
60
- def renderer
61
- app
62
- end
63
-
64
- end
65
- end
@@ -1,3 +0,0 @@
1
- h1. View Models for Rails
2
-
3
- This is the Rails specific folder of the view models.
@@ -1,5 +0,0 @@
1
- h1. Next up
2
-
3
- * Encapsule the rather bloated hierarchical rendering in a HierarchicalRendering object that mediates the whole rendering process.
4
-
5
- --* Explore possibilities to include Modules in hierarchical rendering.--
@@ -1,6 +0,0 @@
1
- Usage:
2
- script/generate view_models <view model class name>
3
- script/generate view_models User
4
-
5
- script/generate view_models <view model class name> <partials for render_as, separated by space>
6
- script/generate view_models User compact extensive list_item table_item
@@ -1 +0,0 @@
1
- View Model generated. Have fun!
@@ -1,7 +0,0 @@
1
- require File.dirname(__FILE__) + '/../spec_helper'
2
-
3
- describe ViewModels::<%= class_name %> do
4
-
5
-
6
-
7
- end
@@ -1,5 +0,0 @@
1
- class ViewModels::<%= class_name %> < ViewModels::Project
2
-
3
- # model_reader :icon, :filter_through => [:h]
4
-
5
- end
@@ -1 +0,0 @@
1
- <ul class="collection"><%- collection.each do |item| -%><%- view_model = view_model_for item -%><li><%- options = template_format ? { :format => template_format } : {} -%><%= view_model.render_as template_name, options -%></li><%= separator unless item == collection.last %><%- end -%></ul>
@@ -1,6 +0,0 @@
1
- <%- collection.each do |item| -%>
2
- <%- view_model = view_model_for item -%>
3
- <%- options = (template_format ? { :format => template_format } : {}) -%>
4
- <%= view_model.render_as template_name, options -%>
5
- <%= separator unless item == collection.entries.last -%>
6
- <%- end -%>
@@ -1 +0,0 @@
1
- <ol class="collection"><%- collection.each do |item| -%><%- view_model = view_model_for item -%><li><%- options = (template_format ? { :format => template_format } : {}) -%><%= view_model.render_as template_name, options -%></li><%= separator unless item == collection.last %><%- end -%></ol>
@@ -1,6 +0,0 @@
1
- <% collection.each do |item| -%>
2
- <% view_model = view_model_for item -%>
3
- <%- options = (template_format ? { :format => template_format } : {}) -%>
4
- <%= view_model.render_as template_name, options -%>
5
- <%= separator || '\n' unless item == collection.entries.last -%>
6
- <% end -%>
@@ -1,3 +0,0 @@
1
- <%- if collection.page_count > 1 -%>
2
- <%= "Page #{collection.page} of #{collection.page_count}." -%>
3
- <%- end -%>
@@ -1,10 +0,0 @@
1
- <%- width = 66 -%>
2
- <%= '-'*width %>
3
- <% collection.each do |item| -%>
4
- <% view_model = view_model_for(item, self) -%>
5
- <%- result = view_model.render_as(template_name) -%>
6
- <%= '|' + "%-#{width}s"%(result[0,width]) + '|' -%>
7
- <%- p ('|' + "%-#{width}s"%(result[0,width]) + '|') %>
8
- <%= separator || ">#{'-'*(width-2)}<" unless item == collection.entries.last %>
9
- <% end -%>
10
- <%= '-'*width %>
@@ -1,47 +0,0 @@
1
- class ViewModelsGenerator < Rails::Generator::NamedBase
2
- def manifest
3
- record do |m|
4
-
5
- # Check for class naming collisions.
6
- #
7
- m.class_collisions "ViewModels::#{class_name}"
8
-
9
- # ViewModels
10
- #
11
- m.directory 'app/view_models'
12
- m.template "view_models/view_model.rb", "app/view_models/#{file_name}.rb"
13
-
14
- # Specs
15
- #
16
- m.directory "spec/app/view_models"
17
- m.template "spec/view_model_spec.rb", "spec/app/view_models/#{file_name}_spec.rb"
18
-
19
- # Views
20
- #
21
- m.directory "app/views/view_models"
22
- m.directory "app/views/view_models/#{file_name}"
23
- actions << 'list_item' if actions.empty?
24
- actions.each do |action|
25
- m.template "views/_empty.html.haml", "app/views/view_models/#{file_name}/_#{action}.html.haml"
26
- end
27
-
28
- # Copy collection views.
29
- #
30
- m.directory "app/views/view_models/collection"
31
- m.file "views/view_models/collection/_collection.html.haml", "app/views/view_models/collection/_collection.html.haml"
32
- m.file "views/view_models/collection/_collection.text.erb", "app/views/view_models/collection/_collection.text.erb"
33
- m.file "views/view_models/collection/_list.html.haml", "app/views/view_models/collection/_list.html.haml"
34
- m.file "views/view_models/collection/_list.text.erb", "app/views/view_models/collection/_list.text.erb"
35
- m.file "views/view_models/collection/_pagination.html.haml", "app/views/view_models/collection/_pagination.html.haml"
36
- m.file "views/view_models/collection/_pagination.text.erb", "app/views/view_models/collection/_pagination.text.erb"
37
- m.file "views/view_models/collection/_table.html.haml", "app/views/view_models/collection/_table.html.haml"
38
- m.file "views/view_models/collection/_table.text.erb", "app/views/view_models/collection/_table.text.erb"
39
-
40
- # Show README.
41
- #
42
- m.readme "README"
43
-
44
- end
45
- end
46
-
47
- end
@@ -1,18 +0,0 @@
1
- # require 'experimental/modules_in_render_hierarchy'
2
-
3
- this = File.dirname __FILE__
4
-
5
- require File.join(this, '/lib/view_models')
6
- require File.join(this, '/../shared/init')
7
- require File.join(this, '/lib/view_models/base')
8
- require File.join(this, '/lib/view_models/view')
9
-
10
- require File.join(this, '/lib/helpers/view')
11
- require File.join(this, '/lib/helpers/collection')
12
-
13
- # TODO How was the view models generator included?
14
- #
15
- # require File.join(this, '/generators/view_models/view_models_generator')
16
-
17
- ActionController::Base.send :include, ViewModels::Helpers::Mapping
18
- ActionView::Base.send :include, ViewModels::Helpers::Mapping
@@ -1,32 +0,0 @@
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)
@@ -1,21 +0,0 @@
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
@@ -1,27 +0,0 @@
1
- module ViewModels
2
- module Helpers
3
- module Mapping
4
-
5
- # The Collection view_model helper has the purpose of presenting presentable collections.
6
- # * Render as list
7
- # * Render as table
8
- # * Render as collection
9
- # * Render a pagination
10
- #
11
- class Collection
12
- private
13
-
14
- # Helper method that renders a partial in the context of the context instance.
15
- #
16
- # Example:
17
- # If the collection view_model helper has been instantiated in the context
18
- # of a controller, render will be called in the controller.
19
- #
20
- def render_partial name, locals
21
- @context.instance_eval { render :partial => "view_models/collection/#{name}", :locals => locals }
22
- end
23
- end
24
-
25
- end
26
- end
27
- end
@@ -1 +0,0 @@
1
- require File.join(File.dirname(__FILE__), '/../../shared/lib/view_models')
@@ -1,99 +0,0 @@
1
- # Base Module for Rails 2 ViewModels.
2
- #
3
- module ViewModels
4
-
5
- # Base class from which all view_models inherit.
6
- #
7
- class Base
8
-
9
- # Make helper and helper_method available
10
- #
11
- include ActionController::Helpers
12
-
13
- # This is really only needed because some Rails helpers access
14
- # @controller directly.
15
- # It's really bad.
16
- #
17
- # TODO Make it call super.
18
- #
19
- def initialize model, controller_or_view
20
- @model = model
21
- @context = @controller = ContextExtractor.new(controller_or_view).extract
22
- end
23
-
24
- class << self
25
-
26
- # Alias the context_method to the rails-centric controller_method.
27
- #
28
- alias controller_method context_method
29
-
30
- # Wrapper for add_template_helper in ActionController::Helpers, also
31
- # includes given helper in the view_model
32
- #
33
- # TODO extract into module
34
- #
35
- unless instance_methods.include?('old_add_template_helper')
36
- alias old_add_template_helper add_template_helper
37
- def add_template_helper helper_module
38
- include helper_module
39
- old_add_template_helper helper_module
40
- end
41
- end
42
-
43
- # Sets the view format and tries to render the given options.
44
- #
45
- # Note: Also caches [path, name, format] => template path.
46
- #
47
- def render renderer, options
48
- options.format! renderer
49
- path_store.cached options do
50
- options.file = template_path renderer, options
51
- renderer.render_with options
52
- end
53
- end
54
-
55
- protected
56
-
57
- # Accesses the view to find a suitable template path.
58
- #
59
- def template_path_from renderer, options
60
- template = renderer.find_template tentative_template_path(options)
61
-
62
- template && template.path
63
- end
64
-
65
- end # class << self
66
-
67
- # Delegate context methods.
68
- #
69
- context_method :form_authenticity_token, :protect_against_forgery?, :request_forgery_protection_token
70
-
71
- # Make all the dynamically generated routes (restful routes etc.)
72
- # available in the view_model
73
- #
74
- ActionController::Routing::Routes.install_helpers self
75
-
76
- protected
77
-
78
- alias controller context
79
-
80
- # CaptureHelper needs this.
81
- #
82
- attr_accessor :output_buffer
83
-
84
- # Returns a view instance for render_xxx.
85
- #
86
- # TODO Try getting a view instance from the controller.
87
- #
88
- def renderer
89
- # view = if controller.response.template
90
- # controller.response.template
91
- # else
92
- View.new controller, master_helper_module
93
- # end
94
-
95
- # view.extend Extensions::View
96
- end
97
-
98
- end
99
- end