render_parent 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,5 @@
1
+ lib/**/*.rb
2
+ bin/*
3
+ -
4
+ features/**/*.feature
5
+ LICENSE.txt
data/Gemfile ADDED
@@ -0,0 +1,10 @@
1
+ source "http://rubygems.org"
2
+
3
+ gem "rails", ">= 2.3.0"
4
+
5
+ # Add dependencies to develop your gem here.
6
+ # Include everything needed to run rake, tests, features, etc.
7
+ group :development do
8
+ gem "bundler", "~> 1.1.0"
9
+ gem "jeweler", "~> 1.8.3"
10
+ end
@@ -0,0 +1,20 @@
1
+ Copyright (c) 2012 Anton Argirov
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.
@@ -0,0 +1,19 @@
1
+ = render_parent
2
+
3
+ Description goes here.
4
+
5
+ == Contributing to render_parent
6
+
7
+ * Check out the latest master to make sure the feature hasn't been implemented or the bug hasn't been fixed yet.
8
+ * Check out the issue tracker to make sure someone already hasn't requested it and/or contributed it.
9
+ * Fork the project.
10
+ * Start a feature/bugfix branch.
11
+ * Commit and push until you are happy with your contribution.
12
+ * Make sure to add tests for it. This is important so I don't break it in a future version unintentionally.
13
+ * Please try not to mess with the Rakefile, version, or history. If you want to have your own version, or is otherwise necessary, that is fine, but please isolate to its own commit so I can cherry-pick around it.
14
+
15
+ == Copyright
16
+
17
+ Copyright (c) 2012 Anton Argirov. See LICENSE.txt for
18
+ further details.
19
+
@@ -0,0 +1,44 @@
1
+ # encoding: utf-8
2
+
3
+ require 'rubygems'
4
+ require 'bundler'
5
+ begin
6
+ Bundler.setup(:default, :development)
7
+ rescue Bundler::BundlerError => e
8
+ $stderr.puts e.message
9
+ $stderr.puts "Run `bundle install` to install missing gems"
10
+ exit e.status_code
11
+ end
12
+ require 'rake'
13
+
14
+ require 'jeweler'
15
+ Jeweler::Tasks.new do |gem|
16
+ # gem is a Gem::Specification... see http://docs.rubygems.org/read/chapter/20 for more options
17
+ gem.name = "render_parent"
18
+ gem.homepage = "http://redmine.academ.org"
19
+ gem.license = "MIT"
20
+ gem.summary = %Q{Adds Rails "render :parent" helper, which renders template with the same name as current but higher on the view path}
21
+ gem.email = "anton.argirov@gmail.com"
22
+ gem.authors = ["Anton Argirov"]
23
+ # dependencies defined in Gemfile
24
+ end
25
+ Jeweler::RubygemsDotOrgTasks.new
26
+
27
+ require 'rake/testtask'
28
+ Rake::TestTask.new(:test) do |test|
29
+ test.libs << 'lib' << 'test'
30
+ test.pattern = 'test/**/test_*.rb'
31
+ test.verbose = true
32
+ end
33
+
34
+ task :default => :test
35
+
36
+ require 'rdoc/task'
37
+ Rake::RDocTask.new do |rdoc|
38
+ version = File.exist?('VERSION') ? File.read('VERSION') : ""
39
+
40
+ rdoc.rdoc_dir = 'rdoc'
41
+ rdoc.title = "render_parent #{version}"
42
+ rdoc.rdoc_files.include('README*')
43
+ rdoc.rdoc_files.include('lib/**/*.rb')
44
+ end
data/VERSION ADDED
@@ -0,0 +1 @@
1
+ 0.0.1
@@ -0,0 +1 @@
1
+ require 'render_parent/rails2'
@@ -0,0 +1,5 @@
1
+ if Rails::VERSION::MAJOR == 3
2
+ require 'render_parent/rails3'
3
+ elsif Rails::VERSION::MAJOR == 2
4
+ require 'render_parent/rails2'
5
+ end
@@ -0,0 +1,21 @@
1
+ require 'action_view/base'
2
+
3
+ ActionView::Base.class_eval do
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}
7
+ result = render({:file => template.to_s}, local_assigns, &block)
8
+ view_paths.replace(saved_view_paths)
9
+ result
10
+ end
11
+
12
+ def render_with_parent(options = {}, local_assigns = {}, &block)
13
+ if options == :parent
14
+ render_parent_template(local_assigns, &block)
15
+ else
16
+ render_without_parent(options, local_assigns, &block)
17
+ end
18
+ end
19
+
20
+ alias_method_chain :render, :parent
21
+ end
@@ -0,0 +1,14 @@
1
+ require 'rails'
2
+
3
+ module RenderParent
4
+ class Railtie < Rails::Railtie
5
+ initializer "render_parent.initialize" do
6
+ ActiveSupport.on_load(:action_controller) do
7
+ require 'render_parent/rails3/on_load_action_controller'
8
+ end
9
+ ActiveSupport.on_load(:action_view) do
10
+ require 'render_parent/rails3/on_load_action_view'
11
+ end
12
+ end
13
+ end
14
+ end
@@ -0,0 +1,11 @@
1
+ require 'action_controller/base'
2
+
3
+ ActionController::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
@@ -0,0 +1,47 @@
1
+ require 'action_view/helpers/rendering_helper'
2
+ require 'action_view/renderer/template_renderer'
3
+
4
+ ActionView::Helpers::RenderingHelper.module_eval do
5
+ def render_parent_template(locals = {}, &block)
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}
9
+ result = render({:file => template.virtual_path}, locals, &block)
10
+ view_paths.paths.replace(saved_view_paths)
11
+ result
12
+ end
13
+
14
+ def render_with_parent(options = {}, locals = {}, &block)
15
+ if options == :parent
16
+ render_parent_template(locals, &block)
17
+ else
18
+ render_without_parent(options, locals, &block)
19
+ end
20
+ end
21
+
22
+ alias_method_chain :render, :parent
23
+ end
24
+
25
+ ActionView::TemplateRenderer.class_eval do
26
+ def render_template_with_active_template(template, layout_name = nil, locals = {})
27
+ template_stack = @view.controller.try(:active_template_stack)
28
+ template_stack.push(template) if template_stack
29
+ result = render_template_without_active_template( template, layout_name, locals)
30
+ template_stack.pop if template_stack
31
+ result
32
+ end
33
+
34
+ alias_method_chain :render_template, :active_template
35
+ end
36
+
37
+ ActionView::PartialRenderer.class_eval do
38
+ def render_partial_with_active_template
39
+ template_stack = @view.controller.try(:active_template_stack)
40
+ template_stack.push(@template) if template_stack
41
+ result = render_partial_without_active_template
42
+ template_stack.pop if template_stack
43
+ result
44
+ end
45
+
46
+ alias_method_chain :render_partial, :active_template
47
+ end
@@ -0,0 +1,59 @@
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
+
@@ -0,0 +1,18 @@
1
+ require 'rubygems'
2
+ require 'bundler'
3
+ begin
4
+ Bundler.setup(:default, :development)
5
+ rescue Bundler::BundlerError => e
6
+ $stderr.puts e.message
7
+ $stderr.puts "Run `bundle install` to install missing gems"
8
+ exit e.status_code
9
+ end
10
+ require 'test/unit'
11
+ require 'shoulda'
12
+
13
+ $LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
14
+ $LOAD_PATH.unshift(File.dirname(__FILE__))
15
+ require 'render_parent'
16
+
17
+ class Test::Unit::TestCase
18
+ end
@@ -0,0 +1,7 @@
1
+ require 'helper'
2
+
3
+ class TestRenderParent < Test::Unit::TestCase
4
+ should "probably rename this file and start testing for real" do
5
+ flunk "hey buddy, you should probably rename this file and start testing for real"
6
+ end
7
+ end
metadata ADDED
@@ -0,0 +1,129 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: render_parent
3
+ version: !ruby/object:Gem::Version
4
+ hash: 29
5
+ prerelease:
6
+ segments:
7
+ - 0
8
+ - 0
9
+ - 1
10
+ version: 0.0.1
11
+ platform: ruby
12
+ authors:
13
+ - Anton Argirov
14
+ autorequire:
15
+ bindir: bin
16
+ cert_chain: []
17
+
18
+ date: 2012-09-17 00:00:00 +07:00
19
+ default_executable:
20
+ dependencies:
21
+ - !ruby/object:Gem::Dependency
22
+ name: rails
23
+ type: :runtime
24
+ version_requirements: &id001 !ruby/object:Gem::Requirement
25
+ none: false
26
+ requirements:
27
+ - - ">="
28
+ - !ruby/object:Gem::Version
29
+ hash: 3
30
+ segments:
31
+ - 2
32
+ - 3
33
+ - 0
34
+ version: 2.3.0
35
+ requirement: *id001
36
+ prerelease: false
37
+ - !ruby/object:Gem::Dependency
38
+ name: bundler
39
+ type: :development
40
+ version_requirements: &id002 !ruby/object:Gem::Requirement
41
+ none: false
42
+ requirements:
43
+ - - ~>
44
+ - !ruby/object:Gem::Version
45
+ hash: 19
46
+ segments:
47
+ - 1
48
+ - 1
49
+ - 0
50
+ version: 1.1.0
51
+ requirement: *id002
52
+ prerelease: false
53
+ - !ruby/object:Gem::Dependency
54
+ name: jeweler
55
+ type: :development
56
+ version_requirements: &id003 !ruby/object:Gem::Requirement
57
+ none: false
58
+ requirements:
59
+ - - ~>
60
+ - !ruby/object:Gem::Version
61
+ hash: 49
62
+ segments:
63
+ - 1
64
+ - 8
65
+ - 3
66
+ version: 1.8.3
67
+ requirement: *id003
68
+ prerelease: false
69
+ description:
70
+ email: anton.argirov@gmail.com
71
+ executables: []
72
+
73
+ extensions: []
74
+
75
+ extra_rdoc_files:
76
+ - LICENSE.txt
77
+ - README.rdoc
78
+ files:
79
+ - .document
80
+ - Gemfile
81
+ - LICENSE.txt
82
+ - README.rdoc
83
+ - Rakefile
84
+ - VERSION
85
+ - lib/rails/init.rb
86
+ - lib/render_parent.rb
87
+ - lib/render_parent/rails2.rb
88
+ - lib/render_parent/rails3.rb
89
+ - lib/render_parent/rails3/on_load_action_controller.rb
90
+ - lib/render_parent/rails3/on_load_action_view.rb
91
+ - render_parent.gemspec
92
+ - test/helper.rb
93
+ - test/test_render_parent.rb
94
+ has_rdoc: true
95
+ homepage: http://redmine.academ.org
96
+ licenses:
97
+ - MIT
98
+ post_install_message:
99
+ rdoc_options: []
100
+
101
+ require_paths:
102
+ - lib
103
+ required_ruby_version: !ruby/object:Gem::Requirement
104
+ none: false
105
+ requirements:
106
+ - - ">="
107
+ - !ruby/object:Gem::Version
108
+ hash: 3
109
+ segments:
110
+ - 0
111
+ version: "0"
112
+ required_rubygems_version: !ruby/object:Gem::Requirement
113
+ none: false
114
+ requirements:
115
+ - - ">="
116
+ - !ruby/object:Gem::Version
117
+ hash: 3
118
+ segments:
119
+ - 0
120
+ version: "0"
121
+ requirements: []
122
+
123
+ rubyforge_project:
124
+ rubygems_version: 1.6.2
125
+ signing_key:
126
+ 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
128
+ test_files: []
129
+