render_parent 0.0.9 → 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 146b2ecebd56388e965f6eac412b7f47a019e1561c02b8dd75038e2814e9fe10
4
- data.tar.gz: 7b31323be1a7a6807fcac4118e370d17d8f4b6c3892373251927364fa5a14032
3
+ metadata.gz: 4678d3b70f2c931c5237bffe7aa89eee83913ed79cc6916db74cbec7609a845b
4
+ data.tar.gz: 41a4a66d7e0943d002ebd870eb5358965a66332aa0c28cafc9f9aa17f7885570
5
5
  SHA512:
6
- metadata.gz: 880a5b2c0c492dbc64dfc9372b760b80e96a00058358b0d454c6fbccbb901d67ec136146699699dc1ce60911431ec9b1c79a7d9e18c80981916be71caec5e7eb
7
- data.tar.gz: 6e1857189a4164cc355b25adcd28a1ec169db5194589bf374975a890359379c1b4c597367b61ed5e4a01cbe1ceb90b0b023bfa66e22ba08173121f866f84702d
6
+ metadata.gz: 2690560a9ef6319e37071e82f9d75d54f358fa5075cfa6d68674cb74acd4db343fcdb89b1f8ec8b2b2cb88402b85e8fa84b051670361f4560a6a87275afd9878
7
+ data.tar.gz: 40e6816f4332d04ccf258fe6a40a9af353c999be64164c34a3c293959ce2b1eba7ecae26c60e986339aed58067de89620c347d00ff852f5dc06cfcfe8d6a9b98
data/.ruby-gemset ADDED
@@ -0,0 +1 @@
1
+ default
data/.ruby-version ADDED
@@ -0,0 +1 @@
1
+ 2.6.6
data/Appraisals ADDED
@@ -0,0 +1,35 @@
1
+ appraise 'rails-32' do
2
+ gem 'rails', '~>3.2.0'
3
+ end
4
+
5
+ appraise 'rails-40' do
6
+ gem 'rails', '~>4.0.0'
7
+ end
8
+
9
+ appraise 'rails-41' do
10
+ gem 'rails', '~>4.1.0'
11
+ end
12
+
13
+ appraise 'rails-42' do
14
+ gem 'rails', '~>4.2.0'
15
+ end
16
+
17
+ appraise 'rails-50' do
18
+ gem 'rails', '~>5.0.0'
19
+ end
20
+
21
+ appraise 'rails-51' do
22
+ gem 'rails', '~>5.1.0'
23
+ end
24
+
25
+ appraise 'rails-52' do
26
+ gem 'rails', '~>5.2.0'
27
+ end
28
+
29
+ appraise 'rails-60' do
30
+ gem 'rails', '~>6.0.0'
31
+ end
32
+
33
+ appraise 'rails-61' do
34
+ gem 'rails', '~>6.1.0'
35
+ end
data/Gemfile CHANGED
@@ -5,6 +5,8 @@ gem 'rails', '>= 2.3.0'
5
5
  # Add dependencies to develop your gem here.
6
6
  # Include everything needed to run rake, tests, features, etc.
7
7
  group :development do
8
- gem 'bundler'
9
- gem 'jeweler'
8
+ gem 'bundler', '< 2.0', '>= 1.3.0'
9
+ gem 'jeweler', github: 'technicalpickles/jeweler'
10
+ gem 'rspec'
11
+ gem 'appraisal'
10
12
  end
data/Rakefile CHANGED
@@ -13,34 +13,20 @@ require 'rake'
13
13
 
14
14
  require 'jeweler'
15
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"
16
+ gem.name = "render_parent"
18
17
  gem.homepage = "http://github.com/anteo/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 fixes render_collection}
22
- gem.email = "anton.argirov@gmail.com"
23
- gem.authors = ["Anton Argirov", "MayamaTakeshi"]
24
- gem.files = Dir.glob('lib/**/*.rb') + %w(.document Gemfile LICENSE.txt README.rdoc Rakefile VERSION)
25
- # dependencies defined in Gemfile
18
+ gem.license = "MIT"
19
+ gem.summary = %Q{Adds Rails "render :parent" helper, which renders template with the same name as current but higher on the view path}
20
+ gem.email = "anton.argirov@gmail.com"
21
+ gem.authors = ["Anton Argirov"]
22
+ gem.files = Dir.glob("{lib,spec}/**/*") + %w[.ruby-gemset .ruby-version Appraisals Gemfile LICENSE.txt README.rdoc Rakefile VERSION]
26
23
  end
