draper 0.12.0 → 0.12.1

Sign up to get free protection for your applications and to get access to all the features.
data/Gemfile CHANGED
@@ -1,17 +1,3 @@
1
1
  source :rubygems
2
2
 
3
- gem 'rake'
4
- gem 'rspec', '~> 2.0'
5
- gem 'activesupport', '~> 3.1.3'
6
- gem 'actionpack', "~> 3.1.3", :require => 'action_view'
7
- gem 'ammeter', '~> 0.2.2', :require => 'ammeter/init'
8
- gem 'guard'
9
- gem 'guard-rspec'
10
- gem 'launchy'
11
- gem 'yard'
12
-
13
- group :development do
14
- gem 'redcarpet'
15
- end
16
-
17
3
  gemspec
@@ -155,20 +155,12 @@ gem "draper"
155
155
 
156
156
  Then run `bundle` from the project directory.
157
157
 
158
- ### Run the draper:install command
159
-
160
- This will create the `app/decorators` directory and the `ApplicationDecorator` inside it.
161
-
162
- ```
163
- rails generate draper:install
164
- ```
165
-
166
158
  ### Generate the Decorator
167
159
 
168
160
  To decorate a model named `Article`:
169
161
 
170
162
  ```
171
- rails generate draper:decorator article
163
+ rails generate decorator article
172
164
  ```
173
165
 
174
166
  ### Writing Methods
@@ -176,7 +168,7 @@ rails generate draper:decorator article
176
168
  Open the decorator model (ex: `app/decorators/article_decorator.rb`) and add normal instance methods. To access the wrapped source object, use a method named after the `decorates` argument:
177
169
 
178
170
  ```ruby
179
- class ArticleDecorator < ApplicationDecorator
171
+ class ArticleDecorator < Draper::Base
180
172
  decorates :article
181
173
 
182
174
  def author_name
@@ -190,7 +182,7 @@ end
190
182
  You probably want to make use of Rails helpers and those defined in your application. Use the `helpers` or `h` method proxy:
191
183
 
192
184
  ```ruby
193
- class ArticleDecorator < ApplicationDecorator
185
+ class ArticleDecorator < Draper::Base
194
186
  decorates :article
195
187
 
196
188
  def published_at
@@ -206,7 +198,7 @@ end
206
198
  Hate seeing that `h.` proxy all over? Willing to mix a bazillion methods into your decorator? Then try lazy helpers:
207
199
 
208
200
  ```ruby
209
- class ArticleDecorator < ApplicationDecorator
201
+ class ArticleDecorator < Draper::Base
210
202
  decorates :article
211
203
  include Draper::LazyHelpers
212
204
 
@@ -313,7 +305,7 @@ end
313
305
  Then you need to perform the wrapping in your controller. Here's the simplest method:
314
306
 
315
307
  ```ruby
316
- class ArticlesController < ApplicationController
308
+ class ArticlesController < Draper::Decorator
317
309
  def show
318
310
  @article = ArticleDecorator.find params[:id]
319
311
  end
@@ -329,7 +321,7 @@ Then within your views you can utilize both the normal data methods and your new
329
321
  Ta-da! Object-oriented data formatting for your view layer. Below is the complete decorator with extra comments removed:
330
322
 
331
323
  ```ruby
332
- class ArticleDecorator < ApplicationDecorator
324
+ class ArticleDecorator < Draper::Base
333
325
  decorates :article
334
326
 
335
327
  def published_at
@@ -345,12 +337,12 @@ end
345
337
  Add a `decorates_association :association_name` to gain access to a decorated version of your target association.
346
338
 
347
339
  ```ruby
348
- class ArticleDecorator < ApplicationDecorator
340
+ class ArticleDecorator < Draper::Base
349
341
  decorates :article
350
342
  decorates_association :author # belongs_to :author association
351
343
  end
352
344
 
353
- class AuthorDecorator < ApplicationDecorator
345
+ class AuthorDecorator < Draper::Base
354
346
  decorates :author
355
347
 
356
348
  def fancy_name
