active_decorator 0.5.3 → 0.6.0
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 +4 -4
- data/.rspec +1 -0
- data/.travis.yml +8 -14
- data/README.md +45 -1
- data/gemfiles/Gemfile-rails.5.0.0.beta1 +9 -0
- data/lib/active_decorator/config.rb +2 -17
- data/lib/active_decorator/decorator.rb +13 -9
- data/lib/active_decorator/monkey/abstract_controller/rendering.rb +11 -9
- data/lib/active_decorator/monkey/action_controller/base/rescue_from.rb +11 -8
- data/lib/active_decorator/monkey/action_view/partial_renderer.rb +13 -31
- data/lib/active_decorator/railtie.rb +13 -4
- data/lib/active_decorator/version.rb +1 -1
- data/lib/generators/rails/templates/decorator.rb +0 -1
- data/lib/generators/rspec/templates/decorator_spec.rb +0 -1
- data/lib/generators/test_unit/templates/decorator_test.rb +0 -1
- data/spec/configuration_spec.rb +0 -2
- data/spec/controllers/fake_detection_spec.rb +0 -2
- data/spec/fake_app/fake_app.rb +6 -20
- data/spec/features/action_view_helpers_spec.rb +0 -2
- data/spec/features/controller_ivar_spec.rb +0 -7
- data/spec/features/jbuilder_spec.rb +0 -6
- data/spec/features/partial_spec.rb +0 -6
- data/spec/spec_helper.rb +1 -0
- metadata +4 -5
- data/gemfiles/Gemfile-rails.3.0.x +0 -16
- data/gemfiles/Gemfile-rails.3.1.x +0 -19
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 42f46de551b9463436f22f02b446cc587c69d7f4
|
4
|
+
data.tar.gz: bc4bcb100cb17417f34c18e919adce05e18ee02e
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 7e7775bd6e2b67fbbd60b968926eb8d50b0e048729a976e7cd247a9c1a942fc3edbaa6624734dde9d8599cd536dccf15db9b3334da96eb6214ddba5266abd2ba
|
7
|
+
data.tar.gz: c13028fd5ac9ebf59e8e699423aa1179b2816edbaddd70c2e82fce43ccfdb37a8ba9d82fff1a239b1207c49b82fd408d3b561df74d5959499d7c5ec3f5637b5e
|
data/.rspec
CHANGED
data/.travis.yml
CHANGED
@@ -3,33 +3,27 @@ language: ruby
|
|
3
3
|
script: bundle exec rake spec
|
4
4
|
|
5
5
|
rvm:
|
6
|
-
- 1.9.3
|
7
6
|
- 2.0.0
|
8
|
-
- 2.1
|
9
|
-
- 2.2
|
7
|
+
- 2.1.8
|
8
|
+
- 2.2.4
|
9
|
+
- 2.3.0
|
10
10
|
- ruby-head
|
11
11
|
gemfile:
|
12
12
|
- gemfiles/Gemfile-rails.3.2.x
|
13
13
|
- gemfiles/Gemfile-rails.4.0.x
|
14
14
|
- gemfiles/Gemfile-rails.4.1.x
|
15
15
|
- gemfiles/Gemfile-rails.4.2.x
|
16
|
+
- gemfiles/Gemfile-rails.5.0.0.beta1
|
16
17
|
|
17
18
|
sudo: false
|
18
19
|
|
19
20
|
matrix:
|
20
|
-
include:
|
21
|
-
- rvm: 1.8.7
|
22
|
-
gemfile: gemfiles/Gemfile-rails.3.0.x
|
23
|
-
- rvm: 1.8.7
|
24
|
-
gemfile: gemfiles/Gemfile-rails.3.1.x
|
25
|
-
- rvm: 1.8.7
|
26
|
-
gemfile: gemfiles/Gemfile-rails.3.2.x
|
27
|
-
- rvm: 1.9.3
|
28
|
-
gemfile: gemfiles/Gemfile-rails.3.0.x
|
29
|
-
- rvm: 1.9.3
|
30
|
-
gemfile: gemfiles/Gemfile-rails.3.1.x
|
31
21
|
exclude:
|
32
22
|
- rvm: ruby-head
|
33
23
|
gemfile: gemfiles/Gemfile-rails.3.2.x
|
24
|
+
- rvm: 2.0.0
|
25
|
+
gemfile: gemfiles/Gemfile-rails.5.0.0.beta1
|
26
|
+
- rvm: 2.1.8
|
27
|
+
gemfile: gemfiles/Gemfile-rails.5.0.0.beta1
|
34
28
|
allow_failures:
|
35
29
|
- rvm: ruby-head
|
data/README.md
CHANGED
@@ -14,7 +14,9 @@ A simple and Rubyish view helper for Rails 3 and Rails 4. Keep your helpers and
|
|
14
14
|
|
15
15
|
## Supported versions ##
|
16
16
|
|
17
|
-
|
17
|
+
* Ruby 2.0.0, 2.1.x, 2.2.x, 2.3.x, and 2.4 (trunk)
|
18
|
+
|
19
|
+
* Rails 3.2.x, 4.0.x, 4.1.x, 4.2.x, and 5.0 (edge)
|
18
20
|
|
19
21
|
|
20
22
|
## Supported ORMs ##
|
@@ -63,6 +65,48 @@ end
|
|
63
65
|
<% end %>
|
64
66
|
```
|
65
67
|
|
68
|
+
## Decorating associated objects ##
|
69
|
+
|
70
|
+
ActiveDecorator *does not* automatically decorate associated objects. We recommend that you pass associated objects to `render` when decorated associated objects are needed.
|
71
|
+
|
72
|
+
```ruby
|
73
|
+
# app/models/blog_post.rb
|
74
|
+
class BlogPost < ActiveRecord::Base
|
75
|
+
# published_at:datetime
|
76
|
+
end
|
77
|
+
|
78
|
+
# app/models/user.rb
|
79
|
+
class User < ActiveRecord::Base
|
80
|
+
has_many :blog_posts
|
81
|
+
end
|
82
|
+
|
83
|
+
# app/decorators/blog_post_decorator.rb
|
84
|
+
module BlogPostDecorator
|
85
|
+
def published_date
|
86
|
+
published_at.strftime("%Y.%m.%d")
|
87
|
+
end
|
88
|
+
end
|
89
|
+
|
90
|
+
# app/controllers/users_controller.rb
|
91
|
+
class UsersController < ApplicationController
|
92
|
+
def index
|
93
|
+
@users = User.all
|
94
|
+
end
|
95
|
+
end
|
96
|
+
```
|
97
|
+
|
98
|
+
```erb
|
99
|
+
# app/views/users/index.html.erb
|
100
|
+
<% @users.each do |user| %>
|
101
|
+
<%= render partial: "blog_post", locals: { blog_posts: user.blog_posts } %><br>
|
102
|
+
<% end %>
|
103
|
+
|
104
|
+
# app/views/users/_blog_post.html.erb
|
105
|
+
<% blog_posts.each do |blog_post| %>
|
106
|
+
<%= blog_post.published_date %>
|
107
|
+
<% end %>
|
108
|
+
```
|
109
|
+
|
66
110
|
## Configuring the decorator suffix
|
67
111
|
|
68
112
|
By default, ActiveDecorator searches a decorator module named `target_class.name + "Decorator"`
|
@@ -1,20 +1,5 @@
|
|
1
1
|
module ActiveDecorator
|
2
|
-
|
3
|
-
yield @config ||= ActiveDecorator::Configuration.new
|
4
|
-
end
|
2
|
+
include ActiveSupport::Configurable
|
5
3
|
|
6
|
-
|
7
|
-
@config
|
8
|
-
end
|
9
|
-
|
10
|
-
# need a Class for 3.0
|
11
|
-
class Configuration #:nodoc:
|
12
|
-
include ActiveSupport::Configurable
|
13
|
-
|
14
|
-
config_accessor :decorator_suffix
|
15
|
-
end
|
16
|
-
|
17
|
-
configure do |config|
|
18
|
-
config.decorator_suffix = 'Decorator'
|
19
|
-
end
|
4
|
+
config.decorator_suffix = 'Decorator'
|
20
5
|
end
|
@@ -17,15 +17,9 @@ module ActiveDecorator
|
|
17
17
|
obj.each do |r|
|
18
18
|
decorate r
|
19
19
|
end
|
20
|
-
elsif defined?(ActiveRecord) && obj.is_a?(ActiveRecord::Relation) && !obj.
|
21
|
-
|
22
|
-
|
23
|
-
to_a_without_decorator.tap do |arr|
|
24
|
-
ActiveDecorator::Decorator.instance.decorate arr
|
25
|
-
end
|
26
|
-
end
|
27
|
-
alias_method_chain :to_a, :decorator
|
28
|
-
end
|
20
|
+
elsif defined?(ActiveRecord) && obj.is_a?(ActiveRecord::Relation) && !obj.is_a?(ActiveDecorator::RelationDecorator)
|
21
|
+
# don't call each nor to_a immediately
|
22
|
+
obj.extend ActiveDecorator::RelationDecorator
|
29
23
|
else
|
30
24
|
d = decorator_for obj.class
|
31
25
|
return obj unless d
|
@@ -43,10 +37,20 @@ module ActiveDecorator
|
|
43
37
|
d.send :include, ActiveDecorator::Helpers
|
44
38
|
@@decorators[model_class] = d
|
45
39
|
else
|
40
|
+
# Cache nil results
|
46
41
|
@@decorators[model_class] = nil
|
47
42
|
end
|
48
43
|
rescue NameError
|
44
|
+
# Cache nil results
|
49
45
|
@@decorators[model_class] = nil
|
50
46
|
end
|
51
47
|
end
|
48
|
+
|
49
|
+
module RelationDecorator
|
50
|
+
def to_a
|
51
|
+
super.tap do |arr|
|
52
|
+
ActiveDecorator::Decorator.instance.decorate arr
|
53
|
+
end
|
54
|
+
end
|
55
|
+
end
|
52
56
|
end
|
@@ -1,13 +1,15 @@
|
|
1
|
-
module
|
2
|
-
module
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
1
|
+
module ActiveDecorator
|
2
|
+
module Monkey
|
3
|
+
module AbstractController
|
4
|
+
module Rendering
|
5
|
+
def view_assigns
|
6
|
+
hash = super
|
7
|
+
hash.values.each do |v|
|
8
|
+
ActiveDecorator::Decorator.instance.decorate v
|
9
|
+
end
|
10
|
+
hash
|
11
|
+
end
|
7
12
|
end
|
8
|
-
hash
|
9
13
|
end
|
10
|
-
|
11
|
-
alias_method_chain :view_assigns, :decorator
|
12
14
|
end
|
13
15
|
end
|
@@ -1,11 +1,14 @@
|
|
1
|
-
module
|
2
|
-
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
1
|
+
module ActiveDecorator
|
2
|
+
module Monkey
|
3
|
+
module ActionController
|
4
|
+
module Base
|
5
|
+
def rescue_with_handler(*)
|
6
|
+
ActiveDecorator::ViewContext.push(view_context)
|
7
|
+
super
|
8
|
+
ensure
|
9
|
+
ActiveDecorator::ViewContext.pop
|
10
|
+
end
|
11
|
+
end
|
8
12
|
end
|
9
|
-
alias_method_chain :rescue_with_handler, :decorator_view_context
|
10
13
|
end
|
11
14
|
end
|
@@ -1,37 +1,19 @@
|
|
1
1
|
module ActiveDecorator
|
2
|
-
module
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
ActiveDecorator::Decorator.instance.decorate @object unless @object.blank?
|
8
|
-
ActiveDecorator::Decorator.instance.decorate @collection unless @collection.blank?
|
2
|
+
module Monkey
|
3
|
+
module ActionView
|
4
|
+
module PartialRenderer
|
5
|
+
def setup(*)
|
6
|
+
super
|
9
7
|
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
8
|
+
@locals.values.each do |v|
|
9
|
+
ActiveDecorator::Decorator.instance.decorate v
|
10
|
+
end unless @locals.blank?
|
11
|
+
ActiveDecorator::Decorator.instance.decorate @object unless @object.blank?
|
12
|
+
ActiveDecorator::Decorator.instance.decorate @collection unless @collection.blank?
|
14
13
|
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
def setup_with_decorator(context, options, block) #:nodoc:
|
20
|
-
setup_without_decorator context, options, block
|
21
|
-
setup_decorator
|
14
|
+
self
|
15
|
+
end
|
16
|
+
end
|
22
17
|
end
|
23
|
-
|
24
|
-
alias_method_chain :setup, :decorator
|
25
|
-
end
|
26
|
-
else
|
27
|
-
class ActionView::Partials::PartialRenderer
|
28
|
-
include ActiveDecorator::ActionViewExtension
|
29
|
-
|
30
|
-
def setup_with_decorator(options, block) #:nodoc:
|
31
|
-
setup_without_decorator options, block
|
32
|
-
setup_decorator
|
33
|
-
end
|
34
|
-
|
35
|
-
alias_method_chain :setup, :decorator
|
36
18
|
end
|
37
19
|
end
|
@@ -4,17 +4,26 @@ require 'rails'
|
|
4
4
|
module ActiveDecorator
|
5
5
|
class Railtie < ::Rails::Railtie
|
6
6
|
initializer 'active_decorator' do
|
7
|
-
ActiveSupport.on_load
|
7
|
+
ActiveSupport.on_load :action_view do
|
8
8
|
require 'active_decorator/monkey/action_view/partial_renderer'
|
9
|
+
ActionView::PartialRenderer.send :prepend, ActiveDecorator::Monkey::ActionView::PartialRenderer
|
9
10
|
end
|
10
|
-
|
11
|
+
|
12
|
+
ActiveSupport.on_load :action_controller do
|
11
13
|
require 'active_decorator/monkey/abstract_controller/rendering'
|
14
|
+
::ActionController::Base.send :prepend, ActiveDecorator::Monkey::AbstractController::Rendering
|
15
|
+
|
12
16
|
require 'active_decorator/monkey/action_controller/base/rescue_from'
|
17
|
+
ActionController::Base.send :prepend, ActiveDecorator::Monkey::ActionController::Base
|
18
|
+
|
13
19
|
ActionController::Base.send :include, ActiveDecorator::ViewContext::Filter
|
14
20
|
end
|
15
|
-
|
21
|
+
|
22
|
+
ActiveSupport.on_load :action_mailer do
|
23
|
+
require 'active_decorator/monkey/abstract_controller/rendering'
|
24
|
+
ActionMailer::Base.send :prepend, ActiveDecorator::Monkey::AbstractController::Rendering
|
25
|
+
|
16
26
|
if ActionMailer::Base.respond_to? :before_action
|
17
|
-
require 'active_decorator/monkey/abstract_controller/rendering'
|
18
27
|
ActionMailer::Base.send :include, ActiveDecorator::ViewContext::Filter
|
19
28
|
end
|
20
29
|
end
|
data/spec/configuration_spec.rb
CHANGED
data/spec/fake_app/fake_app.rb
CHANGED
@@ -167,28 +167,14 @@ class CreateAllTables < ActiveRecord::Migration
|
|
167
167
|
end
|
168
168
|
|
169
169
|
# Proxy for ActiveRecord::Relation
|
170
|
-
|
171
|
-
|
172
|
-
attr_accessor :ar_relation
|
170
|
+
class RelationProxy < BasicObject
|
171
|
+
attr_accessor :ar_relation
|
173
172
|
|
174
|
-
|
175
|
-
|
176
|
-
end
|
177
|
-
|
178
|
-
def method_missing(method, *args, &block)
|
179
|
-
@ar_relation.public_send(method, *args, &block)
|
180
|
-
end
|
173
|
+
def initialize(ar_relation)
|
174
|
+
@ar_relation = ar_relation
|
181
175
|
end
|
182
|
-
else
|
183
|
-
class RelationProxy < Object
|
184
|
-
attr_accessor :ar_relation
|
185
176
|
|
186
|
-
|
187
|
-
|
188
|
-
end
|
189
|
-
|
190
|
-
def method_missing(method, *args, &block)
|
191
|
-
@ar_relation.send(method, *args, &block)
|
192
|
-
end
|
177
|
+
def method_missing(method, *args, &block)
|
178
|
+
@ar_relation.public_send(method, *args, &block)
|
193
179
|
end
|
194
180
|
end
|
@@ -1,5 +1,3 @@
|
|
1
|
-
require 'spec_helper'
|
2
|
-
|
3
1
|
feature 'decorating controller ivar' do
|
4
2
|
background do
|
5
3
|
@matz = Author.create! :name => 'matz'
|
@@ -7,11 +5,6 @@ feature 'decorating controller ivar' do
|
|
7
5
|
Author.create! :name => 'takahashim'
|
8
6
|
end
|
9
7
|
|
10
|
-
after do
|
11
|
-
Author.delete_all
|
12
|
-
Book.delete_all
|
13
|
-
end
|
14
|
-
|
15
8
|
scenario 'decorating a model object in ivar' do
|
16
9
|
visit "/authors/#{@matz.id}"
|
17
10
|
page.should have_content 'matz'
|
@@ -1,15 +1,9 @@
|
|
1
|
-
require 'spec_helper'
|
2
|
-
|
3
1
|
feature 'decorating partial object in Jbuilder' do
|
4
2
|
background do
|
5
3
|
Author.create! :name => 'aamine'
|
6
4
|
nari = Author.create! :name => 'nari'
|
7
5
|
nari.books.create! :title => 'the gc book'
|
8
6
|
end
|
9
|
-
after do
|
10
|
-
Book.delete_all
|
11
|
-
Author.delete_all
|
12
|
-
end
|
13
7
|
|
14
8
|
scenario 'decorating objects in Jbuilder partials' do
|
15
9
|
visit "/authors/#{Author.last.id}.json"
|
@@ -1,15 +1,9 @@
|
|
1
|
-
require 'spec_helper'
|
2
|
-
|
3
1
|
feature 'decorating partial object' do
|
4
2
|
background do
|
5
3
|
Author.create! :name => 'aamine'
|
6
4
|
nari = Author.create! :name => 'nari'
|
7
5
|
nari.books.create! :title => 'the gc book'
|
8
6
|
end
|
9
|
-
after do
|
10
|
-
Book.delete_all
|
11
|
-
Author.delete_all
|
12
|
-
end
|
13
7
|
|
14
8
|
scenario 'decorating implicit @object' do
|
15
9
|
visit '/authors'
|
data/spec/spec_helper.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: active_decorator
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.6.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Akira Matsuda
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2016-01-04 00:00:00.000000000 Z
|
12
12
|
dependencies: []
|
13
13
|
description: A simple and Rubyish view helper for Rails
|
14
14
|
email:
|
@@ -25,12 +25,11 @@ files:
|
|
25
25
|
- README.md
|
26
26
|
- Rakefile
|
27
27
|
- active_decorator.gemspec
|
28
|
-
- gemfiles/Gemfile-rails.3.0.x
|
29
|
-
- gemfiles/Gemfile-rails.3.1.x
|
30
28
|
- gemfiles/Gemfile-rails.3.2.x
|
31
29
|
- gemfiles/Gemfile-rails.4.0.x
|
32
30
|
- gemfiles/Gemfile-rails.4.1.x
|
33
31
|
- gemfiles/Gemfile-rails.4.2.x
|
32
|
+
- gemfiles/Gemfile-rails.5.0.0.beta1
|
34
33
|
- lib/active_decorator.rb
|
35
34
|
- lib/active_decorator/config.rb
|
36
35
|
- lib/active_decorator/decorator.rb
|
@@ -86,7 +85,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
86
85
|
version: '0'
|
87
86
|
requirements: []
|
88
87
|
rubyforge_project: active_decorator
|
89
|
-
rubygems_version: 2.4.5
|
88
|
+
rubygems_version: 2.4.5.1
|
90
89
|
signing_key:
|
91
90
|
specification_version: 4
|
92
91
|
summary: A simple and Rubyish view helper for Rails
|
@@ -1,16 +0,0 @@
|
|
1
|
-
source 'https://rubygems.org'
|
2
|
-
|
3
|
-
gem 'active_decorator', :path => '..'
|
4
|
-
|
5
|
-
gem 'rails', '~> 3.0.0'
|
6
|
-
gem 'rspec-rails', '~> 2.14.0'
|
7
|
-
gem 'capybara', '~> 2.0.0'
|
8
|
-
# rubyzip >=1 doesn't support ruby 1.8
|
9
|
-
gem 'rubyzip', '< 1.0.0'
|
10
|
-
gem 'sqlite3'
|
11
|
-
gem 'nokogiri', '~> 1.5.0'
|
12
|
-
if RUBY_VERSION <= '1.8.7'
|
13
|
-
gem 'jbuilder', '< 2'
|
14
|
-
else
|
15
|
-
gem 'jbuilder'
|
16
|
-
end
|
@@ -1,19 +0,0 @@
|
|
1
|
-
source 'https://rubygems.org'
|
2
|
-
|
3
|
-
gem 'active_decorator', :path => '..'
|
4
|
-
|
5
|
-
gem 'rails', '~> 3.1.0'
|
6
|
-
gem 'rspec-rails', '~> 2.14.0'
|
7
|
-
if RUBY_VERSION <= '1.8.7'
|
8
|
-
gem 'i18n', '~> 0.6.11'
|
9
|
-
end
|
10
|
-
gem 'capybara', '~> 2.0.0'
|
11
|
-
# rubyzip >=1 doesn't support ruby 1.8
|
12
|
-
gem 'rubyzip', '< 1.0.0'
|
13
|
-
gem 'sqlite3'
|
14
|
-
gem 'nokogiri', '~> 1.5.0'
|
15
|
-
if RUBY_VERSION <= '1.8.7'
|
16
|
-
gem 'jbuilder', '< 2'
|
17
|
-
else
|
18
|
-
gem 'jbuilder'
|
19
|
-
end
|