showcase 0.1.3 → 0.1.4

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: c2dac659595ecfefe450c2e7b15134928cfb092f
4
- data.tar.gz: 894b2b499088e50f4c1d6928ae318935678048b1
3
+ metadata.gz: 0c3e2b2cefd111fc7d1a066a4d9391e196292ecc
4
+ data.tar.gz: 6aeeda275c85e39770048b89ae9b17c747209bd7
5
5
  SHA512:
6
- metadata.gz: ede80b6f7826d8899ae55dfc64ed0c651ec2f7f1fb8b694cf93520299b02992bc5e87f0761a3797feb066105a1ab754af8f1b9aa90af6b8ef352f5b9e59eb778
7
- data.tar.gz: 6b2faaa1ad5d27333be12c34748da6263ff18ed61305ecc47d7289453a4d968f42910f70a3bd41f739aec30d1701dede0cec2bb3591a7d8ce27e99771832ad90
6
+ metadata.gz: 0551db2643cffe9fa475f4c3e8a31cc552788a8efd33ad3a2a809f1815dd79d2f31ce291a636dd6fb2b68330ce3c6916566966c1032e4b94d72bead873974a47
7
+ data.tar.gz: 9b94f78359199fd20804d1903420e314eed8ece8e8b2a8a18bd8d6158a440d6ed874aac09f38518a4b9c85ab5834994131d4d613f5803fd4e0990f87fda8c41c
data/README.md CHANGED
@@ -1,6 +1,17 @@
1
- # Showcase [![Build Status](https://travis-ci.org/welaika/showcase.png?branch=master)](https://travis-ci.org/welaika/showcase)
1
+ # Showcase [![Build Status](https://travis-ci.org/welaika/showcase.png?branch=master)](https://travis-ci.org/welaika/showcase) [![Coverage Status](https://coveralls.io/repos/welaika/showcase/badge.png?branch=master)](https://coveralls.io/r/welaika/showcase)
2
2
 
