render_inheritable 0.5.0 → 1.0.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -5,12 +5,15 @@ A Rails 3 plugin that allows one to inherit or override single templates for con
5
5
  In the default case, a template is searched in the current controller's view folder. If it is not found there, the template with the same name in the view folder of the superclass controller is used. Have a look at the examples for more clarification.
6
6
 
7
7
  Install the gem with
8
+
8
9
  gem install render_inheritable
9
10
 
10
11
  In your Rails application's +Gemfile+, add
12
+
11
13
  gem 'render_inheritable'
12
14
 
13
15
  To use inheritable templates in a certain controller hierarchy, add this declaration to the respective base controller:
16
+
14
17
  render_inheritable
15
18
 
16
19
  That's it, no more duplications in your views and partials.
@@ -69,6 +72,8 @@ Now, the <code>render :partial => 'entry'</code> call in <i>views/crud/_list.htm
69
72
 
70
73
  Of course, the lookup not only works for HTML templates and partials, but for any format. Even <code>page.replace 'element_id', :partial => 'element'</code> calls in RJS templates benefit from this gem.
71
74
 
75
+ Wait! What if I want to render a specific partial, without getting it overriden somewhere else? No problem, just specifiy the complete path:
76
+ <%= render :partial => 'parent/show' %>
72
77
 
73
78
  == Custom Lookup Paths
74
79
 
data/Rakefile CHANGED
@@ -2,9 +2,14 @@ require 'rubygems'
2
2
  require "rake/testtask"
3
3
  require 'rake/gempackagetask'
4
4
  require 'rake/rdoctask'
5
- sdoc = (require 'sdoc' || true) rescue false
5
+ sdoc = begin
6
+ require 'sdoc'
7
+ true
8
+ rescue Exception
9
+ false
10
+ end
6
11
 
7
- load 'render_inheritable.gemspec'
12
+ load 'render_inheritable.gemspec'
8
13
 
9
14
  TEST_APP_ROOT = File.join(File.dirname(__FILE__), 'test', 'test_app')
10
15
 
@@ -12,22 +17,22 @@ task :default => :test
12
17
 
13
18
  desc "Run all tests"
14
19
  task :test => ['test:app:init'] do
15
- Rake::TestTask.new do |test|
16
- test.libs << "#{TEST_APP_ROOT}/test"
17
- test.test_files = Dir[ "#{TEST_APP_ROOT}/test/**/*_test.rb" ]
18
- test.verbose = true
19
- end
20
+ Rake::TestTask.new do |test|
21
+ test.libs << "#{TEST_APP_ROOT}/test"
22
+ test.test_files = Dir[ "#{TEST_APP_ROOT}/test/**/*_test.rb" ]
23
+ test.verbose = true
24
+ end
20
25
  end
21
26
 
22
27
  namespace :test do
23
- namespace :app do
24
- desc "Create a rails test application"
25
- task :create do
26
- unless File.exist?(TEST_APP_ROOT)
27
- sh "rails _3.0.0.beta4_ new #{TEST_APP_ROOT}"
28
- end
29
- end
30
-
28
+ namespace :app do
29
+ desc "Create a rails test application"
30
+ task :create do
31
+ unless File.exist?(TEST_APP_ROOT)
32
+ sh "rails new #{TEST_APP_ROOT}"
33
+ end
34
+ end
35
+
31
36
  desc "Initializes the test application with a couple of classes"
32
37
  task :init => :create do
33
38
  FileUtils.cp_r(File.join(File.dirname(__FILE__), 'test', 'templates', '.'), TEST_APP_ROOT)
@@ -36,57 +41,61 @@ namespace :test do
36
41
  end
37
42
  end
38
43
 
39
- task :environment => :init do
40
- ::RAILS_ROOT = TEST_APP_ROOT
41
- ::RAILS_ENV = 'test'
42
-
43
- require(File.join(TEST_APP_ROOT, 'config', 'environment'))
44
- end
44
+ task :environment => :init do
45
+ ENV['RAILS_ROOT'] = TEST_APP_ROOT
46
+ ENV['RAILS_ENV'] = 'test'
47
+
48
+ require(File.join(TEST_APP_ROOT, 'config', 'environment'))
49
+ end
45
50
 
46
- end
51
+ end
47
52
  end
48
53
 
49
54
  desc "Clean up all generated resources"
50
55
  task :clobber do
51
- FileUtils.rm_rf(TEST_APP_ROOT)
56
+ FileUtils.rm_rf(TEST_APP_ROOT)
52
57
  end
53
58
 
54
59
  desc "Install render_inheritable as a local gem."
55
60
  task :install => [:package] do