27
24
  Jeweler::RubygemsDotOrgTasks.new
28
25
 
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
26
+ require 'rspec/core/rake_task'
27
+ RSpec::Core::RakeTask.new(:spec)
37
28
 
38
- require 'rdoc/task'
39
- Rake::RDocTask.new do |rdoc|
40
- version = File.exist?('VERSION') ? File.read('VERSION') : ""
29
+ task :default => :spec
41
30
 
42
- rdoc.rdoc_dir = 'rdoc'
43
- rdoc.title = "render_parent #{version}"
44
- rdoc.rdoc_files.include('README*')
45
- rdoc.rdoc_files.include('lib/**/*.rb')
46
- end
31
+ require 'appraisal/task'
32
+ Appraisal::Task.new
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.0.9
1
+ 0.1.0
@@ -1,17 +1,9 @@
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_mailer) do
10
- require 'render_parent/rails3/on_load_action_mailer'
11
- end
12
- ActiveSupport.on_load(:action_view) do
13
- require 'render_parent/rails3/on_load_action_view'
14
- end
15
- end
16
- end
17
- end
1
+ ActiveSupport.on_load(:action_controller) do
2
+ require 'render_parent/rails/on_load_action_controller'
3
+ end
4
+ ActiveSupport.on_load(:action_mailer) do
5
+ require 'render_parent/rails/on_load_action_mailer'
6
+ end
7
+ ActiveSupport.on_load(:action_view) do
8
+ require 'render_parent/rails3/on_load_action_view'
9
+ end
@@ -1,17 +1,9 @@
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_mailer) do
10
- require 'render_parent/rails3/on_load_action_mailer'
11
- end
12
- ActiveSupport.on_load(:action_view) do
13
- require 'render_parent/rails5/on_load_action_view'
14
- end
15
- end
16
- end
1
+ ActiveSupport.on_load(:action_controller) do
2
+ require 'render_parent/rails/on_load_action_controller'
3
+ end
4
+ ActiveSupport.on_load(:action_mailer) do
5
+ require 'render_parent/rails/on_load_action_mailer'
6
+ end
7
+ ActiveSupport.on_load(:action_view) do
8
+ require 'render_parent/rails5/on_load_action_view'
17
9
  end
@@ -0,0 +1,69 @@
1
+ ActionView::Base.class_eval do
2
+ def render_parent_template(locals = {}, &block)
3
+ template = @current_template
4
+ view_paths.excluded(template) do
5
+ locals["__rendered_depth_#{view_paths.exclusions.count}"] = true
6
+
7
+ handlers = ActionView::Template::Handlers.extensions.select do |ext|
8
+ ActionView::Template.handler_for_extension(ext) == template.handler
9
+ end
10
+ render template: template.virtual_path,
11
+ formats: template.format,
12
+ handlers: handlers,
13
+ locals: locals, &block
14
+ end
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 excluded(template)
33
+ exclusions << template
34
+ yield
35
+ ensure
36
+ exclusions.delete template
37
+ end
38
+
39
+ def exclusions
40
+ @exclusions ||= []
41
+ end
42
+
43
+ def find_all_with_exclusions(path, prefixes = [], *args)
44
+ excluded = exclusions.map(&:identifier)
45
+ prefixes = [prefixes] if String === prefixes
46
+ prefixes.each do |prefix|
47
+ paths.each do |resolver|
48
+ templates = resolver.find_all(path, prefix, *args)
49
+ templates.delete_if { |t| excluded.include? t.identifier } unless templates.empty?
50
+ return templates unless templates.empty?
51
+ end
52
+ end
53
+ []
54
+ end
55
+
56
+ alias_method :find_all_without_exclusions, :find_all
57
+ alias_method :find_all, :find_all_with_exclusions
58
+ end
59
+
60
+ ActionView::LookupContext.class_eval do
61
+ def initialize_with_exclusions(view_paths, details = {}, prefixes = [])
62
+ initialize_without_exclusions(view_paths, details, prefixes)
63
+ @view_paths.exclusions = view_paths.exclusions if view_paths.is_a?(ActionView::PathSet)
64
+ end
65
+
66
+ alias_method :initialize_without_exclusions, :initialize
67
+ alias_method :initialize, :initialize_with_exclusions
68
+ end
69
+
@@ -0,0 +1,3 @@
1
+ ActiveSupport.on_load(:action_view) do
2
+ require 'render_parent/rails6/on_load_action_view'
3
+ end
data/lib/render_parent.rb CHANGED
@@ -1,4 +1,9 @@
1
- if Rails::VERSION::MAJOR >= 5
1
+ require 'rails'
2
+ require 'action_view'
3
+
4
+ if Rails::VERSION::MAJOR >= 6
5
+ require 'render_parent/rails6'
6
+ elsif Rails::VERSION::MAJOR >= 5
2
7
  require 'render_parent/rails5'
