topherfangio-inherit_views 1.0.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (45) hide show
  1. data/History.txt +27 -0
  2. data/License.txt +20 -0
  3. data/README.rdoc +65 -0
  4. data/Rakefile +64 -0
  5. data/Todo.txt +0 -0
  6. data/garlic.rb +33 -0
  7. data/inherit_views.gemspec +17 -0
  8. data/init.rb +5 -0
  9. data/lib/inherit_views.rb +166 -0
  10. data/spec/app.rb +47 -0
  11. data/spec/controllers/a_controller_spec.rb +44 -0
  12. data/spec/controllers/b_controller_spec.rb +70 -0
  13. data/spec/controllers/c_controller_spec.rb +71 -0
  14. data/spec/controllers/d_controller_spec.rb +21 -0
  15. data/spec/controllers/normal_controller_spec.rb +10 -0
  16. data/spec/mailers/mailer_spec.rb +42 -0
  17. data/spec/spec_helper.rb +10 -0
  18. data/spec/views_for_specs/a/_partial_render_parent.html.erb +1 -0
  19. data/spec/views_for_specs/a/in_a.html.erb +1 -0
  20. data/spec/views_for_specs/a/in_ab.html.erb +1 -0
  21. data/spec/views_for_specs/a/in_abc.html.erb +1 -0
  22. data/spec/views_for_specs/a/render_non_existent_partial.html.erb +1 -0
  23. data/spec/views_for_specs/a/render_parent.html.erb +1 -0
  24. data/spec/views_for_specs/b/_partial_in_b.html.erb +1 -0
  25. data/spec/views_for_specs/b/_partial_in_bc.html.erb +1 -0
  26. data/spec/views_for_specs/b/_partial_render_parent.html.erb +1 -0
  27. data/spec/views_for_specs/b/bad_render_parent.html.erb +1 -0
  28. data/spec/views_for_specs/b/collection_in_bc.html.erb +1 -0
  29. data/spec/views_for_specs/b/in_ab.html.erb +1 -0
  30. data/spec/views_for_specs/b/in_abc.html.erb +1 -0
  31. data/spec/views_for_specs/b/in_b.html.erb +1 -0
  32. data/spec/views_for_specs/b/partial_in_b.html.erb +1 -0
  33. data/spec/views_for_specs/b/partial_in_bc.html.erb +1 -0
  34. data/spec/views_for_specs/b/partial_render_parent.html.erb +1 -0
  35. data/spec/views_for_specs/b/render_parent.html.erb +1 -0
  36. data/spec/views_for_specs/c/_partial_in_bc.html.erb +1 -0
  37. data/spec/views_for_specs/c/_partial_render_parent.html.erb +1 -0
  38. data/spec/views_for_specs/c/in_abc.html.erb +1 -0
  39. data/spec/views_for_specs/c/in_c.html.erb +1 -0
  40. data/spec/views_for_specs/c/render_parent.html.erb +1 -0
  41. data/spec/views_for_specs/inheriting_mailer/email.erb +2 -0
  42. data/spec/views_for_specs/normal/partial_from_c.html.erb +1 -0
  43. data/spec/views_for_specs/normal_mailer/_partial.erb +1 -0
  44. data/spec/views_for_specs/normal_mailer/email.erb +2 -0
  45. metadata +97 -0
