bourgeois 0.0.1
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/.gitignore +17 -0
- data/Gemfile +4 -0
- data/LICENSE.md +26 -0
- data/README.md +56 -0
- data/Rakefile +3 -0
- data/bourgeois.gemspec +26 -0
- data/lib/bourgeois/presenter.rb +34 -0
- data/lib/bourgeois/railtie.rb +12 -0
- data/lib/bourgeois/version.rb +3 -0
- data/lib/bourgeois/view_helper.rb +20 -0
- data/lib/bourgeois.rb +10 -0
- metadata +127 -0
data/.gitignore
ADDED
data/Gemfile
ADDED
data/LICENSE.md
ADDED
@@ -0,0 +1,26 @@
|
|
1
|
+
Copyright (c) 2013, Mirego
|
2
|
+
All rights reserved.
|
3
|
+
|
4
|
+
Redistribution and use in source and binary forms, with or without
|
5
|
+
modification, are permitted provided that the following conditions are met:
|
6
|
+
|
7
|
+
- Redistributions of source code must retain the above copyright notice,
|
8
|
+
this list of conditions and the following disclaimer.
|
9
|
+
- Redistributions in binary form must reproduce the above copyright notice,
|
10
|
+
this list of conditions and the following disclaimer in the documentation
|
11
|
+
and/or other materials provided with the distribution.
|
12
|
+
- Neither the name of the Mirego nor the names of its contributors may
|
13
|
+
be used to endorse or promote products derived from this software without
|
14
|
+
specific prior written permission.
|
15
|
+
|
16
|
+
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
17
|
+
AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
18
|
+
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
19
|
+
ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
|
20
|
+
LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
|
21
|
+
CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
|
22
|
+
SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
|
23
|
+
INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
|
24
|
+
CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
25
|
+
ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
26
|
+
POSSIBILITY OF SUCH DAMAGE.
|
data/README.md
ADDED
@@ -0,0 +1,56 @@
|
|
1
|
+
# Bourgeois
|
2
|
+
|
3
|
+
Bourgeois is a Ruby library that makes using presenters a very simple thing.
|
4
|
+
|
5
|
+
## Installation
|
6
|
+
|
7
|
+
Add this line to your application’s Gemfile:
|
8
|
+
|
9
|
+
```ruby
|
10
|
+
gem 'bourgeois'
|
11
|
+
```
|
12
|
+
|
13
|
+
And then execute:
|
14
|
+
|
15
|
+
```bash
|
16
|
+
$ bundle
|
17
|
+
```
|
18
|
+
|
19
|
+
## Usage
|
20
|
+
|
21
|
+
Create an `app/presenters` directory and put some presenters in it:
|
22
|
+
|
23
|
+
```ruby
|
24
|
+
# app/presenters/user_presenter.rb
|
25
|
+
|
26
|
+
class UserPresenter < Bourgeois::Presenter
|
27
|
+
def formatted_name
|
28
|
+
"#{first_name} #{last_name}".strip
|
29
|
+
end
|
30
|
+
end
|
31
|
+
```
|
32
|
+
|
33
|
+
Then, you can use the `present` helper in your views to wrap `ActiveModel` (and `ActiveRecord`) objects around a presenter:
|
34
|
+
|
35
|
+
```erb
|
36
|
+
# app/view/users/show.erb
|
37
|
+
|
38
|
+
<%= present(@user) do |user| %>
|
39
|
+
<p>This is <%= user.formatted_name %></p>
|
40
|
+
<% end %>
|
41
|
+
```
|
42
|
+
|
43
|
+
Methods that aren’t in the presenter (`first_name` and `last_name`) are delegated to the presented object.
|
44
|
+
|
45
|
+
## Inpiration
|
46
|
+
|
47
|
+
Bourgeois was inspired by some code [@rafBM](https://twitter.com/rafBM) wrote for [his OpenCode talk](https://github.com/rafBM/opencode12-rails) on May 28th, 2013.
|
48
|
+
|
49
|
+
## License
|
50
|
+
|
51
|
+
`Bourgeois` is © 2013 [Mirego](http://www.mirego.com) and may be freely distributed under the [New BSD license](http://opensource.org/licenses/BSD-3-Clause). See the [`LICENSE.md`](https://github.com/mirego/bourgeois/blob/master/LICENSE.md) file.
|
52
|
+
|
53
|
+
## About Mirego
|
54
|
+
|
55
|
+
Mirego is a team of passionate people who believe that work is a place where you can innovate and have fun.
|
56
|
+
We proudly built mobile applications for [iPhone](http://mirego.com/en/iphone-app-development/ "iPhone application development"), [iPad](http://mirego.com/en/ipad-app-development/ "iPad application development"), [Android](http://mirego.com/en/android-app-development/ "Android application development"), [Blackberry](http://mirego.com/en/blackberry-app-development/ "Blackberry application development"), [Windows Phone](http://mirego.com/en/windows-phone-app-development/ "Windows Phone application development") and [Windows 8](http://mirego.com/en/windows-8-app-development/ "Windows 8 application development").
|
data/Rakefile
ADDED
data/bourgeois.gemspec
ADDED
@@ -0,0 +1,26 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'bourgeois/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = 'bourgeois'
|
8
|
+
spec.version = Bourgeois::VERSION
|
9
|
+
spec.authors = ['Rémi Prévost']
|
10
|
+
spec.email = ['rprevost@mirego.com']
|
11
|
+
spec.description = ''
|
12
|
+
spec.summary = ''
|
13
|
+
spec.homepage = 'https://github.com/mirego/bourgeois'
|
14
|
+
spec.license = 'BSD 3-Clause'
|
15
|
+
|
16
|
+
spec.files = `git ls-files`.split($/)
|
17
|
+
spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
|
18
|
+
spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
|
19
|
+
spec.require_paths = ["lib"]
|
20
|
+
|
21
|
+
spec.add_development_dependency 'bundler', '~> 1.3'
|
22
|
+
spec.add_development_dependency 'rake'
|
23
|
+
|
24
|
+
spec.add_dependency 'activemodel', '>= 3.0.0'
|
25
|
+
spec.add_dependency 'actionpack', '>= 3.0.0'
|
26
|
+
end
|
@@ -0,0 +1,34 @@
|
|
1
|
+
module Bourgeois
|
2
|
+
class Presenter < ::SimpleDelegator
|
3
|
+
def initialize(object, view)
|
4
|
+
@view = view
|
5
|
+
super(@object = object)
|
6
|
+
end
|
7
|
+
|
8
|
+
def inspect
|
9
|
+
"#<#{self.class} object=#{@object.inspect}>"
|
10
|
+
end
|
11
|
+
|
12
|
+
def kind_of?(mod)
|
13
|
+
@object.kind_of?(mod)
|
14
|
+
end
|
15
|
+
|
16
|
+
def self.model_name
|
17
|
+
klass.model_name
|
18
|
+
end
|
19
|
+
|
20
|
+
def self.human_attribute_name(*args)
|
21
|
+
klass.human_attribute_name(*args)
|
22
|
+
end
|
23
|
+
|
24
|
+
private
|
25
|
+
|
26
|
+
def view
|
27
|
+
@view
|
28
|
+
end
|
29
|
+
|
30
|
+
def self.klass
|
31
|
+
@klass ||= self.name.split(/Presenter$/).first.constantize
|
32
|
+
end
|
33
|
+
end
|
34
|
+
end
|
@@ -0,0 +1,20 @@
|
|
1
|
+
module Bourgeois
|
2
|
+
module ViewHelper
|
3
|
+
# Wrap a resource or a collection into its related delegator
|
4
|
+
#
|
5
|
+
# @example
|
6
|
+
# present User.new(name: 'Remi') do |user|
|
7
|
+
# puts user.inspect # => #<UserPresenter object=#<User name="Remi>>
|
8
|
+
# puts user.name # => Remi
|
9
|
+
# end
|
10
|
+
def present(object, klass = nil, &blk)
|
11
|
+
return object.map { |o| present(o, klass, &blk) } if object.respond_to?(:to_a)
|
12
|
+
|
13
|
+
klass ||= "#{object.class}Presenter".constantize
|
14
|
+
presenter = klass.new(object, self)
|
15
|
+
yield presenter if block_given?
|
16
|
+
|
17
|
+
presenter
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
data/lib/bourgeois.rb
ADDED
metadata
ADDED
@@ -0,0 +1,127 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: bourgeois
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
prerelease:
|
6
|
+
platform: ruby
|
7
|
+
authors:
|
8
|
+
- Rémi Prévost
|
9
|
+
autorequire:
|
10
|
+
bindir: bin
|
11
|
+
cert_chain: []
|
12
|
+
date: 2013-06-27 00:00:00.000000000 Z
|
13
|
+
dependencies:
|
14
|
+
- !ruby/object:Gem::Dependency
|
15
|
+
name: bundler
|
16
|
+
requirement: !ruby/object:Gem::Requirement
|
17
|
+
none: false
|
18
|
+
requirements:
|
19
|
+
- - ~>
|
20
|
+
- !ruby/object:Gem::Version
|
21
|
+
version: '1.3'
|
22
|
+
type: :development
|
23
|
+
prerelease: false
|
24
|
+
version_requirements: !ruby/object:Gem::Requirement
|
25
|
+
none: false
|
26
|
+
requirements:
|
27
|
+
- - ~>
|
28
|
+
- !ruby/object:Gem::Version
|
29
|
+
version: '1.3'
|
30
|
+
- !ruby/object:Gem::Dependency
|
31
|
+
name: rake
|
32
|
+
requirement: !ruby/object:Gem::Requirement
|
33
|
+
none: false
|
34
|
+
requirements:
|
35
|
+
- - ! '>='
|
36
|
+
- !ruby/object:Gem::Version
|
37
|
+
version: '0'
|
38
|
+
type: :development
|
39
|
+
prerelease: false
|
40
|
+
version_requirements: !ruby/object:Gem::Requirement
|
41
|
+
none: false
|
42
|
+
requirements:
|
43
|
+
- - ! '>='
|
44
|
+
- !ruby/object:Gem::Version
|
45
|
+
version: '0'
|
46
|
+
- !ruby/object:Gem::Dependency
|
47
|
+
name: activemodel
|
48
|
+
requirement: !ruby/object:Gem::Requirement
|
49
|
+
none: false
|
50
|
+
requirements:
|
51
|
+
- - ! '>='
|
52
|
+
- !ruby/object:Gem::Version
|
53
|
+
version: 3.0.0
|
54
|
+
type: :runtime
|
55
|
+
prerelease: false
|
56
|
+
version_requirements: !ruby/object:Gem::Requirement
|
57
|
+
none: false
|
58
|
+
requirements:
|
59
|
+
- - ! '>='
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: 3.0.0
|
62
|
+
- !ruby/object:Gem::Dependency
|
63
|
+
name: actionpack
|
64
|
+
requirement: !ruby/object:Gem::Requirement
|
65
|
+
none: false
|
66
|
+
requirements:
|
67
|
+
- - ! '>='
|
68
|
+
- !ruby/object:Gem::Version
|
69
|
+
version: 3.0.0
|
70
|
+
type: :runtime
|
71
|
+
prerelease: false
|
72
|
+
version_requirements: !ruby/object:Gem::Requirement
|
73
|
+
none: false
|
74
|
+
requirements:
|
75
|
+
- - ! '>='
|
76
|
+
- !ruby/object:Gem::Version
|
77
|
+
version: 3.0.0
|
78
|
+
description: ''
|
79
|
+
email:
|
80
|
+
- rprevost@mirego.com
|
81
|
+
executables: []
|
82
|
+
extensions: []
|
83
|
+
extra_rdoc_files: []
|
84
|
+
files:
|
85
|
+
- .gitignore
|
86
|
+
- Gemfile
|
87
|
+
- LICENSE.md
|
88
|
+
- README.md
|
89
|
+
- Rakefile
|
90
|
+
- bourgeois.gemspec
|
91
|
+
- lib/bourgeois.rb
|
92
|
+
- lib/bourgeois/presenter.rb
|
93
|
+
- lib/bourgeois/railtie.rb
|
94
|
+
- lib/bourgeois/version.rb
|
95
|
+
- lib/bourgeois/view_helper.rb
|
96
|
+
homepage: https://github.com/mirego/bourgeois
|
97
|
+
licenses:
|
98
|
+
- BSD 3-Clause
|
99
|
+
post_install_message:
|
100
|
+
rdoc_options: []
|
101
|
+
require_paths:
|
102
|
+
- lib
|
103
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
104
|
+
none: false
|
105
|
+
requirements:
|
106
|
+
- - ! '>='
|
107
|
+
- !ruby/object:Gem::Version
|
108
|
+
version: '0'
|
109
|
+
segments:
|
110
|
+
- 0
|
111
|
+
hash: 4543301259511540129
|
112
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
113
|
+
none: false
|
114
|
+
requirements:
|
115
|
+
- - ! '>='
|
116
|
+
- !ruby/object:Gem::Version
|
117
|
+
version: '0'
|
118
|
+
segments:
|
119
|
+
- 0
|
120
|
+
hash: 4543301259511540129
|
121
|
+
requirements: []
|
122
|
+
rubyforge_project:
|
123
|
+
rubygems_version: 1.8.23
|
124
|
+
signing_key:
|
125
|
+
specification_version: 3
|
126
|
+
summary: ''
|
127
|
+
test_files: []
|