3
8
  elsif Rails::VERSION::MAJOR >= 3
4
9
  require 'render_parent/rails3'
@@ -0,0 +1,2 @@
1
+ <%= variable %>
2
+ Contents of path1/template.html.erb
@@ -0,0 +1,2 @@
1
+ <%= render :parent, local_assigns %>
2
+ Contents of path2/template.html.erb
@@ -0,0 +1,2 @@
1
+ <%= render :parent, local_assigns %>
2
+ Contents of path3/template.html.erb
@@ -0,0 +1,54 @@
1
+ require 'spec_helper'
2
+
3
+ RSpec.describe :render_parent do
4
+ class Controller < ActionController::Base
5
+ layout false
6
+
7
+ prepend_view_path('spec/fixtures/path1')
8
+ prepend_view_path('spec/fixtures/path2')
9
+ prepend_view_path('spec/fixtures/path3')
10
+
11
+ def self.build
12
+ if Rails::VERSION::MAJOR < 5
13
+ build_4
14
+ else
15
+ build_5
16
+ end
17
+ end
18
+
19
+ def self.build_4
20
+ request = ActionDispatch::TestRequest.new
21
+ response = ActionDispatch::Response.new
22
+
23
+ instance = new
24
+ instance.request = request
25
+ instance.response = response
26
+ instance
27
+ end
28
+
29
+ def self.build_5
30
+ request = ActionDispatch::TestRequest.create
31
+
32
+ instance = new
33
+ instance.set_request! request
34
+ instance.set_response! make_response!(request)
35
+ instance
36
+ end
37
+ end
38
+
39
+ before(:all) do
40
+ end
41
+
42
+ let(:controller) { Controller.build }
43
+
44
+ it 'should render templates in defined order' do
45
+ result = controller.render(template: 'template', locals: { variable: 'Test variable' })
46
+ result = result.first if result.is_a?(Array)
47
+ expect(result).to eq(<<~EOS)
48
+ Test variable
49
+ Contents of path1/template.html.erb
50
+ Contents of path2/template.html.erb
51
+ Contents of path3/template.html.erb
52
+ EOS
53
+ end
54
+ end
@@ -0,0 +1,103 @@
1
+ require 'action_controller'
2
+ require 'render_parent'
3
+
4
+ # This file was generated by the `rspec --init` command. Conventionally, all
5
+ # specs live under a `spec` directory, which RSpec adds to the `$LOAD_PATH`.
6
+ # The generated `.rspec` file contains `--require spec_helper` which will cause
7
+ # this file to always be loaded, without a need to explicitly require it in any
8
+ # files.
9
+ #
10
+ # Given that it is always loaded, you are encouraged to keep this file as
11
+ # light-weight as possible. Requiring heavyweight dependencies from this file
12
+ # will add to the boot time of your test suite on EVERY test run, even for an
13
+ # individual file that may not need all of that loaded. Instead, consider making
14
+ # a separate helper file that requires the additional dependencies and performs
15
+ # the additional setup, and require it from the spec files that actually need
16
+ # it.
17
+ #
18
+ # See http://rubydoc.info/gems/rspec-core/RSpec/Core/Configuration
19
+ RSpec.configure do |config|
20
+ # rspec-expectations config goes here. You can use an alternate
21
+ # assertion/expectation library such as wrong or the stdlib/minitest
22
+ # assertions if you prefer.
23
+ config.expect_with :rspec do |expectations|
24
+ # This option will default to `true` in RSpec 4. It makes the `description`
25
+ # and `failure_message` of custom matchers include text for helper methods
26
+ # defined using `chain`, e.g.:
27
+ # be_bigger_than(2).and_smaller_than(4).description
28
+ # # => "be bigger than 2 and smaller than 4"
29
+ # ...rather than:
30
+ # # => "be bigger than 2"
31
+ expectations.include_chain_clauses_in_custom_matcher_descriptions = true
32
+ end
33
+
34
+ # rspec-mocks config goes here. You can use an alternate test double
35
+ # library (such as bogus or mocha) by changing the `mock_with` option here.
36
+ config.mock_with :rspec do |mocks|
37
+ # Prevents you from mocking or stubbing a method that does not exist on
38
+ # a real object. This is generally recommended, and will default to
39
+ # `true` in RSpec 4.
40
+ mocks.verify_partial_doubles = true
41
+ end
42
+
43
+ # This option will default to `:apply_to_host_groups` in RSpec 4 (and will
44
+ # have no way to turn it off -- the option exists only for backwards
45
+ # compatibility in RSpec 3). It causes shared context metadata to be
46
+ # inherited by the metadata hash of host groups and examples, rather than
47
+ # triggering implicit auto-inclusion in groups with matching metadata.
48
+ config.shared_context_metadata_behavior = :apply_to_host_groups
49
+
50
+ # The settings below are suggested to provide a good initial experience
51
+ # with RSpec, but feel free to customize to your heart's content.
52
+ =begin
53
+ # This allows you to limit a spec run to individual examples or groups
54
+ # you care about by tagging them with `:focus` metadata. When nothing
55
+ # is tagged with `:focus`, all examples get run. RSpec also provides
56
+ # aliases for `it`, `describe`, and `context` that include `:focus`
57
+ # metadata: `fit`, `fdescribe` and `fcontext`, respectively.
58
+ config.filter_run_when_matching :focus
59
+
60
+ # Allows RSpec to persist some state between runs in order to support
61
+ # the `--only-failures` and `--next-failure` CLI options. We recommend
62
+ # you configure your source control system to ignore this file.
63
+ config.example_status_persistence_file_path = "spec/examples.txt"
64
+
65
+ # Limits the available syntax to the non-monkey patched syntax that is
66
+ # recommended. For more details, see:
67
+ # - http://rspec.info/blog/2012/06/rspecs-new-expectation-syntax/
68
+ # - http://www.teaisaweso.me/blog/2013/05/27/rspecs-new-message-expectation-syntax/
69
+ # - http://rspec.info/blog/2014/05/notable-changes-in-rspec-3/#zero-monkey-patching-mode
70
+ config.disable_monkey_patching!
71
+
72
+ # This setting enables warnings. It's recommended, but in some cases may
73
+ # be too noisy due to issues in dependencies.
74
+ config.warnings = true
75
+
76
+ # Many RSpec users commonly either run the entire suite or an individual
77
+ # file, and it's useful to allow more verbose output when running an
78
+ # individual spec file.
79
+ if config.files_to_run.one?
80
+ # Use the documentation formatter for detailed output,
81
+ # unless a formatter has already been configured
82
+ # (e.g. via a command-line flag).
83
+ config.default_formatter = "doc"
84
+ end
85
+
86
+ # Print the 10 slowest examples and example groups at the
87
+ # end of the spec run, to help surface which specs are running
88
+ # particularly slow.
89
+ config.profile_examples = 10
90
+
91
+ # Run specs in random order to surface order dependencies. If you find an
92
+ # order dependency and want to debug it, you can fix the order by providing
93
+ # the seed, which is printed after each run.
94
+ # --seed 1234
95
+ config.order = :random
96
+
97
+ # Seed global randomization in this process using the `--seed` CLI option.
98
+ # Setting this allows you to use `--seed` to deterministically reproduce
99
+ # test failures related to randomization by passing the same `--seed` value
100
+ # as the one that triggered the failure.
101
+ Kernel.srand config.seed
102
+ =end
103
+ end
metadata CHANGED
@@ -1,15 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: render_parent
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.9
4
+ version: 0.1.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Anton Argirov
8
- - MayamaTakeshi
9
- autorequire:
8
+ autorequire:
10
9
  bindir: bin