@@ -15,6 +15,16 @@ Gem::Specification.new do |s|
15
15
  s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
16
16
  s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
17
17
  s.require_paths = ["lib"]
18
- s.add_dependency('activesupport', '>= 2.3.10')
19
- s.add_development_dependency('redcarpet')
18
+
19
+ s.add_dependency 'activesupport', '>= 2.3.10'
20
+ s.add_dependency 'rake'
21
+ s.add_dependency 'rspec', '~> 2.0'
22
+ s.add_dependency 'activesupport', '~> 3.1.3'
23
+ s.add_dependency 'actionpack', "~> 3.1.3"
24
+
25
+ s.add_development_dependency 'ammeter', '~> 0.2.2'
26
+ s.add_development_dependency 'guard'
27
+ s.add_development_dependency 'guard-rspec'
28
+ s.add_development_dependency 'launchy'
29
+ s.add_development_dependency 'yard'
20
30
  end
@@ -1,4 +1,6 @@
1
- require "draper/version"
1
+ require 'action_view'
2
+
3
+ require 'draper/version'
2
4
  require 'draper/system'
3
5
  require 'draper/active_model_support'
4
6
  require 'draper/base'
@@ -1,3 +1,3 @@
1
1
  module Draper
2
- VERSION = "0.12.0"
2
+ VERSION = "0.12.1"
3
3
  end
@@ -17,7 +17,7 @@ module Rails
17
17
  def parent_class_name
18
18
  if options[:parent]
19
19
  options[:parent]
20
- elsif defined?(:ApplicationDecorator)
20
+ elsif defined?(ApplicationDecorator)
21
21
  "ApplicationDecorator"
22
22
  else
23
23
  "Draper::Base"
@@ -1,5 +1,5 @@
1
1
  <% module_namespacing do -%>
2
- class <%= class_name %>Decorator < ApplicationDecorator
2
+ class <%= class_name %>Decorator < <%= parent_class_name %>
3
3
  decorates :<%= singular_name %>
4
4
 
5
5
  # Accessing Helpers
@@ -15,7 +15,7 @@ describe Rails::Generators::DecoratorGenerator do
15
15
  describe 'app/decorators/your_model_decorator.rb' do
16
16
  subject { file('app/decorators/your_model_decorator.rb') }
17
17
  it { should exist }
18
- it { should contain "class YourModelDecorator < ApplicationDecorator" }
18
+ it { should contain "class YourModelDecorator < Draper::Base" }
19
19
  it { should contain "decorates :your_model" }
20
20
  end
21
21
  end
@@ -30,6 +30,27 @@ describe Rails::Generators::DecoratorGenerator do
30
30
  end
31
31
  end
32
32
 
33
+ context 'parent decorator' do
34
+ describe 'decorator inhereted from Draper::Base' do
35
+ before { run_generator ["YourModel"] }
36
+
37
+ subject { file('app/decorators/your_model_decorator.rb') }
38
+ it { should exist }
39
+ it { should contain "class YourModelDecorator < Draper::Base" }
40
+ end
41
+
42
+ describe "decorator inhereted from ApplicationDecorator if it's present" do
43
+ before do
44
+ class ApplicationDecorator; end
45
+ run_generator ["YourModel"]
46
+ end
47
+
48
+ subject { file('app/decorators/your_model_decorator.rb') }
49
+ it { should exist }
50
+ it { should contain "class YourModelDecorator < ApplicationDecorator" }
51
+ end
52
+ end
53
+
33
54
  context 'using rspec' do
34
55
  before { run_generator ["YourModel", "-t=rspec"] }
35
56
 
@@ -1,5 +1,6 @@
1
1
  require 'rubygems'
2
2
  require 'bundler/setup'
3
+ require 'ammeter/init'
3
4
  require 'rails'
4
5
 
5
6
  Bundler.require
metadata CHANGED
@@ -1,47 +1,183 @@
1
- --- !ruby/object:Gem::Specification
1
+ --- !ruby/object:Gem::Specification
2
2
  name: draper
