render_parent2 0.0.1

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.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: aade8ed90bd10e06c8f61b5a6007745f5db03c3a
4
+ data.tar.gz: 1d041c9c6e61a9f8361d9690f7253f25551a78d5
5
+ SHA512:
6
+ metadata.gz: '08e692bc6199b8e606c8b2302b2ce8459f8e4ec18ac8a171227650ed373f63b1e9317c23858953dc05655579b61fe5033ec707b04138f5b35d9691b49b1b6304'
7
+ data.tar.gz: 1ca45fcbcd72a8c5bfee5e48b18a09b8171023c871ecb493808644c470f1c7e80e282f7aa840ccf135b23e0faba2640f1fedac3206169403bbd6b7aee821b8a5
data/.document ADDED
@@ -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 'https://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'
9
+ gem 'jeweler'
10
+ end
data/LICENSE.txt ADDED
@@ -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.
data/README.rdoc ADDED
@@ -0,0 +1,5 @@
1
+ = render_parent2
2
+
3
+ Adds Rails "render :parent" helper, which renders template with the same name as current but higher on the view path
4
+
5
+ This is a fork from https://github.com/anteo/render-parent that adds support for Rails 5.
data/Rakefile ADDED
@@ -0,0 +1,46 @@
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_parent2"
18
+ gem.homepage = "https://github.com/kenan3008/render_parent"
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.description = %Q{This version adds Rails 5 support}
22
+ gem.email = "kenan@dkenan.com"
23
+ gem.authors = ["Kenan Dervišević", "Anton Argirov", "MayamaTakeshi"]
24
+ gem.files = Dir.glob('lib/**/*.rb') + %w(.document Gemfile LICENSE.txt README.rdoc Rakefile VERSION)
25
+ # dependencies defined in Gemfile
26
+ end
27
+ Jeweler::RubygemsDotOrgTasks.new
28
+
29
+ require 'rake/testtask'
30
+ Rake::TestTask.new(:test) do |test|
31
+ test.libs << 'lib' << 'test'
32
+ test.pattern = 'test/**/test_*.rb'
33
+ test.verbose = true
34
+ end
35
+
36
+ task :default => :test
37
+
38
+ require 'rdoc/task'
39
+ Rake::RDocTask.new do |rdoc|
40
+ version = File.exist?('VERSION') ? File.read('VERSION') : ""
41
+
42
+ rdoc.rdoc_dir = 'rdoc'
43
+ rdoc.title = "render_parent2 #{version}"
44
+ rdoc.rdoc_files.include('README*')
45
+ rdoc.rdoc_files.include('lib/**/*.rb')
46
+ end
data/VERSION ADDED
@@ -0,0 +1 @@
1
+ 0.0.9
data/lib/rails/init.rb ADDED
@@ -0,0 +1 @@
1
+ require 'render_parent2/rails2'
@@ -0,0 +1,7 @@
1
+ if Rails::VERSION::MAJOR >= 5
2
+ require 'render_parent2/rails5'
3
+ elsif Rails::VERSION::MAJOR >= 3
4
+ require 'render_parent2/rails3'
5
+ elsif Rails::VERSION::MAJOR == 2
6
+ require 'render_parent2/rails2'
7
+ end
@@ -0,0 +1,62 @@
1
+ require 'action_view/base'
2
+
3
+ ActionView::Base.class_eval do
4
+ def render_parent_template(local_assigns = {}, &block)
5
+ view_paths.exclusions << template
6
+ result = render(:file => template.to_s, :locals => local_assigns, &block)
7
+ view_paths.exclusions.delete template
8
+ result
9
+ end
10
+
11
+ def render_with_parent(options = {}, local_assigns = {}, &block)
12
+ if options == :parent
13
+ render_parent_template(local_assigns, &block)
14
+ else
15
+ render_without_parent(options, local_assigns, &block)
16
+ end
17
+ end
18
+
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
62
+ end
@@ -0,0 +1,17 @@
1
+ require 'rails'
2
+
3
+ module RenderParent
4
+ class Railtie < Rails::Railtie
5
+ initializer "render_parent2.initialize" do
6
+ ActiveSupport.on_load(:action_controller) do
7
+ require 'render_parent2/rails3/on_load_action_controller'
8
+ end
9
+ ActiveSupport.on_load(:action_mailer) do
10
+ require 'render_parent2/rails3/on_load_action_mailer'
11
+ end
12
+ ActiveSupport.on_load(:action_view) do
13
+ require 'render_parent2/rails3/on_load_action_view'
14
+ end
15
+ end
16
+ end
17
+ 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,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
@@ -0,0 +1,61 @@
1
+ ActionView::Base.class_eval do
2
+ def render_parent_template(locals = {}, &block)
3
+ template = controller.active_template
4
+ view_paths.exclusions << template
5
+ locals["__rendered_depth_#{view_paths.exclusions.count}"] = true
6
+ handlers = ActionView::Template::Handlers.extensions.select do |ext|
7
+ ActionView::Template.handler_for_extension(ext) == template.handler
8
+ end
9
+ result = render(:template => template.virtual_path,
10
+ :formats => template.formats,
11
+ :handlers => handlers,
12
+ :locals => locals, &block)
13
+ view_paths.exclusions.delete template
14
+ result
15
+ end
16
+
17
+ def render_with_parent(options = {}, locals = {}, &block)
18
+ if options == :parent
19
+ render_parent_template(locals, &block)
20
+ else
21
+ render_without_parent(options, locals, &block)
22
+ end
23
+ end
24
+
25
+ alias_method_chain :render, :parent
26
+ end
27
+
28
+ ActionView::PathSet.class_eval do
29
+ attr_writer :exclusions
30
+
31
+ def exclusions
32
+ @exclusions ||= []
33
+ end
34
+
35
+ def find_all_with_exclusions(path, prefixes = [], *args)
36
+ excluded = exclusions.map(&:identifier)
37
+ prefixes = [prefixes] if String === prefixes
38
+ prefixes.each do |prefix|
39
+ paths.each do |resolver|
40
+ templates = resolver.find_all(path, prefix, *args)
41
+ templates.delete_if {|t| excluded.include? t.identifier} unless templates.empty?
42
+ return templates unless templates.empty?
43
+ end
44
+ end
45
+ []
46
+ end
47
+
48
+ alias_method_chain :find_all, :exclusions
49
+ end
50
+
51
+ ActionView::Template.class_eval do
52
+ def render_with_active_template(view, locals, buffer=nil, &block)
53
+ template_stack = view.controller.respond_to?(:active_template_stack) && view.controller.active_template_stack
54
+ template_stack.push(self) if template_stack
55
+ result = render_without_active_template(view, locals, buffer, &block)
56
+ template_stack.pop if template_stack
57
+ result
58
+ end
59
+
60
+ alias_method_chain :render, :active_template
61
+ end
@@ -0,0 +1,17 @@
1
+ require 'rails'
2
+
3
+ module RenderParent
4
+ class Railtie < Rails::Railtie
5
+ initializer "render_parent2.initialize" do
6
+ ActiveSupport.on_load(:action_controller) do
7
+ require 'render_parent2/rails3/on_load_action_controller'
8
+ end
9
+ ActiveSupport.on_load(:action_mailer) do
10
+ require 'render_parent2/rails3/on_load_action_mailer'
11
+ end
12
+ ActiveSupport.on_load(:action_view) do
13
+ require 'render_parent2/rails5/on_load_action_view'
14
+ end
15
+ end
16
+ end
17
+ end
@@ -0,0 +1,64 @@
1
+ ActionView::Base.class_eval do
2
+ def render_parent_template(locals = {}, &block)
3
+ template = controller.active_template
4
+ view_paths.exclusions << template
5
+ locals["__rendered_depth_#{view_paths.exclusions.count}"] = true
6
+ handlers = ActionView::Template::Handlers.extensions.select do |ext|
7
+ ActionView::Template.handler_for_extension(ext) == template.handler
8
+ end
9
+ result = render(:template => template.virtual_path,
10
+ :formats => template.formats,
11
+ :handlers => handlers,
12
+ :locals => locals, &block)
13
+ view_paths.exclusions.delete template
14
+ result
15
+ end
16
+
17
+ def render_with_parent(options = {}, locals = {}, &block)
18
+ if options == :parent
19
+ render_parent_template(locals, &block)
20
+ else
21
+ render_without_parent(options, locals, &block)
22
+ end
23
+ end
24
+
25
+ alias_method :render_without_parent, :render
26
+ alias_method :render, :render_with_parent
27
+ end
28
+
29
+ ActionView::PathSet.class_eval do
30
+ attr_writer :exclusions
31
+
32
+ def exclusions
33
+ @exclusions ||= []
34
+ end
35
+
36
+ def find_all_with_exclusions(path, prefixes = [], *args)
37
+ excluded = exclusions.map(&:identifier)
38
+ prefixes = [prefixes] if String === prefixes
39
+ prefixes.each do |prefix|
40
+ paths.each do |resolver|
41
+ templates = resolver.find_all(path, prefix, *args)
42
+ templates.delete_if {|t| excluded.include? t.identifier} unless templates.empty?
43
+ return templates unless templates.empty?
44
+ end
45
+ end
46
+ []
47
+ end
48
+
49
+ alias_method :find_all_without_exclusions, :find_all
50
+ alias_method :find_all, :find_all_with_exclusions
51
+ end
52
+
53
+ ActionView::Template.class_eval do
54
+ def render_with_active_template(view, locals, buffer=nil, &block)
55
+ template_stack = view.controller.respond_to?(:active_template_stack) && view.controller.active_template_stack
56
+ template_stack.push(self) if template_stack
57
+ result = render_without_active_template(view, locals, buffer, &block)
58
+ template_stack.pop if template_stack
59
+ result
60
+ end
61
+
62
+ alias_method :render_without_active_template, :render
63
+ alias_method :render, :render_with_active_template
64
+ end
metadata ADDED
@@ -0,0 +1,105 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: render_parent2
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - Kenan Dervišević
8
+ - Anton Argirov
9
+ - MayamaTakeshi
10
+ autorequire:
11
+ bindir: bin
12
+ cert_chain: []
13
+ date: 2019-05-05 00:00:00.000000000 Z
14
+ dependencies:
15
+ - !ruby/object:Gem::Dependency
16
+ name: rails
17
+ requirement: !ruby/object:Gem::Requirement
18
+ requirements:
19
+ - - ">="
20
+ - !ruby/object:Gem::Version
21
+ version: 2.3.0
22
+ type: :runtime
23
+ prerelease: false
24
+ version_requirements: !ruby/object:Gem::Requirement
25
+ requirements:
26
+ - - ">="
27
+ - !ruby/object:Gem::Version
28
+ version: 2.3.0
29
+ - !ruby/object:Gem::Dependency
30
+ name: bundler
31
+ requirement: !ruby/object:Gem::Requirement
32
+ requirements:
33
+ - - ">="
34
+ - !ruby/object:Gem::Version
35
+ version: '0'
36
+ type: :development
37
+ prerelease: false
38
+ version_requirements: !ruby/object:Gem::Requirement
39
+ requirements:
40
+ - - ">="
41
+ - !ruby/object:Gem::Version
42
+ version: '0'
43
+ - !ruby/object:Gem::Dependency
44
+ name: jeweler
45
+ requirement: !ruby/object:Gem::Requirement
46
+ requirements:
47
+ - - ">="
48
+ - !ruby/object:Gem::Version
49
+ version: '0'
50
+ type: :development
51
+ prerelease: false
52
+ version_requirements: !ruby/object:Gem::Requirement
53
+ requirements:
54
+ - - ">="
55
+ - !ruby/object:Gem::Version
56
+ version: '0'
57
+ description: This version adds Rails 5 support
58
+ email: kenan@dkenan.com
59
+ executables: []
60
+ extensions: []
61
+ extra_rdoc_files:
62
+ - LICENSE.txt
63
+ - README.rdoc
64
+ files:
65
+ - ".document"
66
+ - Gemfile
67
+ - LICENSE.txt
68
+ - README.rdoc
69
+ - Rakefile
70
+ - VERSION
71
+ - lib/rails/init.rb
72
+ - lib/render_parent2.rb
73
+ - lib/render_parent2/rails2.rb
74
+ - lib/render_parent2/rails3.rb
75
+ - lib/render_parent2/rails3/on_load_action_controller.rb
76
+ - lib/render_parent2/rails3/on_load_action_mailer.rb
77
+ - lib/render_parent2/rails3/on_load_action_view.rb
78
+ - lib/render_parent2/rails5.rb
79
+ - lib/render_parent2/rails5/on_load_action_view.rb
80
+ homepage: https://github.com/kenan3008/render_parent
81
+ licenses:
82
+ - MIT
83
+ metadata: {}
84
+ post_install_message:
85
+ rdoc_options: []
86
+ require_paths:
87
+ - lib
88
+ required_ruby_version: !ruby/object:Gem::Requirement
89
+ requirements:
90
+ - - ">="
91
+ - !ruby/object:Gem::Version
92
+ version: '0'
93
+ required_rubygems_version: !ruby/object:Gem::Requirement
94
+ requirements:
95
+ - - ">="
96
+ - !ruby/object:Gem::Version
97
+ version: '0'
98
+ requirements: []
99
+ rubyforge_project:
100
+ rubygems_version: 2.6.14.4
101
+ signing_key:
102
+ specification_version: 4
103
+ summary: Adds Rails "render :parent" helper, which renders template with the same
104
+ name as current but higher on the view path
105
+ test_files: []