11
10
  cert_chain: []
12
- date: 2019-11-20 00:00:00.000000000 Z
11
+ date: 2021-11-03 00:00:00.000000000 Z
13
12
  dependencies:
14
13
  - !ruby/object:Gem::Dependency
15
14
  name: rails
@@ -27,6 +26,26 @@ dependencies:
27
26
  version: 2.3.0
28
27
  - !ruby/object:Gem::Dependency
29
28
  name: bundler
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ">="
32
+ - !ruby/object:Gem::Version
33
+ version: 1.3.0
34
+ - - "<"
35
+ - !ruby/object:Gem::Version
36
+ version: '2.0'
37
+ type: :development
38
+ prerelease: false
39
+ version_requirements: !ruby/object:Gem::Requirement
40
+ requirements:
41
+ - - ">="
42
+ - !ruby/object:Gem::Version
43
+ version: 1.3.0
44
+ - - "<"
45
+ - !ruby/object:Gem::Version
46
+ version: '2.0'
47
+ - !ruby/object:Gem::Dependency
48
+ name: jeweler
30
49
  requirement: !ruby/object:Gem::Requirement
31
50
  requirements:
32
51
  - - ">="
@@ -40,7 +59,21 @@ dependencies:
40
59
  - !ruby/object:Gem::Version