3
- version: !ruby/object:Gem::Version
4
- version: 0.12.0
3
+ version: !ruby/object:Gem::Version
4
+ hash: 45
5
5
  prerelease:
6
+ segments:
7
+ - 0
8
+ - 12
9
+ - 1
10
+ version: 0.12.1
6
11
  platform: ruby
7
- authors:
12
+ authors:
8
13
  - Jeff Casimir
9
14
  - Steve Klabnik
10
15
  autorequire:
11
16
  bindir: bin
12
17
  cert_chain: []
13
- date: 2012-05-09 00:00:00.000000000 Z
14
- dependencies:
15
- - !ruby/object:Gem::Dependency
18
+
19
+ date: 2012-05-12 00:00:00 Z
20
+ dependencies:
21
+ - !ruby/object:Gem::Dependency
16
22
  name: activesupport
17
- requirement: &70309298925200 !ruby/object:Gem::Requirement
23
+ prerelease: false
24
+ requirement: &id001 !ruby/object:Gem::Requirement
18
25
  none: false
19
- requirements:
20
- - - ! '>='
21
- - !ruby/object:Gem::Version
26
+ requirements:
27
+ - - ">="
28
+ - !ruby/object:Gem::Version
29
+ hash: 23
30
+ segments:
31
+ - 2
32
+ - 3
33
+ - 10
22
34
  version: 2.3.10
23
35
  type: :runtime
36
+ version_requirements: *id001
37
+ - !ruby/object:Gem::Dependency
38
+ name: rake
39
+ prerelease: false
40
+ requirement: &id002 !ruby/object:Gem::Requirement
41
+ none: false
42
+ requirements:
43
+ - - ">="
44
+ - !ruby/object:Gem::Version
45
+ hash: 3
46
+ segments:
47
+ - 0
48
+ version: "0"
49
+ type: :runtime
50
+ version_requirements: *id002
51
+ - !ruby/object:Gem::Dependency
52
+ name: rspec
24
53
  prerelease: false
25
- version_requirements: *70309298925200
26
- - !ruby/object:Gem::Dependency
27
- name: redcarpet
28
- requirement: &70309298924340 !ruby/object:Gem::Requirement
54
+ requirement: &id003 !ruby/object:Gem::Requirement
29
55
  none: false
30
- requirements:
31
- - - ! '>='
32
- - !ruby/object:Gem::Version
33
- version: '0'
56
+ requirements:
57
+ - - ~>
58
+ - !ruby/object:Gem::Version
59
+ hash: 3
60
+ segments:
61
+ - 2
62
+ - 0
63
+ version: "2.0"
64
+ type: :runtime
65
+ version_requirements: *id003
66
+ - !ruby/object:Gem::Dependency
67
+ name: activesupport
68
+ prerelease: false
69
+ requirement: &id004 !ruby/object:Gem::Requirement
70
+ none: false
71
+ requirements:
72
+ - - ~>
73
+ - !ruby/object:Gem::Version
74
+ hash: 5
75
+ segments:
76
+ - 3
77
+ - 1
78
+ - 3
79
+ version: 3.1.3
80
+ type: :runtime
81
+ version_requirements: *id004
82
+ - !ruby/object:Gem::Dependency
83
+ name: actionpack
84
+ prerelease: false
85
+ requirement: &id005 !ruby/object:Gem::Requirement
86
+ none: false
87
+ requirements:
88
+ - - ~>
89
+ - !ruby/object:Gem::Version
90
+ hash: 5
91
+ segments:
92
+ - 3
93
+ - 1
94
+ - 3
95
+ version: 3.1.3
96
+ type: :runtime
97
+ version_requirements: *id005
98
+ - !ruby/object:Gem::Dependency
99
+ name: ammeter
100
+ prerelease: false
101
+ requirement: &id006 !ruby/object:Gem::Requirement
102
+ none: false
103
+ requirements:
104
+ - - ~>
105
+ - !ruby/object:Gem::Version
106
+ hash: 19
107
+ segments:
108
+ - 0
109
+ - 2
110
+ - 2
111
+ version: 0.2.2
112
+ type: :development
113
+ version_requirements: *id006
114
+ - !ruby/object:Gem::Dependency
115
+ name: guard
116
+ prerelease: false
117
+ requirement: &id007 !ruby/object:Gem::Requirement
118
+ none: false
119
+ requirements:
120
+ - - ">="
121
+ - !ruby/object:Gem::Version
122
+ hash: 3
123
+ segments:
124
+ - 0
125
+ version: "0"
126
+ type: :development
127
+ version_requirements: *id007
128
+ - !ruby/object:Gem::Dependency
129
+ name: guard-rspec
130
+ prerelease: false
131
+ requirement: &id008 !ruby/object:Gem::Requirement
132
+ none: false
133
+ requirements:
134
+ - - ">="
135
+ - !ruby/object:Gem::Version
136
+ hash: 3
137
+ segments:
138
+ - 0
139
+ version: "0"
140
+ type: :development
141
+ version_requirements: *id008
142
+ - !ruby/object:Gem::Dependency
143
+ name: launchy
144
+ prerelease: false
145
+ requirement: &id009 !ruby/object:Gem::Requirement
146
+ none: false
147
+ requirements:
148
+ - - ">="
149
+ - !ruby/object:Gem::Version
150
+ hash: 3
151
+ segments:
152
+ - 0
153
+ version: "0"
34
154
  type: :development
