render_parent 0.0.1 → 0.0.2

Sign up to get free protection for your applications and to get access to all the features.
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.0.1
1
+ 0.0.2
@@ -2,10 +2,9 @@ require 'action_view/base'
2
2
 
3
3
  ActionView::Base.class_eval do
4
4
  def render_parent_template(local_assigns = {}, &block)
5
- saved_view_paths = view_paths.dup
6
- view_paths.delete_if {|p| p.to_s == template.load_path.to_s}
5
+ view_paths.exclusions << template
7
6
  result = render({:file => template.to_s}, local_assigns, &block)
8
- view_paths.replace(saved_view_paths)
7
+ view_paths.exclusions.delete template
9
8
  result
10
9
  end
11
10
 
@@ -18,4 +17,46 @@ ActionView::Base.class_eval do
18
17
  end
19
18
 
20
19
  alias_method_chain :render, :parent
20
+ end
21
+
22
+ ActionView::PathSet.class_eval do
23
+ attr_writer :exclusions
24
+
25
+ def exclusions
26
+ @exclusions ||= []
27
+ end
28
+
29
+ def find_template(original_template_path, format = nil, html_fallback = true)
30
+ return original_template_path if original_template_path.respond_to?(:render)
31
+ template_path = original_template_path.sub(/^\//, '')
32
+
33
+ each do |load_path|
34
+ if format && (template = load_path["#{template_path}.#{I18n.locale}.#{format}"]) && !exclusions.include?(template)
35
+ return template
36
+ # Try the default locale version if the current locale doesn't have one
37
+ # (i.e. you haven't translated this view to German yet, but you have the English version on hand)
38
+ elsif format && (template = load_path["#{template_path}.#{I18n.default_locale}.#{format}"]) && !exclusions.include?(template)
39
+ return template
40
+ elsif format && (template = load_path["#{template_path}.#{format}"]) && !exclusions.include?(template)
41
+ return template
42
+ elsif (template = load_path["#{template_path}.#{I18n.locale}"]) && !exclusions.include?(template)
43
+ return template
44
+ elsif (template = load_path["#{template_path}.#{I18n.default_locale}"]) && !exclusions.include?(template)
45
+ return template
46
+ elsif (template = load_path[template_path]) && !exclusions.include?(template)
47
+ return template
48
+ # Try to find html version if the format is javascript
49
+ elsif format == :js && html_fallback && (template = load_path["#{template_path}.#{I18n.locale}.html"]) && !exclusions.include?(template)
50
+ return template
51
+ elsif format == :js && html_fallback && (template = load_path["#{template_path}.#{I18n.default_locale}.html"]) && !exclusions.include?(template)
52
+ return template
53
+ elsif format == :js && html_fallback && (template = load_path["#{template_path}.html"]) && !exclusions.include?(template)
54
+ return template
55
+ end
56
+ end
57
+
58
+ return ActionView::Template.new(original_template_path) if File.file?(original_template_path)
59
+
60
+ raise ActionView::MissingTemplate.new(self, original_template_path, format)
61
+ end
21
62
  end
@@ -6,6 +6,9 @@ module RenderParent
6
6
  ActiveSupport.on_load(:action_controller) do
7
7
  require 'render_parent/rails3/on_load_action_controller'
8
8
  end
9
+ ActiveSupport.on_load(:action_mailer) do
10
+ require 'render_parent/rails3/on_load_action_mailer'
11
+ end
9
12
  ActiveSupport.on_load(:action_view) do
10
13
  require 'render_parent/rails3/on_load_action_view'
11
14
  end
@@ -0,0 +1,11 @@
1
+ require 'action_mailer/base'
2
+
3
+ ActionMailer::Base.class_eval do
4
+ def active_template_stack
5
+ @active_template_stack ||= []
6
+ end
7
+
8
+ def active_template
9
+ @active_template_stack.last
10
+ end
11
+ end
@@ -4,10 +4,9 @@ require 'action_view/renderer/template_renderer'
4
4
  ActionView::Helpers::RenderingHelper.module_eval do
5
5
  def render_parent_template(locals = {}, &block)
6
6
  template = controller.active_template
7
- saved_view_paths = view_paths.paths.dup
8
- view_paths.paths.delete_if {|p| template.identifier.start_with? p.to_s}
7
+ view_paths.exclusions << template
9
8
  result = render({:file => template.virtual_path}, locals, &block)
10
- view_paths.paths.replace(saved_view_paths)
9
+ view_paths.exclusions.delete template
11
10
  result
12
11
  end
13
12
 
@@ -22,9 +21,31 @@ ActionView::Helpers::RenderingHelper.module_eval do
22
21
  alias_method_chain :render, :parent
23
22
  end
24
23
 
24
+ ActionView::PathSet.class_eval do
25
+ attr_writer :exclusions
26
+
27
+ def exclusions
28
+ @exclusions ||= []
29
+ end
30
+
31
+ def find_all_with_exclusions(path, prefixes = [], *args)
32
+ prefixes = [prefixes] if String === prefixes
33
+ prefixes.each do |prefix|
34
+ paths.each do |resolver|
35
+ templates = resolver.find_all(path, prefix, *args)
36
+ templates.delete_if {|t| exclusions.include? t}
37
+ return templates unless templates.empty?
38
+ end
39
+ end
40
+ []
41
+ end
42
+
43
+ alias_method_chain :find_all, :exclusions
44
+ end
45
+
25
46
  ActionView::TemplateRenderer.class_eval do
26
47
  def render_template_with_active_template(template, layout_name = nil, locals = {})
27
- template_stack = @view.controller.try(:active_template_stack)
48
+ template_stack = @view.controller.respond_to?(:active_template_stack) && @view.controller.active_template_stack
28
49
  template_stack.push(template) if template_stack
29
50
  result = render_template_without_active_template( template, layout_name, locals)
30
51
  template_stack.pop if template_stack
@@ -36,7 +57,7 @@ end
36
57
 
37
58
  ActionView::PartialRenderer.class_eval do
38
59
  def render_partial_with_active_template
39
- template_stack = @view.controller.try(:active_template_stack)
60
+ template_stack = @view.controller.respond_to?(:active_template_stack) && @view.controller.active_template_stack
40
61
  template_stack.push(@template) if template_stack
41
62
  result = render_partial_without_active_template
42
63
  template_stack.pop if template_stack
metadata CHANGED
@@ -1,81 +1,72 @@
1
- --- !ruby/object:Gem::Specification
1
+ --- !ruby/object:Gem::Specification
2
2
  name: render_parent
3
- version: !ruby/object:Gem::Version
4
- hash: 29
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.2
5
5
  prerelease:
6
- segments:
7
- - 0
8
- - 0
9
- - 1
10
- version: 0.0.1
11
6
  platform: ruby
12
- authors:
7
+ authors:
13
8
  - Anton Argirov
14
9
  autorequire:
15
10
  bindir: bin
16
11
  cert_chain: []
17
-
18
- date: 2012-09-17 00:00:00 +07:00
19
- default_executable:
20
- dependencies:
21
- - !ruby/object:Gem::Dependency
12
+ date: 2012-10-11 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
22
15
  name: rails
23
- type: :runtime
24
- version_requirements: &id001 !ruby/object:Gem::Requirement
16
+ requirement: !ruby/object:Gem::Requirement
25
17
  none: false
26
- requirements:
27
- - - ">="
28
- - !ruby/object:Gem::Version
29
- hash: 3
30
- segments:
31
- - 2
32
- - 3
33
- - 0
18
+ requirements:
19
+ - - ! '>='
20
+ - !ruby/object:Gem::Version
34
21
  version: 2.3.0
35
- requirement: *id001
22
+ type: :runtime
36
23
  prerelease: false
37
- - !ruby/object:Gem::Dependency
24
+ version_requirements: !ruby/object:Gem::Requirement
25
+ none: false
26
+ requirements:
27
+ - - ! '>='
28
+ - !ruby/object:Gem::Version
29
+ version: 2.3.0
30
+ - !ruby/object:Gem::Dependency
38
31
  name: bundler
39
- type: :development
40
- version_requirements: &id002 !ruby/object:Gem::Requirement
32
+ requirement: !ruby/object:Gem::Requirement
41
33
  none: false
42
- requirements:
34
+ requirements:
43
35
  - - ~>
44
- - !ruby/object:Gem::Version
45
- hash: 19
46
- segments:
47
- - 1
48
- - 1
49
- - 0
36
+ - !ruby/object:Gem::Version
50
37
  version: 1.1.0
51
- requirement: *id002
38
+ type: :development
52
39
  prerelease: false
53
- - !ruby/object:Gem::Dependency
40
+ version_requirements: !ruby/object:Gem::Requirement
41
+ none: false
42
+ requirements:
43
+ - - ~>
44
+ - !ruby/object:Gem::Version
45
+ version: 1.1.0
46
+ - !ruby/object:Gem::Dependency
54
47
  name: jeweler
55
- type: :development
56
- version_requirements: &id003 !ruby/object:Gem::Requirement
48
+ requirement: !ruby/object:Gem::Requirement
57
49
  none: false
58
- requirements:
50
+ requirements:
59
51
  - - ~>
60
- - !ruby/object:Gem::Version
61
- hash: 49
62
- segments:
63
- - 1
64
- - 8
65
- - 3
52
+ - !ruby/object:Gem::Version
66
53
  version: 1.8.3
67
- requirement: *id003
54
+ type: :development
68
55
  prerelease: false
56
+ version_requirements: !ruby/object:Gem::Requirement
57
+ none: false
58
+ requirements:
59
+ - - ~>
60
+ - !ruby/object:Gem::Version
61
+ version: 1.8.3
69
62
  description:
70
63
  email: anton.argirov@gmail.com
71
64
  executables: []
72
-
73
65
  extensions: []
74
-
75
- extra_rdoc_files:
66
+ extra_rdoc_files:
76
67
  - LICENSE.txt
77
68
  - README.rdoc
78
- files:
69
+ files:
79
70
  - .document
80
71
  - Gemfile
81
72
  - LICENSE.txt
@@ -87,43 +78,37 @@ files:
87
78
  - lib/render_parent/rails2.rb
88
79
  - lib/render_parent/rails3.rb
89
80
  - lib/render_parent/rails3/on_load_action_controller.rb
81
+ - lib/render_parent/rails3/on_load_action_mailer.rb
90
82
  - lib/render_parent/rails3/on_load_action_view.rb
91
- - render_parent.gemspec
92
83
  - test/helper.rb
93
84
  - test/test_render_parent.rb
94
- has_rdoc: true
95
85
  homepage: http://redmine.academ.org
96
- licenses:
86
+ licenses:
97
87
  - MIT
98
88
  post_install_message:
99
89
  rdoc_options: []
100
-
101
- require_paths:
90
+ require_paths:
102
91
  - lib
103
- required_ruby_version: !ruby/object:Gem::Requirement
92
+ required_ruby_version: !ruby/object:Gem::Requirement
104
93
  none: false
105
- requirements:
106
- - - ">="
107
- - !ruby/object:Gem::Version
108
- hash: 3
109
- segments:
94
+ requirements:
95
+ - - ! '>='
96
+ - !ruby/object:Gem::Version
97
+ version: '0'
98
+ segments:
110
99
  - 0
111
- version: "0"
112
- required_rubygems_version: !ruby/object:Gem::Requirement
100
+ hash: 117922609
101
+ required_rubygems_version: !ruby/object:Gem::Requirement
113
102
  none: false
114
- requirements:
115
- - - ">="
116
- - !ruby/object:Gem::Version
117
- hash: 3
118
- segments:
119
- - 0
120
- version: "0"
103
+ requirements:
104
+ - - ! '>='
105
+ - !ruby/object:Gem::Version
106
+ version: '0'
121
107
  requirements: []
122
-
123
108
  rubyforge_project:
124
- rubygems_version: 1.6.2
109
+ rubygems_version: 1.8.24
125
110
  signing_key:
126
111
  specification_version: 3
127
- summary: Adds Rails "render :parent" helper, which renders template with the same name as current but higher on the view path
112
+ summary: Adds Rails "render :parent" helper, which renders template with the same
113
+ name as current but higher on the view path
128
114
  test_files: []
129
-
@@ -1,59 +0,0 @@
1
- # Generated by jeweler
2
- # DO NOT EDIT THIS FILE DIRECTLY
3
- # Instead, edit Jeweler::Tasks in rakefile, and run 'rake gemspec'
4
- # -*- encoding: utf-8 -*-
5
-
6
- Gem::Specification.new do |s|
7
- s.name = %q{render_parent}
8
- s.version = "0.0.1"
9
-
10
- s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
- s.authors = ["Anton Argirov"]
12
- s.date = %q{2012-09-17}
13
- s.email = %q{anton.argirov@gmail.com}
14
- s.extra_rdoc_files = [
15
- "LICENSE.txt",
16
- "README.rdoc"
17
- ]
18
- s.files = [
19
- ".document",
20
- "Gemfile",
21
- "LICENSE.txt",
22
- "README.rdoc",
23
- "Rakefile",
24
- "VERSION",
25
- "lib/rails/init.rb",
26
- "lib/render_parent.rb",
27
- "lib/render_parent/rails2.rb",
28
- "lib/render_parent/rails3.rb",
29
- "lib/render_parent/rails3/on_load_action_controller.rb",
30
- "lib/render_parent/rails3/on_load_action_view.rb",
31
- "render_parent.gemspec",
32
- "test/helper.rb",
33
- "test/test_render_parent.rb"
34
- ]
35
- s.homepage = %q{http://redmine.academ.org}
36
- s.licenses = ["MIT"]
37
- s.require_paths = ["lib"]
38
- s.rubygems_version = %q{1.6.2}
39
- s.summary = %q{Adds Rails "render :parent" helper, which renders template with the same name as current but higher on the view path}
40
-
41
- if s.respond_to? :specification_version then
42
- s.specification_version = 3
43
-
44
- if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
45
- s.add_runtime_dependency(%q<rails>, [">= 2.3.0"])
46
- s.add_development_dependency(%q<bundler>, ["~> 1.1.0"])
47
- s.add_development_dependency(%q<jeweler>, ["~> 1.8.3"])
48
- else
49
- s.add_dependency(%q<rails>, [">= 2.3.0"])
50
- s.add_dependency(%q<bundler>, ["~> 1.1.0"])
51
- s.add_dependency(%q<jeweler>, ["~> 1.8.3"])
52
- end
53
- else
54
- s.add_dependency(%q<rails>, [">= 2.3.0"])
55
- s.add_dependency(%q<bundler>, ["~> 1.1.0"])
56
- s.add_dependency(%q<jeweler>, ["~> 1.8.3"])
57
- end
58
- end
59
-