data/History.txt ADDED
@@ -0,0 +1,27 @@
1
+ * Added gemspec for GitHub auto-creation
2
+
3
+ * Added ActionMailer support
4
+
5
+ * Added support for rails 2.3
6
+
7
+ * Removed render_parent for now (in edge rails version)
8
+
9
+ * inherit_views allows inherited templates to be rendered where there is no action method
10
+
11
+ * Vastly simplified internals, making use of the _pick_template single point of entry
12
+
13
+ * branched fro rails 2.0 and 2.1 in rails-2.0-2.1, edge rails follows master branch
14
+
15
+ * Now using garlic for CI
16
+
17
+ * Compatibility update for the new ActionView::Partial refactoring.
18
+ [thanks Chris Hapgood for reporting, and tracking down, the bug]
19
+
20
+ * Compatible with both Rails 2.0.x and beyond - uses the template.finder object
21
+ to find templates if that is available
22
+
23
+ * Vastly improved readability of specs, and made them much more acceptance like
24
+
25
+ * BC Alert! inherit_views has changed to keep up with edge rails internals.
26
+ If you're using latest Edge, no problems. If you're using < 7413 then freeze
27
+ to r390 of inherit_views
data/License.txt ADDED
@@ -0,0 +1,20 @@
1
+ Copyright (c) 2008-2009 Ian White - ian.w.white@gmail.com
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining
4
+ a copy of this software and associated documentation files (the
5
+ "Software"), to deal in the Software without restriction, including
6
+ without limitation the rights to use, copy, modify, merge, publish,
7
+ distribute, sublicense, and/or sell copies of the Software, and to
8
+ permit persons to whom the Software is furnished to do so, subject to
9
+ the following conditions:
10
+
11
+ The above copyright notice and this permission notice shall be
12
+ included in all copies or substantial portions of the Software.
13
+
14
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
18
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
19
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.rdoc ADDED
@@ -0,0 +1,65 @@
1
+ = {ianwhite}[http://github.com/ianwhite] / {inherit_views}[http://github.com/ianwhite/inherit_views] >>{info}[http://ianwhite.github.com/inherit_views] >>{api}[http://ianwhite.github.com/inherit_views/doc]
2
+
3
+ == Status
4
+
5
+ inherit_views works with rails 2.x
6
+
7
+ If you're on <b>rails 2.3 or rails edge</b>, you want {inherit_views/master}[http://github.com/ianwhite/inherit_views/tree/master]
8
+
9
+ If you're on <b>rails 2.2</b>, you want {inherit_views/rails-2.2}[http://github.com/ianwhite/inherit_views/tree/rails-2.2]
10
+
11
+ If you're on <b>rails 2.0, or 2.1</b>, you want {inherit_views/rails-2.0-2.1}[http://github.com/ianwhite/inherit_views/tree/rails-2.0-2.1]
12
+
13
+ == what does it do?
14
+
15
+ This rails plugin allows your controllers/mailers to inherit their views from parent controllers/mailers.
16
+ The default behaviour is to inherit along the ancestor path of the controller/mailer, but you can also specify custom inherit view paths to search.
17
+
18
+ Example:
19
+
20
+ class ApplicationController < ActionController::Base
21
+ inherit_views
22
+ end
23
+
24
+ class FooController < ApplicationController
25
+ # will look for views in 'views/foo', then 'views/application'
26
+ end
27
+
28
+ class BarController < FooController
29
+ # will look for views in 'views/bar', then 'views/foo', then 'view/application'
30
+ end
31
+
32
+ See InheritViews for more details
33
+
34
+ NOTE: this plugin is not aimed at having multiple view paths for your controllers, which is addressed with the view_paths addition to ActionController::Base for rails 2.0. Rather, within these view paths, you can inherit views from other controller paths.
35
+
36
+ == In templates
37
+
38
+ You can render the 'parent' template from within a template if you so choose. This works for partials and top-level templates alike.
39
+
40
+ <b>foo/view.html.erb</b>
41
+ <h1>Foo View</h1>
42
+
43
+ <b>bar/view.html.erb</b>
44
+ <%= render :parent %>
45
+ <h2>With some 'bar' action</h2>
46
+
47
+ rendering bar/view (with the controller setup described above):
48
+ <h1>Foo View</h1>
49
+ <h2>With some 'bar' action</h2>
50
+
51
+ == Testing & CI
52
+
53
+ RSpec is used for testing, so the tests are in <tt>spec/</tt> rather than
54
+ <tt>test/</tt> Do rake --tasks for more details.
55
+
56
+ {garlic}[http://github.com/ianwhite/garlic] is used for CI, see garlic.rb for details on
57
+ what versions of rails are tested.
58
+
59
+ == Contributors
60
+
61
+ Author: {Ian W. White}[http://github.com/ianwhite]
62
+
63
+ Contributions by:
64
+
65
+ * {The Dark One}[http://github.com/thedarkone]
data/Rakefile ADDED
@@ -0,0 +1,64 @@
1
+ # use pluginized rpsec if it exists
2
+ rspec_base = File.expand_path(File.dirname(__FILE__) + '/../rspec/lib')
3
+ $LOAD_PATH.unshift(rspec_base) if File.exist?(rspec_base) and !$LOAD_PATH.include?(rspec_base)
4
+
5
+ require 'spec/rake/spectask'
6
+ require 'spec/rake/verify_rcov'
7
+
8
+ PluginName = 'inherit_views'
9
+
10
+ task :default => :spec
11
+
12
+ desc "Run the specs for #{PluginName}"
13
+ Spec::Rake::SpecTask.new(:spec) do |t|
14
+ t.spec_files = FileList['spec/**/*_spec.rb']
15
+ t.spec_opts = ["--colour"]
16
+ end
17
+
18
+ desc "Generate RCov report for #{PluginName}"
19
+ Spec::Rake::SpecTask.new(:rcov) do |t|
20
+ t.spec_files = FileList['spec/**/*_spec.rb']
21
+ t.rcov = true
22
+ t.rcov_dir = 'doc/coverage'
23
+ t.rcov_opts = ['--text-report', '--exclude', "spec/,rcov.rb,#{File.expand_path(File.join(File.dirname(__FILE__),'../../..'))}"]
24
+ end
25
+
26
+ namespace :rcov do
27
+ desc "Verify RCov threshold for #{PluginName}"
28
+ RCov::VerifyTask.new(:verify => :rcov) do |t|
29
+ t.threshold = 100.0
30
+ t.index_html = File.join(File.dirname(__FILE__), 'doc/coverage/index.html')
31
+ end
32
+ end
33
+
34
+ # the following optional tasks are for CI and doc building
35
+ begin
36
+ require 'hanna/rdoctask'
37
+ require 'garlic/tasks'
38
+ require 'grancher/task'
39
+
40
+ task :cruise => ['garlic:all', 'doc:publish']
41
+
42
+ Rake::RDocTask.new(:doc) do |d|
43
+ d.options << '--all'
44
+ d.rdoc_dir = 'doc'
45
+ d.main = 'README.rdoc'
46
+ d.title = "#{PluginName} API docs"
47
+ d.rdoc_files.include('README.rdoc', 'History.txt', 'License.txt', 'Todo.txt', 'lib/**/*.rb')
48
+ end
49
+
50
+ namespace :doc do
51
+ task :publish => :doc do
52
+ Rake::Task['doc:push'].invoke unless uptodate?('.git/refs/heads/gh-pages', 'doc')
53
+ end
54
+
55
+ Grancher::Task.new(:push) do |g|
56
+ g.keep_all
57
+ g.directory 'doc', 'doc'
58
+ g.branch = 'gh-pages'
59
+ g.push_to = 'origin'
60
+ end
61
+ end
62
+
63
+ rescue LoadError
64
+ end
data/Todo.txt ADDED
File without changes
data/garlic.rb ADDED
@@ -0,0 +1,33 @@
1
+ garlic do
2
+ repo 'inherit_views', :path => '.'
3
+
4
+ repo 'rails', :url => 'git://github.com/rails/rails'
5
+ repo 'rspec', :url => 'git://github.com/dchelimsky/rspec'
6
+ repo 'rspec-rails', :url => 'git://github.com/dchelimsky/rspec-rails'
7
+
8
+ # Make sure you set up tracking branches for origin/rails-2.2, and origin/rails-2.0-2.1
9
+ [
10
+ {:rails => 'master', :inherit_views => 'master'},
11
+ {:rails => '2-3-stable', :inherit_views => 'master'},
12
+ {:rails => '2-2-stable', :inherit_views => 'rails-2.2'},
13
+ {:rails => '2-1-stable', :inherit_views => 'rails-2.0-2.1'},
14
+ {:rails => '2-0-stable', :inherit_views => 'rails-2.0-2.1'}
15
+ ].each do |target|
16
+
17
+ target target[:rails], :branch => "origin/#{target[:rails]}" do
18
+ prepare do
19
+ plugin 'inherit_views', :branch => "origin/#{target[:inherit_views]}", :clone => true
20
+ plugin 'rspec', :branch => 'origin/1.1-maintenance'
21
+ plugin 'rspec-rails', :branch => 'origin/1.1-maintenance' do
22
+ sh "script/generate rspec -f"
23
+ end
24
+ end
25
+ run do
26
+ cd "vendor/plugins/inherit_views" do
27
+ sh "rake rcov:verify"
28
+ end
29
+ end
30
+ end
31
+
32
+ end
33
+ end
@@ -0,0 +1,17 @@
1
+ Gem::Specification.new do |s|
2
+ s.name = %q{inherit_views}
3
+ s.version = '1.0.1'
4
+
5
+ s.date = %q{2009-06-18}
6
+ s.summary = %q{Allow rails views to inherit from each other.}
7
+ s.description = %q{Allow rails views to inherit from each other.}
8
+ s.authors = ["Ian W. White", "thedarkone"]
9
+ s.email = "ian.w.white@gmail.com"
10
+ s.homepage = "http://github.com/topherfangio/inherit_views/tree/master"
11
+
12
+ s.has_rdoc = true
13
+ s.require_paths = ["lib"]
14
+
15
+ s.files = ["garlic.rb", "History.txt", "inherit_views.gemspec", "init.rb", "License.txt", "Rakefile", "README.rdoc", "Todo.txt", "lib/inherit_views.rb", "spec/controllers/a_controller_spec.rb", "spec/controllers/c_controller_spec.rb", "spec/controllers/b_controller_spec.rb", "spec/controllers/normal_controller_spec.rb", "spec/controllers/d_controller_spec.rb", "spec/spec_helper.rb", "spec/app.rb", "spec/mailers/mailer_spec.rb", "spec/views_for_specs/b/partial_in_b.html.erb", "spec/views_for_specs/b/bad_render_parent.html.erb", "spec/views_for_specs/b/partial_in_bc.html.erb", "spec/views_for_specs/b/in_abc.html.erb", "spec/views_for_specs/b/partial_render_parent.html.erb", "spec/views_for_specs/b/_partial_in_b.html.erb", "spec/views_for_specs/b/_partial_in_bc.html.erb", "spec/views_for_specs/b/collection_in_bc.html.erb", "spec/views_for_specs/b/in_b.html.erb", "spec/views_for_specs/b/in_ab.html.erb", "spec/views_for_specs/b/_partial_render_parent.html.erb", "spec/views_for_specs/b/render_parent.html.erb", "spec/views_for_specs/normal_mailer/email.erb", "spec/views_for_specs/normal_mailer/_partial.erb", "spec/views_for_specs/a/render_non_existent_partial.html.erb", "spec/views_for_specs/a/in_a.html.erb", "spec/views_for_specs/a/in_abc.html.erb", "spec/views_for_specs/a/in_ab.html.erb", "spec/views_for_specs/a/_partial_render_parent.html.erb", "spec/views_for_specs/a/render_parent.html.erb", "spec/views_for_specs/normal/partial_from_c.html.erb", "spec/views_for_specs/c/in_abc.html.erb", "spec/views_for_specs/c/_partial_in_bc.html.erb", "spec/views_for_specs/c/_partial_render_parent.html.erb", "spec/views_for_specs/c/in_c.html.erb", "spec/views_for_specs/c/render_parent.html.erb", "spec/views_for_specs/inheriting_mailer/email.erb"]
16
+
17
+ end
data/init.rb ADDED
@@ -0,0 +1,5 @@
1
+ require 'inherit_views'
2
+
3
+ defined?(ActionController) && ActionController::Base.extend(InheritViews::ActMethod)
4
+ defined?(ActionMailer) && ActionMailer::Base.extend(InheritViews::ActMethod)
5
+ defined?(ActionView) && ActionView::Base.send(:include, InheritViews::ActionView)
@@ -0,0 +1,166 @@
1
+ # Allow your controllers to inherit their views from parent controllers, or from
2
+ # specified view paths.
3
+ #
4
+ # === Example
5
+ #
6
+ # class FooController < ApplicationController
7
+ # inherit_views
8
+ # end
9
+ #
10
+ # class BarController < FooController
11
+ # ... # will look for views in 'views/bar' and 'views/foo'
12
+ # end
13
+ #
14
+ # In the example above, If BarController, or any of the views in views/bar, renders 'bar/view'
15
+ # and it is not found then 'foo/view' is rendered (if it can be found)
16
+ #
17
+ # You can also specify an inherit path other than the default (it does not have to be the default controller path)
18
+ # If your controller inherits from a controller with inherit_views then that controller
19
+ # gets the inherited view paths as well.
20
+ #
21
+ # class FooController < ApplicationController
22
+ # inherit_views 'far', 'faz' # will look for views in 'foo', then 'far', then 'faz'
23
+ # end
24
+ #
25
+ # class BarController < FooController
26
+ # # will look for views in 'bar', 'foo', 'far', 'faz'
27
+ # end
28
+ #
29
+ # If you want to turn off inherited views for a controller that has inherit_views in its
30
+ # ancestors use self.inherit_views=
31
+ #
32
+ # class BarController < FooController
33
+ # self.inherit_views = false
34
+ # end
35
+ #
36
+ # You can completely override the inherited view paths in a subclass controller using
37
+ # inherit_view_paths=
38
+ #
39
+ # class BarController < FooController
40
+ # self.inherit_view_paths = ['you_can_go', 'your_own_way']
41
+ # # will look for views in 'bar', 'you_can_go', and 'your_own_way'
42
+ # # (not 'far' or 'faz' from FooController)
43
+ # end
44
+ module InheritViews
45
+ # class extension which enables specification of inherit_views
46
+ module ActMethod
47
+ # Specify this to have your controller or mailer inherit its views from the specified path
48
+ # or the current controller/mailer's default path if no argument is given
49
+ def inherit_views(*paths)
50
+ class_eval do
51
+ extend PathsContainer unless respond_to?(:inherit_views_paths)
52
+ self.inherit_views = true
53
+ self.inherit_view_paths = paths if paths.any?
54
+ end
55
+ end
56
+ end
57
+
58
+ # class extension that enables inherit_view_paths to be calculated/set
59
+ #
60
+ # requires a class method called 'controller_path' (ActionController::Base & ActionMailer::Base have this)
61
+ module PathsContainer
62
+ def self.extended(base)
63
+ base.class_eval do
64
+ delegate :inherit_views?, :inherit_view_paths, :to => 'self.class'
65
+ end
66
+ end
67
+
68
+ # Return true if the class is inheriting views
69
+ def inherit_views?
70
+ read_inheritable_attribute('inherit_views') ? true : false
71
+ end
72
+
73
+ # Instruct the class that it is, or is not, inheriting views
74
+ def inherit_views=(bool)
75
+ write_inheritable_attribute('inherit_views', bool)
76
+ end
77
+
78
+ # Return the inherit view paths, in order of self to ancestor.
79
+ # Takes inherit_view_paths from the superclass when first read, and prepends the current controller_path
80
+ def inherit_view_paths
81
+ instance_variable_get('@inherit_view_paths') || instance_variable_set('@inherit_view_paths', [controller_path] + (superclass.inherit_view_paths rescue []))
82
+ end
83
+
84
+ # Set the inherit view paths, in order of self to ancestor.
85
+ # The controller_path for self is always prepended to the front, no matter what the arguments.
86
+ def inherit_view_paths=(new_paths)
87
+ new_paths -= [controller_path]
88
+ old_paths = inherit_view_paths - [controller_path] - new_paths
89
+ instance_variable_set('@inherit_view_paths', [controller_path] + new_paths + old_paths)
90
+ end
91
+ end
92
+
93
+ # just like a normal path set, but can have an optional array of inherit_view_paths
94
+ # which will be used to look for a matching template if the original template is missing
95
+ class PathSet < ::ActionView::PathSet
96
+ attr_accessor :inherit_view_paths
97
+
98
+ alias_method :orig_find_template, :find_template
99
+
100
+ # look for a parent template if a standard one can't be found
101
+ def find_template(template_path, format = nil, html_fallback = true)
102
+ super
103
+ rescue ::ActionView::MissingTemplate
104
+ find_parent_template(template_path, format)
105
+ end
106
+
107
+ # given a template_path and format, returns a parent template, or raise ActionView::MissingTemplate
108
+ def find_parent_template(template_path, format = nil, html_fallback = true)
109
+ # first, we grab the inherit view paths that are 'above' the given template_path
110
+ if inherit_view_paths.present? && (starting_path = inherit_view_paths.detect {|path| template_path.starts_with?("#{path}/")})
111
+ parent_paths = inherit_view_paths.slice(inherit_view_paths.index(starting_path)+1..-1)
112
+ # then, search through each path, substituting the inherit view path, returning the first found
113
+ parent_paths.each do |path|
114
+ begin
115
+ return orig_find_template(template_path.sub(/^#{starting_path}/, path), format, html_fallback)
116
+ rescue ::ActionView::MissingTemplate
117
+ next
118
+ end
119
+ end
120
+ end
121
+ raise ::ActionView::MissingTemplate.new(self, template_path, format)
122
+ end
123
+ end
124
+
125
+ # Mixin for ActionView::Base to enable inherit views functionality. There are two
126
+ # enhancements
127
+ #
128
+ # * view_paths are set to an InheritViews::PathSet object, and any inherit_view_paths
129
+ # are passed from the view's controller to the view_paths
130
+ #
131
+ # * render is extended to include support for render :parent, see render_with_parent
132
+ module ActionView
133
+ def self.included(base)
134
+ base.class_eval do
135
+ def self.process_view_paths(value)
136
+ InheritViews::PathSet.new(Array(value))
137
+ end
138
+
139
+ alias_method_chain :view_paths=, :inherit_views
140
+ alias_method_chain :render, :parent
141
+ end
142
+ end
143
+
144
+ # set the view_paths, and afterwards pass it my controller's inherit_view_paths
145
+ def view_paths_with_inherit_views=(value)
146
+ returning self.view_paths_without_inherit_views=(value) do
147
+ @view_paths.inherit_view_paths = controller.inherit_view_paths if (controller.inherit_views? rescue false)
148
+ end
149
+ end
150
+
151
+ # Extension for render which enables the following (in partials as well as top-level tenplates)
152
+ #
153
+ # <%= render :parent %>
154
+ # <%= render :parent, :locals => {:foo => @foo} %>
155
+ #
156
+ # These calls will render the template that is 'above' the current template according to the#
157
+ # current controller's inherit_view_paths.
158
+ def render_with_parent(*args, &block)
159
+ if args.first == :parent
160
+ args.shift
161
+ args.first[:file] = view_paths.find_parent_template(template.to_s, template.format)
162
+ end
163
+ render_without_parent(*args, &block)
164
+ end
165
+ end
166
+ end
data/spec/app.rb ADDED
@@ -0,0 +1,47 @@
1
+ class InheritViewsTestController < ActionController::Base
2
+ self.view_paths = [File.join(File.dirname(__FILE__), 'views_for_specs')]
3
+ end
4
+
5
+ # :a controller is a normal controller with inherit_views
6
+ # its subclasses will inherit its views
7
+ class AController < InheritViewsTestController
8
+ inherit_views
9
+
10
+ def render_non_existent_template
11
+ render :action => 'non_existent'
12
+ end
13
+ end
14
+
15
+ # :b controller is a normal controller with inherit_views 'a'
16
+ # It will inherit a's views, and its sublcasses will inherit its views ('b', then 'a')
17
+ class BController < InheritViewsTestController
18
+ inherit_views 'a'
19
+ end
20
+
21
+ # :c cotroller is a subclass of :b controller, so it inheirt's b's views ('c', 'b', then 'a')
22
+ class CController < BController
23
+ end
24
+
25
+ # :d controller is a subclass of :a controller, with inherit_views 'other', so its views == ('d', 'other', then 'a')
26
+ class DController < AController
27
+ inherit_views 'other'
28
+ end
29
+
30
+ # used to test normal rails behaviour
31
+ class NormalController < InheritViewsTestController
32
+ end
33
+
34
+ # used to test ActionMailer's use of views is not affected
35
+ class NormalMailer < ActionMailer::Base
36
+ self.template_root = File.join(File.dirname(__FILE__), 'views_for_specs')
37
+
38
+ def email
39
+ recipients 'test@test.com'
40
+ subject 'An email'
41
+ end
42
+ end
43
+
44
+ # inherits views form normal mailer
45
+ class InheritingMailer < NormalMailer
46
+ inherit_views 'normal_mailer'
47
+ end
@@ -0,0 +1,44 @@
1
+ require File.expand_path(File.join(File.dirname(__FILE__), '../spec_helper'))
2
+
3
+ describe AController, " < TestController; inherit_views" do
4
+ describe "(the class)" do
5
+ it { AController.should be_inherit_views }
6
+
7
+ it "should have inherit view paths == ['a']" do
8
+ AController.inherit_view_paths.should == ['a']
9
+ end
10
+ end
11
+
12
+ describe "(an instance)" do
13
+ integrate_views
14
+
15
+ it { @controller.should be_inherit_views }
16
+
17
+ it "should have inherit view paths == ['a']" do
18
+ @controller.class.inherit_view_paths.should == ['a']
19
+ end
20
+
21
+ it "GET :in_abc should render a/in_abc" do
22
+ get :in_abc
23
+ response.body.should == 'a:in_abc'
24
+ end
25
+
26
+ it "GET :in_a should render a/in_a" do
27
+ get :in_a
28
+ response.body.should == 'a:in_a'
29
+ end
30
+
31
+ it "GET :in_ab should render a/in_ab" do
32
+ get :in_ab
33
+ response.body.should == 'a:in_ab'
34
+ end
35
+
36
+ it "GET :render_non_existent_partial should raise ActionView::TemplateError" do
37
+ lambda { get :render_non_existent_partial }.should raise_error(ActionView::TemplateError)
38
+ end
39
+
40
+ it "GET :render_non_existent_template should raise ActionView::MissingTemplate" do
41
+ lambda { get :render_non_existent_template }.should raise_error(ActionView::MissingTemplate)
42
+ end
43
+ end
44
+ end
@@ -0,0 +1,70 @@
1
+ require File.expand_path(File.join(File.dirname(__FILE__), '../spec_helper'))
2
+
3
+ describe BController, " < TestController; inherit_views 'a'" do
4
+ describe "(the class)" do
5
+ it { BController.should be_inherit_views }
6
+
7
+ it "should have inherit view paths == ['b', 'a']" do
8
+ BController.inherit_view_paths.should == ['b', 'a']
9
+ end
10
+ end
11
+
12
+ describe "(an instance)" do
13
+ integrate_views
14
+
15
+ it { @controller.should be_inherit_views }
16
+
17
+ it "should have inherit view paths == ['b', 'a']" do
18
+ @controller.inherit_view_paths.should == ['b', 'a']
19
+ end
20
+
21
+ it "GET :in_first should render a/in_a" do
22
+ get :in_a
23
+ response.body.should == 'a:in_a'
24
+ end
25
+
26
+ it "GET :in_ab should render b/in_ab" do
27
+ get :in_ab
28
+ response.body.should == 'b:in_ab'
29
+ end
30
+
31
+ it "GET :in_b should render b/in_b" do
32
+ get :in_b
33
+ response.body.should == 'b:in_b'
34
+ end
35
+
36
+ it "GET :in_abc should render b/in_abc" do
37
+ get :in_abc
38
+ response.body.should == 'b:in_abc'
39
+ end
40
+
41
+ it "GET :partial_in_bc should render b/partial_in_bc & b/_partial_in_bc" do
42
+ get :partial_in_bc
43
+ response.body.should == "b:partial_in_bc => b:_partial_in_bc"
44
+ end
45
+
46
+ it "GET :partial_in_b should render b/partial_in_b & b/_partial_in_b" do
47
+ get :partial_in_b
48
+ response.body.should == "b:partial_in_b => b:_partial_in_b"
49
+ end
50
+
51
+ it "GET :collection_in_bc should render b/collection_in_bc then b/_partial_in_bc" do
52
+ get :collection_in_bc
53
+ response.body.should == 'b:collection_in_bc => b:_partial_in_bc'
54
+ end
55
+
56
+ it "GET :render_parent should render a/render_parent inside b/render_parent" do
57
+ get :render_parent
58
+ response.body.should == "b:render_parent(a:render_parent)"
59
+ end
60
+
61
+ it "GET :partial_render_parent should render a/_partial_render_parent inside b/_partial_render_parent" do
62
+ get :partial_render_parent
63
+ response.body.should == "b:partial_render_parent => b:_partial_render_parent(a:_parent_render_parent)"
64
+ end
65
+
66
+ it "GET :bad_render_parent should rasie TemplateError" do
67
+ lambda { get :bad_render_parent }.should raise_error(ActionView::TemplateError)
68
+ end
69
+ end
70
+ end
@@ -0,0 +1,71 @@
1
+ require File.expand_path(File.join(File.dirname(__FILE__), '../spec_helper'))
2
+
3
+ describe CController, " < BController" do
4
+ describe "(the class)" do
5
+ it { CController.should be_inherit_views }
6
+
7
+ it "should have inherit view paths == ['c', 'b', 'a']" do
8
+ CController.inherit_view_paths.should == ['c', 'b', 'a']
9
+ end
10
+ end
11
+
12
+ describe "(an instance)" do
13
+ integrate_views
14
+
15
+ it { @controller.should be_inherit_views }
16
+
17
+ it "should have inherit view paths == ['c', 'b', 'a']" do
18
+ @controller.inherit_view_paths.should == ['c', 'b', 'a']
19
+ end
20
+
21
+ it "GET :in_a should render a/in_a" do
22
+ get :in_a
23
+ response.body.should == 'a:in_a'
24
+ end
25
+
26
+ it "GET :in_ab should render b/in_ab" do
27
+ get :in_ab
28
+ response.body.should == 'b:in_ab'
29
+ end
30
+
31
+ it "GET :in_b should render b/in_b" do
32
+ get :in_b
33
+ response.body.should == 'b:in_b'
34
+ end
35
+
36
+ it "GET :in_abc should render c/in_abc" do
37
+ get :in_abc
38
+ response.body.should == 'c:in_abc'
39
+ end
40
+
41
+ it "GET :in_c should render c/in_c" do
42
+ get :in_c
43
+ response.body.should == 'c:in_c'
44
+ end
45
+
46
+ it "GET :partial_in_bc should render b/partial_in_bc then c/_partial_in_bc" do
47
+ get :partial_in_bc
48
+ response.body.should == "b:partial_in_bc => c:_partial_in_bc"
49
+ end
50
+
51
+ it "GET :partial_in_b should render b/partial_in_b & b/_partial_in_b" do
52
+ get :partial_in_b
53
+ response.body.should == "b:partial_in_b => b:_partial_in_b"
54
+ end
55
+
56
+ it "GET :collection_in_bc should render b/collection_in_bc then c/_partial_in_bc" do
57
+ get :collection_in_bc
58
+ response.body.should == 'b:collection_in_bc => c:_partial_in_bc'
59
+ end
60
+
61
+ it "GET :render_parent should render a/render_parent inside b/render_parent inside c/render_parent" do
62
+ get :render_parent
63
+ response.body.should == "c:render_parent(b:render_parent(a:render_parent))"
64
+ end
65
+
66
+ it "GET :partial_render_parent should render b:partial_render_parent with a,b, and c partials " do
67
+ get :partial_render_parent
68
+ response.body.should == "b:partial_render_parent => c:_partial_render_parent(b:_partial_render_parent(a:_parent_render_parent))"
69
+ end
70
+ end
71
+ end
@@ -0,0 +1,21 @@
1
+ require File.expand_path(File.join(File.dirname(__FILE__), '../spec_helper'))
2
+
3
+ describe DController, " < AController; inherit_views 'other'" do
4
+ describe "(the class)" do
5
+ it { DController.should be_inherit_views }
6
+
7
+ it "should have inherit view paths == ['d', 'other', 'a']" do
8
+ DController.inherit_view_paths.should == ['d', 'other', 'a']
9
+ end
10
+ end
11
+
12
+ describe "(an instance)" do
13
+ integrate_views
14
+
15
+ it { @controller.should be_inherit_views }
16
+
17
+ it "should have inherit view paths == ['d', 'other', 'a']" do
18
+ @controller.class.inherit_view_paths.should == ['d', 'other', 'a']
19
+ end
20
+ end
21
+ end
@@ -0,0 +1,10 @@
1
+ require File.expand_path(File.join(File.dirname(__FILE__), '../spec_helper'))
2
+
3
+ describe NormalController do
4
+ integrate_views
5
+
6
+ it "GET :partial_from_c should render normal/partial_from_c, then c/_partial_in_bc" do
7
+ get :partial_from_c
8
+ response.body.should == 'normal:partial_from_c => c:_partial_in_bc'
9
+ end
10
+ end
@@ -0,0 +1,42 @@
1
+ require File.expand_path(File.join(File.dirname(__FILE__), '../spec_helper'))
2
+
3
+ describe 'Mailer specs' do
4
+ before :all do
5
+ ActionMailer::Base.delivery_method = :test
6
+ ActionMailer::Base.perform_deliveries = true
7
+ end
8
+
9
+ before :each do
10
+ ActionMailer::Base.deliveries.clear
11
+ end
12
+
13
+ describe NormalMailer do
14
+ before :each do
15
+ NormalMailer.deliver_email
16
+ @deliveries = ActionMailer::Base.deliveries
17
+ end
18
+
19
+ it "should deliver email" do
20
+ @deliveries.size.should == 1
21
+ end
22
+
23
+ it "should render email with partial" do
24
+ @deliveries.first.body.should == "normal_mailer:email\nnormal_mailer:_partial"
25
+ end
26
+ end
27
+
28
+ describe InheritingMailer do
29
+ before :each do
30
+ InheritingMailer.deliver_email
31
+ @deliveries = ActionMailer::Base.deliveries
32
+ end
33
+
34
+ it "should deliver email" do
35
+ @deliveries.size.should == 1
36
+ end
37
+
38
+ it "should render email with inherited partial" do
39
+ @deliveries.first.body.should == "inheriting_mailer:email\nnormal_mailer:_partial"
40
+ end
41
+ end
42
+ end
@@ -0,0 +1,10 @@
1
+ # This file is copied to ~/spec when you run 'ruby script/generate rspec'
2
+ # from the project root directory.
3
+ ENV["RAILS_ENV"] ||= "test"
4
+ require File.expand_path(File.join(File.dirname(__FILE__), "../../../../config/environment"))
5
+ require 'spec/rails'
6
+
7
+ Spec::Runner.configure do |config|
8
+ end
9
+
10
+ require File.expand_path(File.join(File.dirname(__FILE__), 'app'))
@@ -0,0 +1 @@
1
+ a:_parent_render_parent
@@ -0,0 +1 @@
1
+ a:in_a
@@ -0,0 +1 @@
1
+ a:in_ab
@@ -0,0 +1 @@
1
+ a:in_abc
@@ -0,0 +1 @@
1
+ <%= render :partial => 'non_existent' %>
@@ -0,0 +1 @@
1
+ a:render_parent
@@ -0,0 +1 @@
1
+ b:_partial_in_b
@@ -0,0 +1 @@
1
+ b:_partial_in_bc
@@ -0,0 +1 @@
1
+ b:_partial_render_parent(<%= render :parent %>)
@@ -0,0 +1 @@
1
+ <%= render :parent %>
@@ -0,0 +1 @@
1
+ b:collection_in_bc => <%= render :partial => 'partial_in_bc', :collection => [1] %>
@@ -0,0 +1 @@
1
+ b:in_ab
@@ -0,0 +1 @@
1
+ b:in_abc
@@ -0,0 +1 @@
1
+ b:in_b
@@ -0,0 +1 @@
1
+ b:partial_in_b => <%= render :partial => 'partial_in_b' %>
@@ -0,0 +1 @@
1
+ b:partial_in_bc => <%= render :partial => 'partial_in_bc' %>
@@ -0,0 +1 @@
1
+ b:partial_render_parent => <%= render :partial => 'partial_render_parent' %>
@@ -0,0 +1 @@
1
+ b:render_parent(<%= render :parent %>)
@@ -0,0 +1 @@
1
+ c:_partial_in_bc
@@ -0,0 +1 @@
1
+ c:_partial_render_parent(<%= render :parent %>)
@@ -0,0 +1 @@
1
+ c:in_abc
@@ -0,0 +1 @@
1
+ c:in_c
@@ -0,0 +1 @@
1
+ c:render_parent(<%= render :parent %>)
@@ -0,0 +1,2 @@
1
+ inheriting_mailer:email
2
+ <%= render 'partial' %>
@@ -0,0 +1 @@
1
+ normal:partial_from_c => <%= render :partial => 'c/partial_in_bc' %>
@@ -0,0 +1 @@
1
+ normal_mailer:_partial
@@ -0,0 +1,2 @@
1
+ normal_mailer:email
2
+ <%= render 'partial' %>
metadata ADDED
@@ -0,0 +1,97 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: topherfangio-inherit_views
3
+ version: !ruby/object:Gem::Version
4
+ version: 1.0.1
5
+ platform: ruby
6
+ authors:
7
+ - Ian W. White
8
+ - thedarkone
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+
13
+ date: 2009-06-18 00:00:00 -07:00
14
+ default_executable:
15
+ dependencies: []
16
+
17
+ description: Allow rails views to inherit from each other.
18
+ email: ian.w.white@gmail.com
19
+ executables: []
20
+
21
+ extensions: []
22
+
23
+ extra_rdoc_files: []
24
+
25
+ files:
26
+ - garlic.rb
27
+ - History.txt
28
+ - inherit_views.gemspec
29
+ - init.rb
30
+ - License.txt
31
+ - Rakefile
32
+ - README.rdoc
33
+ - Todo.txt
34
+ - lib/inherit_views.rb
35
+ - spec/controllers/a_controller_spec.rb
36
+ - spec/controllers/c_controller_spec.rb
37
+ - spec/controllers/b_controller_spec.rb
38
+ - spec/controllers/normal_controller_spec.rb
39
+ - spec/controllers/d_controller_spec.rb
40
+ - spec/spec_helper.rb
41
+ - spec/app.rb
42
+ - spec/mailers/mailer_spec.rb
43
+ - spec/views_for_specs/b/partial_in_b.html.erb
44
+ - spec/views_for_specs/b/bad_render_parent.html.erb
45
+ - spec/views_for_specs/b/partial_in_bc.html.erb
46
+ - spec/views_for_specs/b/in_abc.html.erb
47
+ - spec/views_for_specs/b/partial_render_parent.html.erb
48
+ - spec/views_for_specs/b/_partial_in_b.html.erb
49
+ - spec/views_for_specs/b/_partial_in_bc.html.erb
50
+ - spec/views_for_specs/b/collection_in_bc.html.erb
51
+ - spec/views_for_specs/b/in_b.html.erb
52
+ - spec/views_for_specs/b/in_ab.html.erb
53
+ - spec/views_for_specs/b/_partial_render_parent.html.erb
54
+ - spec/views_for_specs/b/render_parent.html.erb
55
+ - spec/views_for_specs/normal_mailer/email.erb
56
+ - spec/views_for_specs/normal_mailer/_partial.erb
57
+ - spec/views_for_specs/a/render_non_existent_partial.html.erb
58
+ - spec/views_for_specs/a/in_a.html.erb
59
+ - spec/views_for_specs/a/in_abc.html.erb
60
+ - spec/views_for_specs/a/in_ab.html.erb
61
+ - spec/views_for_specs/a/_partial_render_parent.html.erb
62
+ - spec/views_for_specs/a/render_parent.html.erb
63
+ - spec/views_for_specs/normal/partial_from_c.html.erb
64
+ - spec/views_for_specs/c/in_abc.html.erb
65
+ - spec/views_for_specs/c/_partial_in_bc.html.erb
66
+ - spec/views_for_specs/c/_partial_render_parent.html.erb
67
+ - spec/views_for_specs/c/in_c.html.erb
68
+ - spec/views_for_specs/c/render_parent.html.erb
69
+ - spec/views_for_specs/inheriting_mailer/email.erb
70
+ has_rdoc: true
71
+ homepage: http://github.com/topherfangio/inherit_views/tree/master
72
+ post_install_message:
73
+ rdoc_options: []
74
+
75
+ require_paths:
76
+ - lib
77
+ required_ruby_version: !ruby/object:Gem::Requirement
78
+ requirements:
79
+ - - ">="
80
+ - !ruby/object:Gem::Version
81
+ version: "0"
82
+ version:
83
+ required_rubygems_version: !ruby/object:Gem::Requirement
84
+ requirements:
85
+ - - ">="
86
+ - !ruby/object:Gem::Version
87
+ version: "0"
88
+ version:
89
+ requirements: []
90
+
91
+ rubyforge_project:
92
+ rubygems_version: 1.2.0
93
+ signing_key:
94
+ specification_version: 2
95
+ summary: Allow rails views to inherit from each other.
96
+ test_files: []
97
+