155
+ version_requirements: *id009
156
+ - !ruby/object:Gem::Dependency
157
+ name: yard
35
158
  prerelease: false
36
- version_requirements: *70309298924340
159
+ requirement: &id010 !ruby/object:Gem::Requirement
160
+ none: false
161
+ requirements:
162
+ - - ">="
163
+ - !ruby/object:Gem::Version
164
+ hash: 3
165
+ segments:
166
+ - 0
167
+ version: "0"
168
+ type: :development
169
+ version_requirements: *id010
37
170
  description: Draper implements a decorator or presenter pattern for Rails applications.
38
- email:
171
+ email:
39
172
  - jeff@casimircreative.com
40
173
  - steve@steveklabnik.com
41
174
  executables: []
175
+
42
176
  extensions: []
177
+
43
178
  extra_rdoc_files: []
44
- files:
179
+
180
+ files:
45
181
  - .gitignore
46
182
  - .rspec
47
183
  - .travis.yml
@@ -123,29 +259,38 @@ files:
123
259
  - spec/support/samples/widget_decorator.rb
124
260
  homepage: http://github.com/jcasimir/draper
125
261
  licenses: []
262
+
126
263
  post_install_message:
127
264
  rdoc_options: []
128
- require_paths:
265
+
266
+ require_paths:
129
267
  - lib
130
- required_ruby_version: !ruby/object:Gem::Requirement
268
+ required_ruby_version: !ruby/object:Gem::Requirement
131
269
  none: false
132
- requirements:
133
- - - ! '>='
134
- - !ruby/object:Gem::Version
135
- version: '0'
136
- required_rubygems_version: !ruby/object:Gem::Requirement
270
+ requirements:
271
+ - - ">="
272
+ - !ruby/object:Gem::Version
273
+ hash: 3
274
+ segments:
275
+ - 0
276
+ version: "0"
277
+ required_rubygems_version: !ruby/object:Gem::Requirement
137
278
  none: false
138
- requirements:
139
- - - ! '>='
140
- - !ruby/object:Gem::Version
141
- version: '0'
279
+ requirements:
280
+ - - ">="
281
+ - !ruby/object:Gem::Version
282
+ hash: 3
283
+ segments:
284
+ - 0
285
+ version: "0"
142
286
  requirements: []
287
+
143
288
  rubyforge_project: draper
144
- rubygems_version: 1.8.16
289
+ rubygems_version: 1.8.24
145
290
  signing_key:
146
291
  specification_version: 3
147
292
  summary: Decorator pattern implementation for Rails.
148
- test_files:
293
+ test_files:
149
294
  - spec/draper/base_spec.rb
150
295
  - spec/draper/helper_support_spec.rb
151
296
  - spec/draper/model_support_spec.rb