3
- A simple (< 100 lines of code) but powerful presenter implementation. Framework agnostic: works with Rails, Padrino or simply Sinatra.
3
+ A simple (< 100 lines of code) but powerful exhibit/presenter implementation. It's framework agnostic: works with Rails, Padrino or simply Sinatra.
4
+
5
+ ## Properties of the Exhibit pattern
6
+
7
+ Citing [Avdi's introductory post](http://devblog.avdi.org/2012/06/04/displaycase-gem-now-available/):
8
+
9
+ * **It wraps a single model instance.** Not an assortment of objects.
10
+ * **It is a true Decorator.** All unrecognized messages are passed through to the underlying object. This facilitates a gradual migration to the use of Exhibits to encapsulate presentation knowledge, since they can be layered onto models without any change to the existing views. It also enables multiple Exhibits to be layered onto an object, each handling different aspects of presentation.
11
+ * **It brings together a model and a context.** Exhibits need a reference to a “context” object—either a controller or a view context—in order to be able to render templates as well as construct URLs for the object or related resources.
12
+ * **It encapsulates decisions about how to render an object.** The tell-tale of an Exhibit is telling an object “render yourself”, rather than explicitly rendering a template and passing the object in as an argument.
13
+ * **It may modify the behavior of an object.** For instance, an Exhibit might impose a scope on a `Blog#entries` association which only returns entries that are visible to the current user (as determined from the Exhibit’s controller context). Or it might reformat the return value of a `#social_security_number` method to include dashes and have all but the last four digits obscured: `***-**-5678`.
14
+ * **There is a many-to-many relationship between model classes and exhibit classes.** One generic exhibit class may apply to several different types of model. Other exhibits may be specific, not just to a model, but to a model in a particular state, or within a particular viewing context.
4
15
 
5
16
  ## Installation
6
17
 
@@ -50,7 +61,7 @@ present(person, AdminPresenter) # => returns an AdminPresenter instance
50
61
  present(person, PersonPresenter, context)
51
62
 
52
63
  # maps each person in the collection with a presenter
53
- present_collection([ people ]) # => returns an array of PeoplePresenters
64
+ present_collection([person]) # => returns an array of PersonPresenters
54
65
  ```
55
66
 
56
67
  Define your presenters i.e. in a `app/presenters` folder:
@@ -60,6 +71,9 @@ class ProjectPresenter < Showcase::Presenter
60
71
  # automatically wraps the attribute into a PersonPresenter
61
72
  presents :person
62
73
 
74
+ # automatically wraps the attribute into an AdminPresenter
75
+ presents :person, with: AdminPresenter
76
+
63
77
  # expects project.task to return an enumerable. automatically wraps each task in a TaskPresenter presenter
64
78
  presents_collection :tasks
65
79
 
@@ -1,5 +1,7 @@
1
1
  require 'delegate'
2
2
  require 'showcase/helpers'
3
+ require 'active_support/core_ext/array/extract_options'
4
+ require 'active_support/core_ext/hash/keys'
3
5
 
4
6
  module Showcase
5
7
  class Presenter < SimpleDelegator
@@ -28,18 +30,26 @@ module Showcase
28
30
  object.instance_of?(klass)
29
31
  end
30
32
 
31
- def self.presents(*attrs)
32
- attrs.each do |attr|
33
+ def self.presents(*args)
34
+ options = args.extract_options!
35
+ options.assert_valid_keys(:with)
36
+ presenter_klass = options.fetch(:with, nil)
37
+
38
+ args.each do |attr|
33
39
  define_method attr do
34
- present(object.send(attr), nil, view_context)
40
+ present(object.send(attr), presenter_klass, view_context)
35
41
  end
36
42
  end
37
43
  end
38
44
 
39
- def self.presents_collection(*attrs)
40
- attrs.each do |attr|
45
+ def self.presents_collection(*args)
46
+ options = args.extract_options!
47
+ options.assert_valid_keys(:with)
48
+ presenter_klass = options.fetch(:with, nil)
49
+
50
+ args.each do |attr|
41
51
  define_method attr do
42
- present_collection(object.send(attr), nil, view_context)
52
+ present_collection(object.send(attr), presenter_klass, view_context)
43
53
  end
44
54
  end
45
55
  end
@@ -1,3 +1,4 @@
1
1
  module Showcase
2
- VERSION = "0.1.3"
2
+ VERSION = "0.1.4"
3
3
  end
4
+
data/showcase.gemspec CHANGED
@@ -4,20 +4,21 @@ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
4
  require 'showcase/version'
5
5
 
6
6
  Gem::Specification.new do |gem|
7
- gem.name = "showcase"
7
+ gem.name = 'showcase'
8
8
  gem.version = Showcase::VERSION
9
- gem.authors = ["Stefano Verna"]
10
- gem.email = ["stefano.verna@welaika.com"]
9
+ gem.authors = ['Stefano Verna']
10
+ gem.email = ['stefano.verna@welaika.com']
11
11
  gem.description = %q{A barebone and framework agnostic presenter implementation}
12
12
  gem.summary = %q{A barebone and framework agnostic presenter implementation}
13
- gem.homepage = "https://github.com/welaika/showcase"
13
+ gem.homepage = 'https://github.com/welaika/showcase'
14
14
 
15
15
  gem.files = `git ls-files`.split($/)
16
16
  gem.executables = gem.files.grep(%r{^bin/}).map{ |f| File.basename(f) }
17
17
  gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
18
- gem.require_paths = ["lib"]
18
+ gem.require_paths = ['lib']
19
19
 
20
- gem.add_dependency "activesupport"
21
- gem.add_development_dependency "rspec"
20
+ gem.add_dependency 'activesupport'
21
+ gem.add_development_dependency 'rspec'
22
+ gem.add_development_dependency 'coveralls'
22
23
  end
23
24
 
data/spec/fixtures.rb CHANGED
@@ -29,8 +29,14 @@ class PersonPresenter < Showcase::Presenter
29
29
  end
30
30
  end
31
31
 
32
+ class AdminPresenter < PersonPresenter
33
+ def bold_name
34
+ h.bold("Admin #{object.name}")
35
+ end
36
+ end
37
+
32
38
  class ProjectPresenter < Showcase::Presenter
33
- presents :owner
39
+ presents :owner, with: AdminPresenter
34
40
  presents_collection :collaborators
35
41
 
36
42
  def name
@@ -53,3 +59,4 @@ class Context
53
59
  "**#{text}**"
54
60
  end
55
61
  end
62
+
@@ -1,3 +1,6 @@
1
+ require 'coveralls'
2
+ Coveralls.wear!
3
+
1
4
  require 'showcase'
2
5
  require_relative './fixtures'
3
6
 
@@ -15,6 +18,14 @@ describe Showcase::Presenter do
15
18
  subject.class.should == Project
16
19
  end
17
20
 
21
+ it 'should be kind of original class' do
22
+ subject.should be_kind_of Project
23
+ end
24
+
25
+ it 'should be instance of original class' do
26
+ subject.should be_instance_of Project
27
+ end
28
+
18
29
  it 'delegates methods to object' do
19
30
  subject.dummy.should == 'foobar'
20
31
  end
@@ -38,7 +49,7 @@ describe Showcase::Presenter do
38
49
  subject.owner.sex.should == 'male'
39
50
  end
40
51
  it 'passes the context' do
41
- subject.owner.bold_name.should == '**Stefano Verna**'
52
+ subject.owner.bold_name.should == '**Admin Stefano Verna**'
42
53
  end
43
54
  end
44
55
 
@@ -66,7 +77,7 @@ describe Showcase::Helpers do
66
77
  context.present(object, ProjectPresenter).should == 'Presenter'
67
78
  end
68
79
  it 'the context to use can be specified as third parameter' do
69
- different_context = stub
80
+ different_context = double
70
81
  context.present(object, ProjectPresenter, different_context).view_context.should == different_context
71
82
  end
72
83
  end
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.1.3
4
+ version: 0.1.4
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-04-19 00:00:00.000000000 Z
11
+ date: 2013-07-23 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activesupport
@@ -38,6 +38,20 @@ dependencies:
38
38
  - - '>='
39
39
  - !ruby/object:Gem::Version
40
40
  version: '0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: coveralls
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - '>='
46
+ - !ruby/object:Gem::Version
47
+ version: '0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - '>='
53
+ - !ruby/object:Gem::Version
54
+ version: '0'
41
55
  description: A barebone and framework agnostic presenter implementation
42
56
  email:
43
57
  - stefano.verna@welaika.com
@@ -87,3 +101,4 @@ summary: A barebone and framework agnostic presenter implementation
87
101
  test_files:
88
102
  - spec/fixtures.rb
89
103
  - spec/showcase_spec.rb
104
+ has_rdoc: