active_decorator 0.1.0 → 0.2.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.
- data/README.md +6 -1
- data/active_decorator.gemspec +2 -2
- data/lib/active_decorator/decorator.rb +14 -18
- data/lib/{monkey → active_decorator/monkey}/abstract_controller/rendering.rb +1 -1
- data/lib/{monkey → active_decorator/monkey}/action_view/partial_renderer.rb +3 -5
- data/lib/active_decorator/railtie.rb +3 -3
- data/lib/active_decorator/version.rb +1 -1
- metadata +20 -14
data/README.md
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
# ActiveDecorator
|
2
2
|
|
3
|
-
A simple and Rubyish view helper for
|
3
|
+
A simple and Rubyish view helper for Rails 3. Keep your helpers and views Object-Oriented!
|
4
4
|
|
5
5
|
|
6
6
|
## Features ##
|
@@ -17,6 +17,11 @@ A simple and Rubyish view helper for ActiveRecord models. Keep your helpers and
|
|
17
17
|
Rails 3.0.x, 3.1.x, and 3.2 (edge)
|
18
18
|
|
19
19
|
|
20
|
+
## Supported ORMs ##
|
21
|
+
|
22
|
+
ActiveRecord, ActiveResource, and any kind of ORMs that uses Ruby Objects as model objects
|
23
|
+
|
24
|
+
|
20
25
|
## Usage ##
|
21
26
|
|
22
27
|
1. bundle 'active_decorator' gem
|
data/active_decorator.gemspec
CHANGED
@@ -8,8 +8,8 @@ Gem::Specification.new do |s|
|
|
8
8
|
s.authors = ["Akira Matsuda"]
|
9
9
|
s.email = ["ronnie@dio.jp"]
|
10
10
|
s.homepage = ""
|
11
|
-
s.summary = %q{A simple and Rubyish view helper for
|
12
|
-
s.description = %q{A simple and Rubyish view helper for
|
11
|
+
s.summary = %q{A simple and Rubyish view helper for Rails 3}
|
12
|
+
s.description = %q{A simple and Rubyish view helper for Rails 3}
|
13
13
|
|
14
14
|
s.rubyforge_project = "active_decorator"
|
15
15
|
|
@@ -9,33 +9,29 @@ module ActiveDecorator
|
|
9
9
|
@@decorators = {}
|
10
10
|
end
|
11
11
|
|
12
|
-
def
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
12
|
+
def decorate(obj)
|
13
|
+
return if obj.nil?
|
14
|
+
|
15
|
+
if obj.is_a? Array
|
16
|
+
obj.each do |r|
|
17
|
+
decorate r
|
18
|
+
end
|
19
|
+
elsif defined?(ActiveRecord) && obj.is_a?(ActiveRecord::Relation)
|
17
20
|
class << obj
|
18
21
|
def to_a_with_decorator
|
19
|
-
|
20
|
-
|
21
|
-
ActiveDecorator::Decorator.instance.decorate model
|
22
|
+
to_a_without_decorator.tap do |arr|
|
23
|
+
ActiveDecorator::Decorator.instance.decorate arr
|
22
24
|
end
|
23
25
|
end
|
24
26
|
alias_method_chain :to_a, :decorator
|
25
27
|
end
|
26
|
-
|
27
|
-
obj.
|
28
|
-
|
29
|
-
|
28
|
+
else
|
29
|
+
d = decorator_for obj.class
|
30
|
+
return obj unless d
|
31
|
+
obj.extend d unless obj.is_a? d
|
30
32
|
end
|
31
33
|
end
|
32
34
|
|
33
|
-
def decorate(model)
|
34
|
-
d = decorator_for model.class
|
35
|
-
return model unless d
|
36
|
-
model.extend d unless model.is_a? d
|
37
|
-
end
|
38
|
-
|
39
35
|
private
|
40
36
|
def decorator_for(model_class)
|
41
37
|
return @@decorators[model_class] if @@decorators.has_key? model_class
|
@@ -4,12 +4,10 @@ module ActionView
|
|
4
4
|
setup_without_decorator context, options, block
|
5
5
|
|
6
6
|
@locals.values.each do |v|
|
7
|
-
ActiveDecorator::Decorator.instance.
|
7
|
+
ActiveDecorator::Decorator.instance.decorate v
|
8
8
|
end if @locals.present?
|
9
|
-
ActiveDecorator::Decorator.instance.
|
10
|
-
@collection
|
11
|
-
ActiveDecorator::Decorator.instance.decorate_if_model v
|
12
|
-
end if @collection.present?
|
9
|
+
ActiveDecorator::Decorator.instance.decorate @object if @object.present?
|
10
|
+
ActiveDecorator::Decorator.instance.decorate @collection if @collection.present?
|
13
11
|
|
14
12
|
self
|
15
13
|
end
|
@@ -4,13 +4,13 @@ module ActiveDecorator
|
|
4
4
|
class Railtie < ::Rails::Railtie
|
5
5
|
initializer 'active_decorator' do
|
6
6
|
ActiveSupport.on_load(:action_view) do
|
7
|
-
require 'monkey/action_view/partial_renderer'
|
7
|
+
require 'active_decorator/monkey/action_view/partial_renderer'
|
8
8
|
end
|
9
9
|
ActiveSupport.on_load(:action_controller) do
|
10
|
-
require 'monkey/abstract_controller/rendering'
|
10
|
+
require 'active_decorator/monkey/abstract_controller/rendering'
|
11
11
|
end
|
12
12
|
ActiveSupport.on_load(:action_mailer) do
|
13
|
-
require 'monkey/abstract_controller/rendering'
|
13
|
+
require 'active_decorator/monkey/abstract_controller/rendering'
|
14
14
|
end
|
15
15
|
end
|
16
16
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: active_decorator
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.2.0
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,11 +9,11 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2011-12-
|
12
|
+
date: 2011-12-20 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: rails
|
16
|
-
requirement: &
|
16
|
+
requirement: &70315505555960 !ruby/object:Gem::Requirement
|
17
17
|
none: false
|
18
18
|
requirements:
|
19
19
|
- - ! '>='
|
@@ -21,10 +21,10 @@ dependencies:
|
|
21
21
|
version: '0'
|
22
22
|
type: :development
|
23
23
|
prerelease: false
|
24
|
-
version_requirements: *
|
24
|
+
version_requirements: *70315505555960
|
25
25
|
- !ruby/object:Gem::Dependency
|
26
26
|
name: rspec-rails
|
27
|
-
requirement: &
|
27
|
+
requirement: &70315505555540 !ruby/object:Gem::Requirement
|
28
28
|
none: false
|
29
29
|
requirements:
|
30
30
|
- - ! '>='
|
@@ -32,10 +32,10 @@ dependencies:
|
|
32
32
|
version: '0'
|
33
33
|
type: :development
|
34
34
|
prerelease: false
|
35
|
-
version_requirements: *
|
35
|
+
version_requirements: *70315505555540
|
36
36
|
- !ruby/object:Gem::Dependency
|
37
37
|
name: capybara
|
38
|
-
requirement: &
|
38
|
+
requirement: &70315505555120 !ruby/object:Gem::Requirement
|
39
39
|
none: false
|
40
40
|
requirements:
|
41
41
|
- - ! '>='
|
@@ -43,10 +43,10 @@ dependencies:
|
|
43
43
|
version: '0'
|
44
44
|
type: :development
|
45
45
|
prerelease: false
|
46
|
-
version_requirements: *
|
46
|
+
version_requirements: *70315505555120
|
47
47
|
- !ruby/object:Gem::Dependency
|
48
48
|
name: sqlite3
|
49
|
-
requirement: &
|
49
|
+
requirement: &70315505554700 !ruby/object:Gem::Requirement
|
50
50
|
none: false
|
51
51
|
requirements:
|
52
52
|
- - ! '>='
|
@@ -54,8 +54,8 @@ dependencies:
|
|
54
54
|
version: '0'
|
55
55
|
type: :development
|
56
56
|
prerelease: false
|
57
|
-
version_requirements: *
|
58
|
-
description: A simple and Rubyish view helper for
|
57
|
+
version_requirements: *70315505554700
|
58
|
+
description: A simple and Rubyish view helper for Rails 3
|
59
59
|
email:
|
60
60
|
- ronnie@dio.jp
|
61
61
|
executables: []
|
@@ -73,6 +73,8 @@ files:
|
|
73
73
|
- lib/active_decorator.rb
|
74
74
|
- lib/active_decorator/decorator.rb
|
75
75
|
- lib/active_decorator/helpers.rb
|
76
|
+
- lib/active_decorator/monkey/abstract_controller/rendering.rb
|
77
|
+
- lib/active_decorator/monkey/action_view/partial_renderer.rb
|
76
78
|
- lib/active_decorator/railtie.rb
|
77
79
|
- lib/active_decorator/version.rb
|
78
80
|
- lib/generators/rails/decorator_generator.rb
|
@@ -81,8 +83,6 @@ files:
|
|
81
83
|
- lib/generators/rspec/templates/decorator_spec.rb
|
82
84
|
- lib/generators/test_unit/decorator_generator.rb
|
83
85
|
- lib/generators/test_unit/templates/decorator_test.rb
|
84
|
-
- lib/monkey/abstract_controller/rendering.rb
|
85
|
-
- lib/monkey/action_view/partial_renderer.rb
|
86
86
|
- spec/fake_app/authors/index.html.erb
|
87
87
|
- spec/fake_app/authors/show.html.erb
|
88
88
|
- spec/fake_app/books/_book.html.erb
|
@@ -105,18 +105,24 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
105
105
|
- - ! '>='
|
106
106
|
- !ruby/object:Gem::Version
|
107
107
|
version: '0'
|
108
|
+
segments:
|
109
|
+
- 0
|
110
|
+
hash: 965343407426954688
|
108
111
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
109
112
|
none: false
|
110
113
|
requirements:
|
111
114
|
- - ! '>='
|
112
115
|
- !ruby/object:Gem::Version
|
113
116
|
version: '0'
|
117
|
+
segments:
|
118
|
+
- 0
|
119
|
+
hash: 965343407426954688
|
114
120
|
requirements: []
|
115
121
|
rubyforge_project: active_decorator
|
116
122
|
rubygems_version: 1.8.10
|
117
123
|
signing_key:
|
118
124
|
specification_version: 3
|
119
|
-
summary: A simple and Rubyish view helper for
|
125
|
+
summary: A simple and Rubyish view helper for Rails 3
|
120
126
|
test_files:
|
121
127
|
- spec/fake_app/authors/index.html.erb
|
122
128
|
- spec/fake_app/authors/show.html.erb
|