rails-render_hooks 1.0.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.coveralls.yml +1 -0
- data/.gitignore +22 -0
- data/.travis.yml +9 -0
- data/Gemfile +4 -0
- data/LICENSE.txt +22 -0
- data/README.md +65 -0
- data/Rakefile +14 -0
- data/gemfiles/rails_3_2_x.gemfile +5 -0
- data/gemfiles/rails_4_0_x.gemfile +5 -0
- data/gemfiles/rails_4_1_x.gemfile +6 -0
- data/lib/rails/render_hooks/version.rb +5 -0
- data/lib/rails/render_hooks.rb +49 -0
- data/rails-render_hooks.gemspec +26 -0
- data/test/render_hooks_test.rb +114 -0
- data/test/test_helper.rb +20 -0
- metadata +117 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 1091d4e28aa999c15e246d30b20c154d90232d94
|
4
|
+
data.tar.gz: 7368ed7dda9cb22b97133232ccc0dd064b6fce66
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: d42637eea5e9d116ca0e74a1b383dad26097f6b2cd387f17a7c7640887ec23f27bab415df56ef198087412c20cb30f62d4232fb0a3964b6ebdf2be766c84953d
|
7
|
+
data.tar.gz: 14741159673abd8b59f8f4812e5f32567ef40b5e52b83ed317c6f60c171b09b3c2d06b2d5c4551cdffce8dff65293f171356652a4f043f68f4bc760c6efb78fc
|
data/.coveralls.yml
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
service_name: travis-ci
|
data/.gitignore
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
*.gem
|
2
|
+
*.rbc
|
3
|
+
.bundle
|
4
|
+
.config
|
5
|
+
.yardoc
|
6
|
+
Gemfile.lock
|
7
|
+
InstalledFiles
|
8
|
+
_yardoc
|
9
|
+
coverage
|
10
|
+
doc/
|
11
|
+
lib/bundler/man
|
12
|
+
pkg
|
13
|
+
rdoc
|
14
|
+
spec/reports
|
15
|
+
test/tmp
|
16
|
+
test/version_tmp
|
17
|
+
tmp
|
18
|
+
*.bundle
|
19
|
+
*.so
|
20
|
+
*.o
|
21
|
+
*.a
|
22
|
+
mkmf.log
|
data/.travis.yml
ADDED
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
Copyright (c) 2014 pinzolo
|
2
|
+
|
3
|
+
MIT License
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
6
|
+
a copy of this software and associated documentation files (the
|
7
|
+
"Software"), to deal in the Software without restriction, including
|
8
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
9
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
10
|
+
permit persons to whom the Software is furnished to do so, subject to
|
11
|
+
the following conditions:
|
12
|
+
|
13
|
+
The above copyright notice and this permission notice shall be
|
14
|
+
included in all copies or substantial portions of the Software.
|
15
|
+
|
16
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
17
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
18
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
19
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
20
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
21
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
22
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,65 @@
|
|
1
|
+
# rails-render_hooks
|
2
|
+
|
3
|
+
[![Build Status](https://secure.travis-ci.org/pinzolo/rails-render_hooks.png)](http://travis-ci.org/pinzolo/rails-render_hooks)
|
4
|
+
[![Coverage Status](https://coveralls.io/repos/pinzolo/rails-render_hooks/badge.png)](https://coveralls.io/r/pinzolo/rails-render_hooks)
|
5
|
+
|
6
|
+
This gem provides new callbacks to your controller (on RoR).
|
7
|
+
|
8
|
+
## Installation
|
9
|
+
|
10
|
+
Add this line to your application's Gemfile:
|
11
|
+
|
12
|
+
gem 'rails-render_hooks'
|
13
|
+
|
14
|
+
And then execute:
|
15
|
+
|
16
|
+
$ bundle
|
17
|
+
|
18
|
+
Or install it yourself as:
|
19
|
+
|
20
|
+
$ gem install rails-render_hooks
|
21
|
+
|
22
|
+
## Hooks
|
23
|
+
|
24
|
+
* before_render
|
25
|
+
* prepend_before_render
|
26
|
+
* skip_before_render
|
27
|
+
* after_render
|
28
|
+
* prepend_after_render
|
29
|
+
* skip_after_render
|
30
|
+
* around_render
|
31
|
+
* prepend_around_render
|
32
|
+
* skip_around_render
|
33
|
+
|
34
|
+
## Ordering of hooks
|
35
|
+
|
36
|
+
1. before_action (before_filter)
|
37
|
+
1. around_action (around_filter)
|
38
|
+
1. prepend_around_render
|
39
|
+
1. prepend_before_render
|
40
|
+
1. before_render
|
41
|
+
1. around_render
|
42
|
+
1. rendering
|
43
|
+
1. around_render
|
44
|
+
1. after_render
|
45
|
+
1. prepend_after_render
|
46
|
+
1. prepend_around_render
|
47
|
+
1. around_action (around_filter)
|
48
|
+
1. after_action (after_filter)
|
49
|
+
|
50
|
+
## Supported versions
|
51
|
+
|
52
|
+
* Ruby: 1.9.3, 2.0.0, 2.1.2
|
53
|
+
* Rails: 3.2.x, 4.0.x, 4.1.x
|
54
|
+
|
55
|
+
## Contributing
|
56
|
+
|
57
|
+
1. Fork it ( https://github.com/[my-github-username]/rails-render_hooks/fork )
|
58
|
+
2. Create your feature branch (`git checkout -b my-new-feature`)
|
59
|
+
3. Commit your changes (`git commit -am 'Add some feature'`)
|
60
|
+
4. Push to the branch (`git push origin my-new-feature`)
|
61
|
+
5. Create a new Pull Request
|
62
|
+
|
63
|
+
## Changelog
|
64
|
+
|
65
|
+
* v1.0.0 (2014-06-10 JST): First release
|
data/Rakefile
ADDED
@@ -0,0 +1,14 @@
|
|
1
|
+
require "bundler/gem_tasks"
|
2
|
+
require 'rake'
|
3
|
+
require 'rake/testtask'
|
4
|
+
|
5
|
+
desc 'Default: run unit tests.'
|
6
|
+
task :default => :test
|
7
|
+
|
8
|
+
desc 'Test the before_render plugin.'
|
9
|
+
Rake::TestTask.new(:test) do |t|
|
10
|
+
t.libs << 'lib'
|
11
|
+
t.libs << 'test'
|
12
|
+
t.pattern = 'test/**/*_test.rb'
|
13
|
+
t.verbose = true
|
14
|
+
end
|
@@ -0,0 +1,49 @@
|
|
1
|
+
require "rails/render_hooks/version"
|
2
|
+
require "active_support/concern"
|
3
|
+
require "action_controller"
|
4
|
+
|
5
|
+
module RenderHooks
|
6
|
+
extend ActiveSupport::Concern
|
7
|
+
|
8
|
+
included do
|
9
|
+
define_callbacks :process_render
|
10
|
+
alias_method_chain :render, :render_hooks
|
11
|
+
end
|
12
|
+
|
13
|
+
def render_with_render_hooks(*options, &block)
|
14
|
+
if ActiveSupport::VERSION::STRING >= '4.0.0'
|
15
|
+
run_callbacks(:process_render) do
|
16
|
+
render_without_render_hooks(*options, &block)
|
17
|
+
end
|
18
|
+
else
|
19
|
+
run_callbacks(:process_render, action_name) do
|
20
|
+
render_without_render_hooks(*options, &block)
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
24
|
+
|
25
|
+
module ClassMethods
|
26
|
+
[:before, :after, :around].each do |callback|
|
27
|
+
define_method "#{callback}_render" do |*names, &block|
|
28
|
+
_insert_callbacks(names, block) do |name, options|
|
29
|
+
set_callback(:process_render, callback, name, options)
|
30
|
+
end
|
31
|
+
end
|
32
|
+
alias_method :"append_#{callback}_render", :"#{callback}_render"
|
33
|
+
|
34
|
+
define_method "prepend_#{callback}_render" do |*names, &block|
|
35
|
+
_insert_callbacks(names, block) do |name, options|
|
36
|
+
set_callback(:process_render, callback, name, options.merge(:prepend => true))
|
37
|
+
end
|
38
|
+
end
|
39
|
+
|
40
|
+
define_method "skip_#{callback}_render" do |*names, &block|
|
41
|
+
_insert_callbacks(names, block) do |name, options|
|
42
|
+
skip_callback(:process_render, callback, name, options)
|
43
|
+
end
|
44
|
+
end
|
45
|
+
end
|
46
|
+
end
|
47
|
+
end
|
48
|
+
|
49
|
+
ActionController::Base.__send__(:include, RenderHooks)
|
@@ -0,0 +1,26 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'rails/render_hooks/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = "rails-render_hooks"
|
8
|
+
spec.version = Rails::RenderHooks::VERSION
|
9
|
+
spec.authors = ["pinzolo"]
|
10
|
+
spec.email = ["pinzolo@gmail.com"]
|
11
|
+
spec.summary = %q{Add callbacks for render method}
|
12
|
+
spec.description = spec.summary
|
13
|
+
spec.homepage = "https://github.com/pinzolo/rails-render_hooks"
|
14
|
+
spec.license = "MIT"
|
15
|
+
|
16
|
+
spec.files = `git ls-files -z`.split("\x0")
|
17
|
+
spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
|
18
|
+
spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
|
19
|
+
spec.require_paths = ["lib"]
|
20
|
+
|
21
|
+
spec.add_dependency "actionpack", ">= 3.2.0"
|
22
|
+
|
23
|
+
spec.add_development_dependency "bundler", "~> 1.6"
|
24
|
+
spec.add_development_dependency "rake"
|
25
|
+
spec.add_development_dependency "coveralls"
|
26
|
+
end
|
@@ -0,0 +1,114 @@
|
|
1
|
+
require 'test_helper'
|
2
|
+
|
3
|
+
class SampleController < ActionController::Base
|
4
|
+
include RenderHooks
|
5
|
+
|
6
|
+
before_filter :exec_before_action
|
7
|
+
after_filter :exec_after_action
|
8
|
+
around_filter :exec_around_action
|
9
|
+
prepend_before_render :exec_prepend_before_render
|
10
|
+
before_render :exec_before_render, except: [:new]
|
11
|
+
skip_before_render :exec_before_render, only: [:show]
|
12
|
+
prepend_after_render :exec_prepend_after_render
|
13
|
+
after_render :exec_after_render, except: [:new]
|
14
|
+
skip_after_render :exec_after_render, only: [:show]
|
15
|
+
prepend_around_render :exec_prepend_around_render
|
16
|
+
around_render :exec_around_render, except: [:new]
|
17
|
+
skip_around_render :exec_around_render, only: [:show]
|
18
|
+
|
19
|
+
attr_accessor :footmarks
|
20
|
+
|
21
|
+
[:index, :new, :show].each do |action|
|
22
|
+
define_method(action) { render text: '' }
|
23
|
+
end
|
24
|
+
|
25
|
+
def reset
|
26
|
+
@footmarks = []
|
27
|
+
end
|
28
|
+
|
29
|
+
private
|
30
|
+
[:action, :render].each do |type|
|
31
|
+
[:before, :after].each do |callback|
|
32
|
+
define_method(:"exec_#{callback}_#{type}") do
|
33
|
+
@footmarks << "exec_#{callback}_#{type}"
|
34
|
+
end
|
35
|
+
define_method(:"exec_prepend_#{callback}_#{type}") do
|
36
|
+
@footmarks << "exec_prepend_#{callback}_#{type}"
|
37
|
+
end
|
38
|
+
end
|
39
|
+
end
|
40
|
+
|
41
|
+
def exec_around_action
|
42
|
+
@footmarks << "exec_around_action_1"
|
43
|
+
yield
|
44
|
+
@footmarks << "exec_around_action_2"
|
45
|
+
end
|
46
|
+
|
47
|
+
def exec_around_render
|
48
|
+
@footmarks << "exec_around_render_1"
|
49
|
+
yield
|
50
|
+
@footmarks << "exec_around_render_2"
|
51
|
+
end
|
52
|
+
|
53
|
+
def exec_prepend_around_render
|
54
|
+
@footmarks << "exec_prepend_around_render_1"
|
55
|
+
yield
|
56
|
+
@footmarks << "exec_prepend_around_render_2"
|
57
|
+
end
|
58
|
+
end
|
59
|
+
|
60
|
+
class SampleControllerTest < ActionController::TestCase
|
61
|
+
setup do
|
62
|
+
@controller.reset
|
63
|
+
end
|
64
|
+
|
65
|
+
def test_in_place
|
66
|
+
exec_action(:index)
|
67
|
+
assert_equal @controller.footmarks, ["exec_before_action",
|
68
|
+
"exec_around_action_1",
|
69
|
+
"exec_prepend_around_render_1",
|
70
|
+
"exec_prepend_before_render",
|
71
|
+
"exec_before_render",
|
72
|
+
"exec_around_render_1",
|
73
|
+
"exec_around_render_2",
|
74
|
+
"exec_after_render",
|
75
|
+
"exec_prepend_after_render",
|
76
|
+
"exec_prepend_around_render_2",
|
77
|
+
"exec_around_action_2",
|
78
|
+
"exec_after_action"]
|
79
|
+
end
|
80
|
+
|
81
|
+
def test_with_except_option
|
82
|
+
exec_action(:new)
|
83
|
+
assert_equal @controller.footmarks, ["exec_before_action",
|
84
|
+
"exec_around_action_1",
|
85
|
+
"exec_prepend_around_render_1",
|
86
|
+
"exec_prepend_before_render",
|
87
|
+
"exec_prepend_after_render",
|
88
|
+
"exec_prepend_around_render_2",
|
89
|
+
"exec_around_action_2",
|
90
|
+
"exec_after_action"]
|
91
|
+
end
|
92
|
+
|
93
|
+
def test_skip
|
94
|
+
exec_action(:show)
|
95
|
+
assert_equal @controller.footmarks, ["exec_before_action",
|
96
|
+
"exec_around_action_1",
|
97
|
+
"exec_prepend_around_render_1",
|
98
|
+
"exec_prepend_before_render",
|
99
|
+
"exec_prepend_after_render",
|
100
|
+
"exec_prepend_around_render_2",
|
101
|
+
"exec_around_action_2",
|
102
|
+
"exec_after_action"]
|
103
|
+
end
|
104
|
+
private
|
105
|
+
|
106
|
+
def exec_action(action)
|
107
|
+
with_routing do |set|
|
108
|
+
set.draw do
|
109
|
+
get ':controller(/:action)'
|
110
|
+
end
|
111
|
+
process action
|
112
|
+
end
|
113
|
+
end
|
114
|
+
end
|
data/test/test_helper.rb
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
require "coveralls"
|
2
|
+
require "simplecov"
|
3
|
+
SimpleCov.formatter = Coveralls::SimpleCov::Formatter
|
4
|
+
SimpleCov.start do
|
5
|
+
add_filter '/test/'
|
6
|
+
add_filter '/bundle/'
|
7
|
+
end
|
8
|
+
|
9
|
+
require "active_support/version"
|
10
|
+
if ActiveSupport::VERSION::STRING >= '4.1.0'
|
11
|
+
require 'minitest'
|
12
|
+
require 'minitest/autorun'
|
13
|
+
else
|
14
|
+
require 'test/unit'
|
15
|
+
end
|
16
|
+
|
17
|
+
ENV["RAILS_ENV"] = "test"
|
18
|
+
|
19
|
+
require File.expand_path('../../lib/rails/render_hooks', __FILE__)
|
20
|
+
|
metadata
ADDED
@@ -0,0 +1,117 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: rails-render_hooks
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 1.0.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- pinzolo
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2014-06-10 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: actionpack
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - ">="
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: 3.2.0
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - ">="
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: 3.2.0
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: bundler
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - "~>"
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '1.6'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - "~>"
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '1.6'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: rake
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - ">="
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '0'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - ">="
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '0'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: coveralls
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - ">="
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '0'
|
62
|
+
type: :development
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - ">="
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '0'
|
69
|
+
description: Add callbacks for render method
|
70
|
+
email:
|
71
|
+
- pinzolo@gmail.com
|
72
|
+
executables: []
|
73
|
+
extensions: []
|
74
|
+
extra_rdoc_files: []
|
75
|
+
files:
|
76
|
+
- ".coveralls.yml"
|
77
|
+
- ".gitignore"
|
78
|
+
- ".travis.yml"
|
79
|
+
- Gemfile
|
80
|
+
- LICENSE.txt
|
81
|
+
- README.md
|
82
|
+
- Rakefile
|
83
|
+
- gemfiles/rails_3_2_x.gemfile
|
84
|
+
- gemfiles/rails_4_0_x.gemfile
|
85
|
+
- gemfiles/rails_4_1_x.gemfile
|
86
|
+
- lib/rails/render_hooks.rb
|
87
|
+
- lib/rails/render_hooks/version.rb
|
88
|
+
- rails-render_hooks.gemspec
|
89
|
+
- test/render_hooks_test.rb
|
90
|
+
- test/test_helper.rb
|
91
|
+
homepage: https://github.com/pinzolo/rails-render_hooks
|
92
|
+
licenses:
|
93
|
+
- MIT
|
94
|
+
metadata: {}
|
95
|
+
post_install_message:
|
96
|
+
rdoc_options: []
|
97
|
+
require_paths:
|
98
|
+
- lib
|
99
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
100
|
+
requirements:
|
101
|
+
- - ">="
|
102
|
+
- !ruby/object:Gem::Version
|
103
|
+
version: '0'
|
104
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
105
|
+
requirements:
|
106
|
+
- - ">="
|
107
|
+
- !ruby/object:Gem::Version
|
108
|
+
version: '0'
|
109
|
+
requirements: []
|
110
|
+
rubyforge_project:
|
111
|
+
rubygems_version: 2.2.2
|
112
|
+
signing_key:
|
113
|
+
specification_version: 4
|
114
|
+
summary: Add callbacks for render method
|
115
|
+
test_files:
|
116
|
+
- test/render_hooks_test.rb
|
117
|
+
- test/test_helper.rb
|