56
- sudo = RUBY_PLATFORM =~ /win32/ ? '' : 'sudo'
57
- gem = RUBY_PLATFORM =~ /java/ ? 'jgem' : 'gem'
58
- sh %{#{sudo} #{gem} install --no-ri pkg/render_inheritable-#{File.read('VERSION').strip}}
61
+ sudo = RUBY_PLATFORM =~ /win32/ ? '' : 'sudo'
62
+ gem = RUBY_PLATFORM =~ /java/ ? 'jgem' : 'gem'
63
+ sh %{#{sudo} #{gem} install --no-ri pkg/render_inheritable-#{File.read('VERSION').strip}}
59
64
  end
60
65
 
61
66
  desc "Deploy rdoc to website"
62
67
  task :site => :rdoc do
63
- sh "rsync -rzv rdoc/ #{ENV['DEST']}"
68
+ if ENV['DEST']
69
+ sh "rsync -rzv rdoc/ #{ENV['DEST']}"
70
+ else
71
+ puts "Please specify a destination with DEST=user@server:/deploy/dir"
72
+ end
64
73
  end
65
74
 
66
75
  # :package task
67
76
  Rake::GemPackageTask.new(RENDER_INHERITABLE_GEMSPEC) do |pkg|
68
- if Rake.application.top_level_tasks.include?('release')
69
- pkg.need_tar_gz = true
70
- pkg.need_tar_bz2 = true
71
- pkg.need_zip = true
72
- end
77
+ if Rake.application.top_level_tasks.include?('release')
78
+ pkg.need_tar_gz = true
79
+ pkg.need_tar_bz2 = true
80
+ pkg.need_zip = true
81
+ end
73
82
  end
74
83
 
75
84
  # :rdoc task
76
85
  Rake::RDocTask.new do |rdoc|
77
- rdoc.title = 'Render Inheritable'
78
- rdoc.options << '--line-numbers' << '--inline-source'
86
+ rdoc.title = 'Render Inheritable'
87
+ rdoc.options << '--line-numbers' << '--inline-source'
79
88
  if sdoc
80
- rdoc.options << '--fmt' << 'shtml'
81
- rdoc.template = 'direct'
89
+ rdoc.options << '--fmt' << 'shtml'
90
+ rdoc.template = 'direct'
82
91
  end
83
- rdoc.rdoc_files.include(*FileList.new('*') do |list|
84
- list.exclude(/(^|[^.a-z])[a-z]+/)
85
- list.exclude('TODO')
86
- end.to_a)
87
- rdoc.rdoc_files.include('lib/**/*.rb')
88
- rdoc.rdoc_files.exclude('TODO')
89
-
90
- rdoc.rdoc_dir = 'rdoc'
91
- rdoc.main = 'README.rdoc'
92
+ rdoc.rdoc_files.include(*FileList.new('*') do |list|
93
+ list.exclude(/(^|[^.a-z])[a-z]+/)
94
+ list.exclude('TODO')
95
+ end.to_a)
96
+ rdoc.rdoc_files.include('lib/**/*.rb')
97
+ rdoc.rdoc_files.exclude('TODO')
98
+
99
+ rdoc.rdoc_dir = 'rdoc'
100
+ rdoc.main = 'README.rdoc'
92
101
  end
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.5.0
1
+ 1.0.0
@@ -46,8 +46,9 @@ module RenderInheritable
46
46
  # in a custom #template_lookup_path. In this case, no controller class would need to
47
47
  # exist to render templates from corresponding view folders.
48
48
  def inheritable_controller(param = nil)
49
+ descendants = inheritable_root_controller.descendants
49
50
  c = find_inheritable_artifact(param) do |folder|
50
- ActionController::Base.subclasses.any? { |c| c.constantize.controller_path == folder }
51
+ descendants.any? { |s| s.controller_path == folder }
51
52
  end
52
53
  c || inheritable_root_controller.controller_path
53
54
  end
@@ -1,6 +1,6 @@
1
1
  source 'http://rubygems.org'
2
2
 
3
- gem 'rails', '3.0.0.beta4'
3
+ gem 'rails', '~> 3.0'
4
4
 
5
5
  # Bundle edge Rails instead:
6
6
  # gem 'rails', :git => 'git://github.com/rails/rails.git'
@@ -1,4 +1,4 @@
1
- TestApp::Application.routes.draw do |map|
1
+ TestApp::Application.routes.draw do
2
2
  # The priority is based upon order of creation:
3
3
  # first created -> highest priority.
4
4
 
@@ -1,9 +1,8 @@
1
- require 'rails'
2
1
  require 'test_helper'
3
2
 
4
3
  TEST_VIEW_PATH = File.join(Rails.root, 'test', 'test_views')
5
4
 
6
- class RootController < ActionController::Base
5
+ class RootController < ApplicationController
7
6
  render_inheritable
8
7
 
9
8
  attr_accessor :default_template_format
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: render_inheritable
3
3
  version: !ruby/object:Gem::Version
4
- hash: 11
4
+ hash: 23
5
5
  prerelease: false
6
6
  segments:
7
+ - 1
7
8
  - 0
8
- - 5
9
9
  - 0
10
- version: 0.5.0
10
+ version: 1.0.0
11
11
  platform: ruby
12
12
  authors:
13
13
  - Pascal Zumkehr
@@ -15,7 +15,7 @@ autorequire:
15
15
  bindir: bin
16
16
  cert_chain: []
17
17
 
18
- date: 2010-06-23 00:00:00 +02:00
18
+ date: 2010-08-31 00:00:00 +02:00
19
19
  default_executable:
20
20
  dependencies:
21
21
  - !ruby/object:Gem::Dependency
@@ -24,15 +24,13 @@ dependencies:
24
24
  requirement: &id001 !ruby/object:Gem::Requirement
25
25
  none: false
26
26
  requirements:
27
- - - "="
27
+ - - ~>
28
28
  - !ruby/object:Gem::Version
29
- hash: -1848230024
29
+ hash: 7
30
30
  segments:
31
31
  - 3
32
32
  - 0
33
- - 0
34
- - beta4
35
- version: 3.0.0.beta4
33
+ version: "3.0"
36
34
  type: :runtime
37
35
  version_requirements: *id001
38
36
  description: |