draper 0.9.3 → 0.9.5
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/.rspec +1 -0
- data/Readme.markdown +35 -9
- data/draper.gemspec +3 -4
- data/lib/draper.rb +1 -0
- data/lib/draper/base.rb +18 -2
- data/lib/draper/decorated_enumerable_proxy.rb +12 -6
- data/lib/draper/helper_support.rb +5 -0
- data/lib/draper/model_support.rb +13 -0
- data/lib/draper/system.rb +5 -3
- data/lib/draper/version.rb +1 -1
- data/lib/draper/view_context.rb +14 -4
- data/spec/{base_spec.rb → draper/base_spec.rb} +83 -19
- data/spec/draper/helper_support_spec.rb +18 -0
- data/spec/draper/model_support_spec.rb +14 -0
- data/spec/{view_context_spec.rb → draper/view_context_spec.rb} +2 -13
- data/spec/spec_helper.rb +2 -4
- data/spec/{samples → support/samples}/active_record.rb +5 -0
- data/spec/{samples → support/samples}/application_controller.rb +15 -1
- data/spec/{samples → support/samples}/application_helper.rb +0 -0
- data/spec/{samples → support/samples}/decorator.rb +0 -0
- data/spec/{samples → support/samples}/decorator_with_allows.rb +0 -0
- data/spec/{samples → support/samples}/decorator_with_application_helper.rb +0 -0
- data/spec/{samples → support/samples}/decorator_with_denies.rb +0 -0
- data/spec/{samples → support/samples}/product.rb +23 -1
- data/spec/{samples → support/samples}/product_decorator.rb +0 -0
- metadata +42 -28
data/.rspec
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
--color
|
data/Readme.markdown
CHANGED
@@ -20,17 +20,28 @@
|
|
20
20
|
6. Output the instance methods in your view templates
|
21
21
|
ex: `@article_decorator.created_at`
|
22
22
|
|
23
|
-
##
|
23
|
+
## Watch the RailsCast
|
24
|
+
|
25
|
+
Ryan Bates has put together an excellent RailsCast on Draper based on the 0.8.0 release:
|
26
|
+
|
27
|
+
[](http://railscasts.com/episodes/286-draper)
|
24
28
|
|
25
|
-
|
29
|
+
## What's New
|
26
30
|
|
27
|
-
|
28
|
-
|
29
|
-
*
|
30
|
-
*
|
31
|
-
*
|
32
|
-
*
|
33
|
-
*
|
31
|
+
### Version 0.9.X
|
32
|
+
|
33
|
+
* `.5`: Render the `decorate` helper, passing a source object and a block in a view template to auto-decorate and render the block (ISSUE: see https://github.com/jcasimir/draper/issues/32)
|
34
|
+
* `.5`: `ArticleDecorator.first` and `ArticleDecorator.last` will return decorated instances as you'd expect
|
35
|
+
* `.5`: Calling `ArticleDecorator.all` will now return a `DecoratedEnumerableProxy` of the objects from `Article.all`
|
36
|
+
* `.5`: More love for `DecoratedEnumerableProxy` including better use of `respond_to`, `include?`, and overriding `.all` to return a
|
37
|
+
* `.4`: Improved the collection proxy's `respond_to` and `to_ary` to play nicely with Rails' `render`
|
38
|
+
* `.3`: Helpers are available from the decorator class level, so you could write a `ArticleDecorator.new_article_link` that uses `h.link_to`
|
39
|
+
* `.2`: Automatically generate a named accessor for the wrapped object, so now inside of `ArticleDecorator` you can use `article` instead of just `model`
|
40
|
+
* `.2`: Automatically generate RSpec/Test::Unit stub for decorator class
|
41
|
+
* `.1`: Removed the `lazy_helpers` method to favor using `include Draper::LazyHelpers`
|
42
|
+
* `.1`: Refactored how methods are selected for delegation to the wrapped model
|
43
|
+
* `.0`: Fixed how the view context is stored to resolve cross-request issues
|
44
|
+
* `.0`: Decorated collections now return a collection proxy instead of an array, which fixes many compatibility issues
|
34
45
|
|
35
46
|
## Goals
|
36
47
|
|
@@ -222,6 +233,21 @@ Use the new methods in your views like any other model method (ex: `@article.pub
|
|
222
233
|
<h1><%= @article.title %> <%= @article.published_at %></h1>
|
223
234
|
```
|
224
235
|
|
236
|
+
### Using in Mailers
|
237
|
+
|
238
|
+
To use decorators in mailers that use helpers, you have to call `set_current_view_context` in your
|
239
|
+
mailer method:
|
240
|
+
|
241
|
+
```ruby
|
242
|
+
class ActicleMailer < ActionMailer::Base
|
243
|
+
def new_article(article)
|
244
|
+
set_current_view_context
|
245
|
+
@article_decorator = ArticleDecorator.decorate(article)
|
246
|
+
mail(:to => 'come@me.bro', :subject => "New Article: #{@article_decorator.title}")
|
247
|
+
end
|
248
|
+
end
|
249
|
+
```
|
250
|
+
|
225
251
|
## Possible Decoration Methods
|
226
252
|
|
227
253
|
Here are some ideas of what you might do in decorator methods:
|
data/draper.gemspec
CHANGED
@@ -8,13 +8,12 @@ Gem::Specification.new do |s|
|
|
8
8
|
s.authors = ["Jeff Casimir"]
|
9
9
|
s.email = ["jeff@casimircreative.com"]
|
10
10
|
s.homepage = "http://github.com/jcasimir/draper"
|
11
|
-
s.summary = "Decorator pattern
|
12
|
-
s.description = "Draper
|
13
|
-
|
11
|
+
s.summary = "Decorator pattern implementation for Rails."
|
12
|
+
s.description = "Draper implements a decorator or presenter pattern for Rails applications."
|
14
13
|
s.rubyforge_project = "draper"
|
15
|
-
|
16
14
|
s.files = `git ls-files`.split("\n")
|
17
15
|
s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
|
18
16
|
s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
|
19
17
|
s.require_paths = ["lib"]
|
18
|
+
s.add_dependency('activesupport', '>= 2.3.10')
|
20
19
|
end
|
data/lib/draper.rb
CHANGED
data/lib/draper/base.rb
CHANGED
@@ -95,6 +95,22 @@ module Draper
|
|
95
95
|
def self.decorate(input, context = {})
|
96
96
|
input.respond_to?(:each) ? Draper::DecoratedEnumerableProxy.new(input, self, context) : new(input, context)
|
97
97
|
end
|
98
|
+
|
99
|
+
# Fetch all instances of the decorated class and decorate them.
|
100
|
+
#
|
101
|
+
# @param [Object] context (optional)
|
102
|
+
# @return [Draper::DecoratedEnumerableProxy]
|
103
|
+
def self.all(context = {})
|
104
|
+
Draper::DecoratedEnumerableProxy.new(model_class.all, self, context)
|
105
|
+
end
|
106
|
+
|
107
|
+
def self.first(context = {})
|
108
|
+
decorate(model_class.first, context)
|
109
|
+
end
|
110
|
+
|
111
|
+
def self.last(context = {})
|
112
|
+
decorate(model_class.last, context)
|
113
|
+
end
|
98
114
|
|
99
115
|
# Access the helpers proxy to call built-in and user-defined
|
100
116
|
# Rails helpers. Aliased to `.h` for convinience.
|
@@ -111,7 +127,7 @@ module Draper
|
|
111
127
|
# @return [Object] proxy
|
112
128
|
class << self
|
113
129
|
def helpers
|
114
|
-
|
130
|
+
Draper::ViewContext.current
|
115
131
|
end
|
116
132
|
alias :h :helpers
|
117
133
|
end
|
@@ -127,7 +143,7 @@ module Draper
|
|
127
143
|
#
|
128
144
|
# @return [Boolean] true if other's model == self's model
|
129
145
|
def ==(other)
|
130
|
-
@model == other.model
|
146
|
+
@model == (other.respond_to?(:model) ? other.model : other)
|
131
147
|
end
|
132
148
|
|
133
149
|
def respond_to?(method, include_private = false)
|
@@ -6,22 +6,28 @@ module Draper
|
|
6
6
|
@wrapped_collection, @klass, @context = collection, klass, context
|
7
7
|
end
|
8
8
|
|
9
|
-
# Implementation of Enumerable#each that proxyes to the wrapped collection
|
10
9
|
def each(&block)
|
11
10
|
@wrapped_collection.each { |member| block.call(@klass.new(member, @context)) }
|
12
11
|
end
|
13
12
|
|
14
|
-
# Implement to_arry so that render @decorated_collection is happy
|
15
13
|
def to_ary
|
16
|
-
@wrapped_collection.
|
14
|
+
@wrapped_collection.map { |member| @klass.new(member, @context) }
|
17
15
|
end
|
18
16
|
|
19
|
-
def method_missing (
|
20
|
-
@wrapped_collection.send(
|
17
|
+
def method_missing (method, *args, &block)
|
18
|
+
@wrapped_collection.send(method, *args, &block)
|
19
|
+
end
|
20
|
+
|
21
|
+
def respond_to?(method)
|
22
|
+
super || @wrapped_collection.respond_to?(method)
|
23
|
+
end
|
24
|
+
|
25
|
+
def ==(other)
|
26
|
+
@wrapped_collection == other
|
21
27
|
end
|
22
28
|
|
23
29
|
def to_s
|
24
30
|
"#<DecoratedEnumerableProxy of #{@klass} for #{@wrapped_collection.inspect}>"
|
25
31
|
end
|
26
32
|
end
|
27
|
-
end
|
33
|
+
end
|
data/lib/draper/model_support.rb
CHANGED
@@ -3,4 +3,17 @@ module Draper::ModelSupport
|
|
3
3
|
@decorator ||= "#{self.class.name}Decorator".constantize.decorate(self)
|
4
4
|
block_given? ? yield(@decorator) : @decorator
|
5
5
|
end
|
6
|
+
|
7
|
+
alias :decorate :decorator
|
8
|
+
|
9
|
+
module ClassMethods
|
10
|
+
def decorate(context = {})
|
11
|
+
@decorator_proxy ||= "#{model_name}Decorator".constantize.decorate(self.scoped)
|
12
|
+
block_given? ? yield(@decorator_proxy) : @decorator_proxy
|
13
|
+
end
|
14
|
+
end
|
15
|
+
|
16
|
+
def self.included(base)
|
17
|
+
base.extend(ClassMethods)
|
18
|
+
end
|
6
19
|
end
|
data/lib/draper/system.rb
CHANGED
@@ -1,7 +1,9 @@
|
|
1
1
|
module Draper
|
2
|
-
class System
|
2
|
+
class System
|
3
3
|
def self.setup
|
4
|
-
ActionController::Base.send(:include, Draper::
|
4
|
+
ActionController::Base.send(:include, Draper::ViewContextFilter) if defined?(ActionController::Base)
|
5
|
+
ActionMailer::Base.send(:include, Draper::ViewContextFilter) if defined?(ActionMailer::Base)
|
6
|
+
ActionController::Base.send(:helper, Draper::HelperSupport) if defined?(ActionController::Base)
|
5
7
|
end
|
6
8
|
end
|
7
|
-
end
|
9
|
+
end
|
data/lib/draper/version.rb
CHANGED
data/lib/draper/view_context.rb
CHANGED
@@ -1,11 +1,21 @@
|
|
1
1
|
module Draper
|
2
2
|
module ViewContext
|
3
|
+
def self.current
|
4
|
+
Thread.current[:current_view_context]
|
5
|
+
end
|
6
|
+
|
7
|
+
def self.current=(input)
|
8
|
+
Thread.current[:current_view_context] = input
|
9
|
+
end
|
10
|
+
end
|
11
|
+
|
12
|
+
module ViewContextFilter
|
3
13
|
def set_current_view_context
|
4
|
-
|
14
|
+
Draper::ViewContext.current = self.view_context
|
5
15
|
end
|
6
|
-
|
16
|
+
|
7
17
|
def self.included(source)
|
8
|
-
source.send(:before_filter, :set_current_view_context)
|
18
|
+
source.send(:before_filter, :set_current_view_context) if source.respond_to?(:before_filter)
|
9
19
|
end
|
10
20
|
end
|
11
|
-
end
|
21
|
+
end
|
@@ -1,5 +1,4 @@
|
|
1
1
|
require 'spec_helper'
|
2
|
-
require 'draper'
|
3
2
|
|
4
3
|
describe Draper::Base do
|
5
4
|
before(:each){ ApplicationController.new.set_current_view_context }
|
@@ -10,11 +9,11 @@ describe Draper::Base do
|
|
10
9
|
it "should pass missing class method calls on to the wrapped class" do
|
11
10
|
subject.class.sample_class_method.should == "sample class method"
|
12
11
|
end
|
13
|
-
|
12
|
+
|
14
13
|
it "should respond_to a wrapped class method" do
|
15
14
|
subject.class.should respond_to(:sample_class_method)
|
16
15
|
end
|
17
|
-
|
16
|
+
|
18
17
|
it "should still respond_to it's own class methods" do
|
19
18
|
subject.class.should respond_to(:own_class_method)
|
20
19
|
end
|
@@ -24,17 +23,17 @@ describe Draper::Base do
|
|
24
23
|
it "should have a valid view_context" do
|
25
24
|
subject.helpers.should be
|
26
25
|
end
|
27
|
-
|
26
|
+
|
28
27
|
it "should be aliased to .h" do
|
29
28
|
subject.h.should == subject.helpers
|
30
|
-
end
|
29
|
+
end
|
31
30
|
end
|
32
|
-
|
31
|
+
|
33
32
|
context("#helpers") do
|
34
33
|
it "should have a valid view_context" do
|
35
34
|
Decorator.helpers.should be
|
36
35
|
end
|
37
|
-
|
36
|
+
|
38
37
|
it "should be aliased to #h" do
|
39
38
|
Decorator.h.should == Decorator.helpers
|
40
39
|
end
|
@@ -44,7 +43,7 @@ describe Draper::Base do
|
|
44
43
|
it "sets the model class for the decorator" do
|
45
44
|
ProductDecorator.new(source).model_class.should == Product
|
46
45
|
end
|
47
|
-
|
46
|
+
|
48
47
|
it "should handle plural-like words properly'" do
|
49
48
|
class Business; end
|
50
49
|
expect do
|
@@ -54,7 +53,7 @@ describe Draper::Base do
|
|
54
53
|
BusinessDecorator.model_class.should == Business
|
55
54
|
end.should_not raise_error
|
56
55
|
end
|
57
|
-
|
56
|
+
|
58
57
|
it "creates a named accessor for the wrapped model" do
|
59
58
|
pd = ProductDecorator.new(source)
|
60
59
|
pd.send(:product).should == source
|
@@ -71,7 +70,7 @@ describe Draper::Base do
|
|
71
70
|
context("selecting methods") do
|
72
71
|
it "echos the methods of the wrapped class except default exclusions" do
|
73
72
|
source.methods.each do |method|
|
74
|
-
unless Draper::Base::DEFAULT_DENIED.include?(method)
|
73
|
+
unless Draper::Base::DEFAULT_DENIED.include?(method)
|
75
74
|
subject.should respond_to(method.to_sym)
|
76
75
|
end
|
77
76
|
end
|
@@ -120,7 +119,7 @@ describe Draper::Base do
|
|
120
119
|
pd.should be_instance_of(ProductDecorator)
|
121
120
|
pd.model.should be_instance_of(Product)
|
122
121
|
end
|
123
|
-
|
122
|
+
|
124
123
|
it "should accept and store a context" do
|
125
124
|
pd = ProductDecorator.find(1, :admin)
|
126
125
|
pd.context.should == :admin
|
@@ -176,18 +175,37 @@ describe Draper::Base do
|
|
176
175
|
subject.should == other
|
177
176
|
end
|
178
177
|
end
|
178
|
+
|
179
|
+
context 'position accessors' do
|
180
|
+
[:first, :last].each do |method|
|
181
|
+
context "##{method}" do
|
182
|
+
it "should return a decorated instance" do
|
183
|
+
ProductDecorator.send(method).should be_instance_of ProductDecorator
|
184
|
+
end
|
185
|
+
|
186
|
+
it "should return the #{method} instance of the wrapped class" do
|
187
|
+
ProductDecorator.send(method).model.should == Product.send(method)
|
188
|
+
end
|
189
|
+
|
190
|
+
it "should accept an optional context" do
|
191
|
+
ProductDecorator.send(method, :admin).context.should == :admin
|
192
|
+
end
|
193
|
+
end
|
194
|
+
end
|
195
|
+
end
|
179
196
|
|
180
197
|
describe "collection decoration" do
|
181
|
-
|
198
|
+
|
182
199
|
# Implementation of #decorate that returns an array
|
183
|
-
# of decorated objects is insufficient to deal with
|
184
|
-
# situations where the original collection has been
|
200
|
+
# of decorated objects is insufficient to deal with
|
201
|
+
# situations where the original collection has been
|
185
202
|
# expanded with the use of modules (as often the case
|
186
|
-
# with paginator gems) or is just more complex then
|
187
|
-
# an array.
|
203
|
+
# with paginator gems) or is just more complex then
|
204
|
+
# an array.
|
188
205
|
module Paginator; def page_number; "magic_value"; end; end
|
189
206
|
Array.send(:include, Paginator)
|
190
207
|
let(:paged_array) { [Product.new, Product.new] }
|
208
|
+
let(:empty_collection) { [] }
|
191
209
|
subject { ProductDecorator.decorate(paged_array) }
|
192
210
|
|
193
211
|
it "should proxy all calls to decorated collection" do
|
@@ -196,10 +214,56 @@ describe Draper::Base do
|
|
196
214
|
end
|
197
215
|
|
198
216
|
it "should support Rails partial lookup for a collection" do
|
199
|
-
# to support Rails render @collection the returned collection
|
200
|
-
# (or its proxy) should implement #to_ary.
|
217
|
+
# to support Rails render @collection the returned collection
|
218
|
+
# (or its proxy) should implement #to_ary.
|
201
219
|
subject.respond_to?(:to_ary).should be true
|
202
|
-
subject.
|
220
|
+
subject.to_ary.first.should == ProductDecorator.decorate(paged_array.first)
|
221
|
+
end
|
222
|
+
|
223
|
+
it "should delegate respond_to? to the wrapped collection" do
|
224
|
+
decorator = ProductDecorator.decorate(paged_array)
|
225
|
+
paged_array.should_receive(:respond_to?).with(:whatever)
|
226
|
+
decorator.respond_to?(:whatever)
|
227
|
+
end
|
228
|
+
|
229
|
+
it "should return blank for a decorated empty collection" do
|
230
|
+
# This tests that respond_to? is defined for the DecoratedEnumerableProxy
|
231
|
+
# since activesupport calls respond_to?(:empty) in #blank
|
232
|
+
decorator = ProductDecorator.decorate(empty_collection)
|
233
|
+
decorator.should be_blank
|
234
|
+
end
|
235
|
+
|
236
|
+
it "should return whether the member is in the array for a decorated wrapped collection" do
|
237
|
+
# This tests that include? is defined for the DecoratedEnumerableProxy
|
238
|
+
member = paged_array.first
|
239
|
+
subject.respond_to?(:include?)
|
240
|
+
subject.include?(member).should == true
|
241
|
+
subject.include?(subject.first).should == true
|
242
|
+
subject.include?(Product.new).should == false
|
243
|
+
end
|
244
|
+
|
245
|
+
it "should equal each other when decorating the same collection" do
|
246
|
+
subject_one = ProductDecorator.decorate(paged_array)
|
247
|
+
subject_two = ProductDecorator.decorate(paged_array)
|
248
|
+
subject_one.should == subject_two
|
249
|
+
end
|
250
|
+
|
251
|
+
it "should not equal each other when decorating different collections" do
|
252
|
+
subject_one = ProductDecorator.decorate(paged_array)
|
253
|
+
new_paged_array = paged_array + [Product.new]
|
254
|
+
subject_two = ProductDecorator.decorate(new_paged_array)
|
255
|
+
subject_one.should_not == subject_two
|
256
|
+
end
|
257
|
+
|
258
|
+
context '#all' do
|
259
|
+
it "should return a decorated collection" do
|
260
|
+
ProductDecorator.all.first.should be_instance_of ProductDecorator
|
261
|
+
end
|
262
|
+
|
263
|
+
it "should accept a context" do
|
264
|
+
collection = ProductDecorator.all(:admin)
|
265
|
+
collection.first.context.should == :admin
|
266
|
+
end
|
203
267
|
end
|
204
268
|
end
|
205
269
|
|
@@ -0,0 +1,18 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe Draper::HelperSupport do
|
4
|
+
before(:each){ @product = Product.new}
|
5
|
+
|
6
|
+
context '#decorate' do
|
7
|
+
it 'renders a block' do
|
8
|
+
output = ApplicationController.decorate(@product){|p| p.model.object_id }
|
9
|
+
output.should == @product.object_id
|
10
|
+
end
|
11
|
+
|
12
|
+
it 'uses #capture so Rails only renders the content once' do
|
13
|
+
ApplicationController.decorate(@product){|p| p.model.object_id }
|
14
|
+
ApplicationController.capture_triggered.should be
|
15
|
+
end
|
16
|
+
end
|
17
|
+
|
18
|
+
end
|
@@ -11,5 +11,19 @@ describe Draper::ModelSupport do
|
|
11
11
|
a = Product.new.decorator { |d| d.awesome_title }
|
12
12
|
a.should eql "Awesome Title"
|
13
13
|
end
|
14
|
+
|
15
|
+
it 'should be aliased to .decorate' do
|
16
|
+
subject.decorator.model.should == subject.decorate.model
|
17
|
+
end
|
18
|
+
end
|
19
|
+
|
20
|
+
describe '#decorate - decorate collections of AR objects' do
|
21
|
+
subject { Product.limit }
|
22
|
+
its(:decorate) { should be_kind_of(Draper::DecoratedEnumerableProxy) }
|
23
|
+
|
24
|
+
it "should decorate the collection" do
|
25
|
+
subject.decorate.size.should == 1
|
26
|
+
subject.decorate.to_ary[0].model.should be_a(Product)
|
27
|
+
end
|
14
28
|
end
|
15
29
|
end
|
@@ -1,5 +1,4 @@
|
|
1
1
|
require 'spec_helper'
|
2
|
-
require 'draper'
|
3
2
|
|
4
3
|
describe Draper::ViewContext do
|
5
4
|
let (:app_controller) do
|
@@ -19,17 +18,7 @@ describe Draper::ViewContext do
|
|
19
18
|
end
|
20
19
|
|
21
20
|
it "raises an exception if the view_context is fetched without being set" do
|
22
|
-
|
21
|
+
Draper::ViewContext.current = nil
|
23
22
|
expect {app_controller.current_view_context}.should raise_exception(Exception)
|
24
23
|
end
|
25
|
-
|
26
|
-
it "sets view_context every time" do
|
27
|
-
app_controller_instance.stub(:view_context) { 'first' }
|
28
|
-
app_controller_instance.set_current_view_context
|
29
|
-
Thread.current[:current_view_context].should == 'first'
|
30
|
-
|
31
|
-
app_controller_instance.stub(:view_context) { 'second' }
|
32
|
-
app_controller_instance.set_current_view_context
|
33
|
-
Thread.current[:current_view_context].should == 'second'
|
34
|
-
end
|
35
|
-
end
|
24
|
+
end
|
data/spec/spec_helper.rb
CHANGED
@@ -1,3 +1,5 @@
|
|
1
|
+
require './spec/support/samples/application_helper'
|
2
|
+
|
1
3
|
module ActionController
|
2
4
|
class Base
|
3
5
|
@@before_filters = []
|
@@ -7,6 +9,9 @@ module ActionController
|
|
7
9
|
def self.before_filter(name)
|
8
10
|
@@before_filters << name
|
9
11
|
end
|
12
|
+
def self.helper(mod)
|
13
|
+
extend mod
|
14
|
+
end
|
10
15
|
end
|
11
16
|
end
|
12
17
|
|
@@ -27,6 +32,15 @@ class ApplicationController < ActionController::Base
|
|
27
32
|
def self.hello
|
28
33
|
"Hello!"
|
29
34
|
end
|
35
|
+
|
36
|
+
def self.capture(&block)
|
37
|
+
@@capture = true
|
38
|
+
block.call
|
39
|
+
end
|
40
|
+
|
41
|
+
def self.capture_triggered
|
42
|
+
@@capture ||= false
|
43
|
+
end
|
30
44
|
end
|
31
45
|
|
32
|
-
Draper::System.setup
|
46
|
+
Draper::System.setup
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
@@ -1,4 +1,26 @@
|
|
1
1
|
class Product < ActiveRecord::Base
|
2
|
+
include Draper::ModelSupport
|
3
|
+
|
4
|
+
def self.first
|
5
|
+
@@first ||= Product.new
|
6
|
+
end
|
7
|
+
|
8
|
+
def self.last
|
9
|
+
@@last ||= Product.new
|
10
|
+
end
|
11
|
+
|
12
|
+
def self.all
|
13
|
+
[Product.new, Product.new]
|
14
|
+
end
|
15
|
+
|
16
|
+
def self.scoped
|
17
|
+
[Product.new]
|
18
|
+
end
|
19
|
+
|
20
|
+
def self.model_name
|
21
|
+
"Product"
|
22
|
+
end
|
23
|
+
|
2
24
|
def self.find(id)
|
3
25
|
return Product.new
|
4
26
|
end
|
@@ -22,4 +44,4 @@ class Product < ActiveRecord::Base
|
|
22
44
|
def block
|
23
45
|
yield
|
24
46
|
end
|
25
|
-
end
|
47
|
+
end
|
File without changes
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: draper
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.9.
|
4
|
+
version: 0.9.5
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,10 +9,20 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2011-10-
|
13
|
-
dependencies:
|
14
|
-
|
15
|
-
|
12
|
+
date: 2011-10-29 00:00:00.000000000Z
|
13
|
+
dependencies:
|
14
|
+
- !ruby/object:Gem::Dependency
|
15
|
+
name: activesupport
|
16
|
+
requirement: &70218782393040 !ruby/object:Gem::Requirement
|
17
|
+
none: false
|
18
|
+
requirements:
|
19
|
+
- - ! '>='
|
20
|
+
- !ruby/object:Gem::Version
|
21
|
+
version: 2.3.10
|
22
|
+
type: :runtime
|
23
|
+
prerelease: false
|
24
|
+
version_requirements: *70218782393040
|
25
|
+
description: Draper implements a decorator or presenter pattern for Rails applications.
|
16
26
|
email:
|
17
27
|
- jeff@casimircreative.com
|
18
28
|
executables: []
|
@@ -20,6 +30,7 @@ extensions: []
|
|
20
30
|
extra_rdoc_files: []
|
21
31
|
files:
|
22
32
|
- .gitignore
|
33
|
+
- .rspec
|
23
34
|
- .travis.yml
|
24
35
|
- .yardopts
|
25
36
|
- Gemfile
|
@@ -51,6 +62,7 @@ files:
|
|
51
62
|
- lib/draper.rb
|
52
63
|
- lib/draper/base.rb
|
53
64
|
- lib/draper/decorated_enumerable_proxy.rb
|
65
|
+
- lib/draper/helper_support.rb
|
54
66
|
- lib/draper/lazy_helpers.rb
|
55
67
|
- lib/draper/model_support.rb
|
56
68
|
- lib/draper/system.rb
|
@@ -67,22 +79,23 @@ files:
|
|
67
79
|
- lib/generators/test_unit/decorator_generator.rb
|
68
80
|
- lib/generators/test_unit/templates/application_decorator_test.rb
|
69
81
|
- lib/generators/test_unit/templates/decorator_test.rb
|
70
|
-
- spec/base_spec.rb
|
82
|
+
- spec/draper/base_spec.rb
|
83
|
+
- spec/draper/helper_support_spec.rb
|
71
84
|
- spec/draper/model_support_spec.rb
|
85
|
+
- spec/draper/view_context_spec.rb
|
72
86
|
- spec/generators/draper/decorator/decorator_generator_spec.rb
|
73
87
|
- spec/generators/rspec/decorator_generator_spec.rb
|
74
88
|
- spec/generators/test_unit/decorator_generator_spec.rb
|
75
|
-
- spec/samples/active_record.rb
|
76
|
-
- spec/samples/application_controller.rb
|
77
|
-
- spec/samples/application_helper.rb
|
78
|
-
- spec/samples/decorator.rb
|
79
|
-
- spec/samples/decorator_with_allows.rb
|
80
|
-
- spec/samples/decorator_with_application_helper.rb
|
81
|
-
- spec/samples/decorator_with_denies.rb
|
82
|
-
- spec/samples/product.rb
|
83
|
-
- spec/samples/product_decorator.rb
|
84
89
|
- spec/spec_helper.rb
|
85
|
-
- spec/
|
90
|
+
- spec/support/samples/active_record.rb
|
91
|
+
- spec/support/samples/application_controller.rb
|
92
|
+
- spec/support/samples/application_helper.rb
|
93
|
+
- spec/support/samples/decorator.rb
|
94
|
+
- spec/support/samples/decorator_with_allows.rb
|
95
|
+
- spec/support/samples/decorator_with_application_helper.rb
|
96
|
+
- spec/support/samples/decorator_with_denies.rb
|
97
|
+
- spec/support/samples/product.rb
|
98
|
+
- spec/support/samples/product_decorator.rb
|
86
99
|
homepage: http://github.com/jcasimir/draper
|
87
100
|
licenses: []
|
88
101
|
post_install_message:
|
@@ -106,21 +119,22 @@ rubyforge_project: draper
|
|
106
119
|
rubygems_version: 1.8.10
|
107
120
|
signing_key:
|
108
121
|
specification_version: 3
|
109
|
-
summary: Decorator pattern
|
122
|
+
summary: Decorator pattern implementation for Rails.
|
110
123
|
test_files:
|
111
|
-
- spec/base_spec.rb
|
124
|
+
- spec/draper/base_spec.rb
|
125
|
+
- spec/draper/helper_support_spec.rb
|
112
126
|
- spec/draper/model_support_spec.rb
|
127
|
+
- spec/draper/view_context_spec.rb
|
113
128
|
- spec/generators/draper/decorator/decorator_generator_spec.rb
|
114
129
|
- spec/generators/rspec/decorator_generator_spec.rb
|
115
130
|
- spec/generators/test_unit/decorator_generator_spec.rb
|
116
|
-
- spec/samples/active_record.rb
|
117
|
-
- spec/samples/application_controller.rb
|
118
|
-
- spec/samples/application_helper.rb
|
119
|
-
- spec/samples/decorator.rb
|
120
|
-
- spec/samples/decorator_with_allows.rb
|
121
|
-
- spec/samples/decorator_with_application_helper.rb
|
122
|
-
- spec/samples/decorator_with_denies.rb
|
123
|
-
- spec/samples/product.rb
|
124
|
-
- spec/samples/product_decorator.rb
|
125
131
|
- spec/spec_helper.rb
|
126
|
-
- spec/
|
132
|
+
- spec/support/samples/active_record.rb
|
133
|
+
- spec/support/samples/application_controller.rb
|
134
|
+
- spec/support/samples/application_helper.rb
|
135
|
+
- spec/support/samples/decorator.rb
|
136
|
+
- spec/support/samples/decorator_with_allows.rb
|
137
|
+
- spec/support/samples/decorator_with_application_helper.rb
|
138
|
+
- spec/support/samples/decorator_with_denies.rb
|
139
|
+
- spec/support/samples/product.rb
|
140
|
+
- spec/support/samples/product_decorator.rb
|