41
60
  version: '0'
42
61
  - !ruby/object:Gem::Dependency
43
- name: jeweler
62
+ name: rspec
63
+ requirement: !ruby/object:Gem::Requirement
64
+ requirements:
65
+ - - ">="
66
+ - !ruby/object:Gem::Version
67
+ version: '0'
68
+ type: :development
69
+ prerelease: false
70
+ version_requirements: !ruby/object:Gem::Requirement
71
+ requirements:
72
+ - - ">="
73
+ - !ruby/object:Gem::Version
74
+ version: '0'
75
+ - !ruby/object:Gem::Dependency
76
+ name: appraisal
44
77
  requirement: !ruby/object:Gem::Requirement
45
78
  requirements:
46
79
  - - ">="
@@ -53,7 +86,7 @@ dependencies:
53
86
  - - ">="
54
87
  - !ruby/object:Gem::Version
55
88
  version: '0'
56
- description: This version fixes render_collection
89
+ description:
57
90
  email: anton.argirov@gmail.com
58
91
  executables: []
59
92
  extensions: []
@@ -61,7 +94,9 @@ extra_rdoc_files:
61
94
  - LICENSE.txt
62
95
  - README.rdoc
63
96
  files:
64
- - ".document"
97
+ - ".ruby-gemset"
98
+ - ".ruby-version"
99
+ - Appraisals
65
100
  - Gemfile
66
101
  - LICENSE.txt
67
102
  - README.rdoc
@@ -69,18 +104,25 @@ files:
69
104
  - VERSION
70
105
  - lib/rails/init.rb
71
106
  - lib/render_parent.rb
107
+ - lib/render_parent/rails/on_load_action_controller.rb
108
+ - lib/render_parent/rails/on_load_action_mailer.rb
72
109
  - lib/render_parent/rails2.rb
73
110
  - lib/render_parent/rails3.rb
74
- - lib/render_parent/rails3/on_load_action_controller.rb
75
- - lib/render_parent/rails3/on_load_action_mailer.rb
76
111
  - lib/render_parent/rails3/on_load_action_view.rb
77
112
  - lib/render_parent/rails5.rb
78
113
  - lib/render_parent/rails5/on_load_action_view.rb
114
+ - lib/render_parent/rails6.rb
115
+ - lib/render_parent/rails6/on_load_action_view.rb
116
+ - spec/fixtures/path1/template.html.erb
117
+ - spec/fixtures/path2/template.html.erb
118
+ - spec/fixtures/path3/template.html.erb
119
+ - spec/lib/render_parent_spec.rb
120
+ - spec/spec_helper.rb
79
121
  homepage: http://github.com/anteo/render-parent
80
122
  licenses:
81
123
  - MIT
82
124
  metadata: {}
83
- post_install_message:
125
+ post_install_message:
84
126
  rdoc_options: []
85
127
  require_paths:
86
128
  - lib
@@ -95,9 +137,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
95
137
  - !ruby/object:Gem::Version
96
138
  version: '0'
97
139
  requirements: []
98
- rubyforge_project:
99
- rubygems_version: 2.7.7
100
- signing_key:
140
+ rubygems_version: 3.0.9
141
+ signing_key:
101
142
  specification_version: 4
102
143
  summary: Adds Rails "render :parent" helper, which renders template with the same
103
144
  name as current but higher on the view path
data/.document DELETED
@@ -1,5 +0,0 @@
1
- lib/**/*.rb
2
- bin/*
3
- -
4
- features/**/*.feature
5
- LICENSE.txt