showcase 0.2.0.rc.4 → 0.2.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: ea7a961ec1b6c1052fad8382dbac298219823089
4
- data.tar.gz: 57e69cf51b6380e1f1e400ccfc7476eded417201
3
+ metadata.gz: 8cc9956d43209ffcf07147c5ebd550aa6dd07407
4
+ data.tar.gz: 2f0302d869f55ac73959facae8ce2595d4c5f4b2
5
5
  SHA512:
6
- metadata.gz: 230965dd32b8151f9ed5f43c72614ad951825f79e1dedea1717300fbb74374b890ae14536d4d9dace620740482b09c972e62d5fbbcf58cae53b1812510288bfc
7
- data.tar.gz: 4c07a160bf50ef8ed1cfd512a29c29b6b827722228d3d7ce7469d4766a2de341602ea07bf5af8405f7e4aafc4a1eb9ea15d4a8a7a074ddaf255ce14e2b2b1e35
6
+ metadata.gz: 28fdce56fdb476019ecf50d476f614bba7d8c7a01d569d78abe6c824ef213f930972d2b90ddf5010143f0d148527ba1f9f9c60e87908e1b674e75a95676ef1b7
7
+ data.tar.gz: d613dce8342d633d97368a003937a068e64bd2d8ec8dc8825cf857648e9c759281c31b15413a35592b9883c4880ec68670d7e56065535bd4c0539510a58740f4
data/Gemfile CHANGED
@@ -4,4 +4,3 @@ source 'https://rubygems.org'
4
4
  gemspec
5
5
 
6
6
  gem "appraisal"
7
-
data/README.md CHANGED
@@ -100,7 +100,7 @@ from `BasePresenter` instead of `Showcase::Presenter`.
100
100
 
101
101
  ### Traits
102
102
 
103
- Please [read the tests](https://github.com/stefanoverna/showcase/tree/master/lib/showcase/traits)
103
+ Please [read the tests](https://github.com/stefanoverna/showcase/tree/master/lib/showcase/traits)
104
104
  for a detailed explanation of each method available.
105
105
 
106
106
  #### `Showcase::Traits::Record`
@@ -145,7 +145,7 @@ Produces the following:
145
145
  </div>
146
146
  ```
147
147
 
148
- Additional HTML attributes can be optionally specified within a config block
148
+ Additional HTML attributes can be optionally specified within a config block
149
149
  inside the presenter:
150
150
 
151
151
  ```ruby
@@ -258,6 +258,23 @@ In your views:
258
258
  <% end %>
259
259
  ```
260
260
 
261
+
262
+ ## Testing
263
+
264
+ Install gems:
265
+
266
+ ```
267
+ $ bundle
268
+ $ rake appraisal:install
269
+ ```
270
+
271
+ Launch tests:
272
+
273
+ ```
274
+ rake appraisal
275
+ ```
276
+
277
+
261
278
  ## Contributing
262
279
 
263
280
  1. Fork it
@@ -265,4 +282,3 @@ In your views:
265
282
  3. Commit your changes (`git commit -am 'Add some feature'`)
266
283
  4. Push to the branch (`git push origin my-new-feature`)
267
284
  5. Create new Pull Request
268
-
@@ -19,7 +19,7 @@ module Showcase
19
19
  options.assert_valid_keys(:nil_presenter)
20
20
 
21
21
  if obj || options.fetch(:nil_presenter, false)
22
- klass ||= "#{obj.class.name}Presenter".constantize
22
+ klass ||= presenter_class(obj)
23
23
  klass.new(obj, context)
24
24
  else
25
25
  nil
@@ -29,7 +29,15 @@ module Showcase
29
29
  def present_collection(obj, klass = nil, context = presenter_context, options = {})
30
30
  obj.map { |o| present(o, klass, context, options) }
31
31
  end
32
+
33
+ private
34
+
35
+ def presenter_class(obj)
36
+ obj.class.ancestors.each do |k|
37
+ klass = "#{k.name}Presenter".safe_constantize
38
+ return klass if klass
39
+ end
40
+ end
32
41
  end
33
42
  end
34
43
  end
35
-
@@ -1,4 +1,4 @@
1
1
  module Showcase
2
- VERSION = "0.2.0.rc.4"
2
+ VERSION = "0.2.0"
3
3
  end
4
4
 
data/spec/fixtures.rb CHANGED
@@ -17,6 +17,12 @@ end
17
17
  class Person < Struct.new(:name)
18
18
  end
19
19
 
20
+ class Customer < Person
21
+ end
22
+
23
+ class EnterpriseCustomer < Customer
24
+ end
25
+
20
26
  class Project < Struct.new(:name)
21
27
  def owner
22
28
  Person.new("Stefano Verna")
data/spec/helpers_spec.rb CHANGED
@@ -2,12 +2,17 @@ require 'spec_helper'
2
2
 
3
3
  describe Showcase::Helpers do
4
4
  let(:object) { Person.new('Steve Ballmer') }
5
+ let(:derived_object) { EnterpriseCustomer.new('Tito Traves') }
5
6
  let(:context) { Context.new }
6
7
 
7
8
  describe '.present' do
8
- it 'instanciate a new presenter, inferring the class' do
9
+ it 'instantiates a new presenter, inferring the class' do
9
10
  PersonPresenter.stub(:new).with(object, context).and_return 'Presenter'
10
- context.present(object, PersonPresenter).should == 'Presenter'
11
+ context.present(object).should == 'Presenter'
12
+ end
13
+ it "instantiates a new presenter, searching presenter class in object ancestors chain" do
14
+ PersonPresenter.stub(:new).with(derived_object, context).and_return 'Presenter'
15
+ context.present(derived_object).should == 'Presenter'
11
16
  end
12
17
  it 'the presenter class to use can be specified as the second parameter' do
13
18
  ProjectPresenter.stub(:new).with(object, context).and_return 'Presenter'
@@ -31,4 +36,3 @@ describe Showcase::Helpers do
31
36
  end
32
37
  end
33
38
  end
34
-
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: showcase
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.0.rc.4
4
+ version: 0.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Stefano Verna
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2013-11-29 00:00:00.000000000 Z
11
+ date: 2013-12-14 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activesupport
@@ -141,9 +141,9 @@ required_ruby_version: !ruby/object:Gem::Requirement
141
141
  version: '0'
142
142
  required_rubygems_version: !ruby/object:Gem::Requirement
143
143
  requirements:
144
- - - '>'
144
+ - - '>='
145
145
  - !ruby/object:Gem::Version
146
- version: 1.3.1
146
+ version: '0'
147
147
  requirements: []
148
148
  rubyforge_project:
149
149
  rubygems_version: 2.0.3