u_presenter 1.0.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +9 -0
- data/.rspec +2 -0
- data/.travis.yml +3 -0
- data/CODE_OF_CONDUCT.md +13 -0
- data/Gemfile +4 -0
- data/LICENSE.txt +21 -0
- data/README.md +85 -0
- data/Rakefile +1 -0
- data/bin/console +14 -0
- data/bin/setup +7 -0
- data/lib/u_presenter.rb +3 -0
- data/lib/u_presenter/base.rb +19 -0
- data/lib/u_presenter/collection_base.rb +28 -0
- data/lib/u_presenter/version.rb +3 -0
- data/u_presenter.gemspec +26 -0
- metadata +116 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: c1223b6add747ad9d7548877748f8bdb6924df51
|
4
|
+
data.tar.gz: b0f5d26665787efb8b89a317a6457e403e216787
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 523661fd3b82b7aa784f3269a8f3e92b7a24469bcef510aa22e9f9e50bfc7e4019187e4bfa002940e83deeeaab841f93059a4c2c2a24ac4ad07728ad6331183c
|
7
|
+
data.tar.gz: 0cfc78cb117bf7dcbf0e068ef58d6600a9210b42b70e1239fe6b24fb0ad4eb205c8217211d4efb17c42bd9985b49e8f85cfa27172f262cf8fc14bd8c5e4a82c3
|
data/.gitignore
ADDED
data/.rspec
ADDED
data/.travis.yml
ADDED
data/CODE_OF_CONDUCT.md
ADDED
@@ -0,0 +1,13 @@
|
|
1
|
+
# Contributor Code of Conduct
|
2
|
+
|
3
|
+
As contributors and maintainers of this project, we pledge to respect all people who contribute through reporting issues, posting feature requests, updating documentation, submitting pull requests or patches, and other activities.
|
4
|
+
|
5
|
+
We are committed to making participation in this project a harassment-free experience for everyone, regardless of level of experience, gender, gender identity and expression, sexual orientation, disability, personal appearance, body size, race, age, or religion.
|
6
|
+
|
7
|
+
Examples of unacceptable behavior by participants include the use of sexual language or imagery, derogatory comments or personal attacks, trolling, public or private harassment, insults, or other unprofessional conduct.
|
8
|
+
|
9
|
+
Project maintainers have the right and responsibility to remove, edit, or reject comments, commits, code, wiki edits, issues, and other contributions that are not aligned to this Code of Conduct. Project maintainers who do not follow the Code of Conduct may be removed from the project team.
|
10
|
+
|
11
|
+
Instances of abusive, harassing, or otherwise unacceptable behavior may be reported by opening an issue or contacting one or more of the project maintainers.
|
12
|
+
|
13
|
+
This Code of Conduct is adapted from the [Contributor Covenant](http:contributor-covenant.org), version 1.0.0, available at [http://contributor-covenant.org/version/1/0/0/](http://contributor-covenant.org/version/1/0/0/)
|
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
The MIT License (MIT)
|
2
|
+
|
3
|
+
Copyright (c) 2015 Nick Savrov
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
7
|
+
in the Software without restriction, including without limitation the rights
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
10
|
+
furnished to do so, subject to the following conditions:
|
11
|
+
|
12
|
+
The above copyright notice and this permission notice shall be included in
|
13
|
+
all copies or substantial portions of the Software.
|
14
|
+
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
21
|
+
THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,85 @@
|
|
1
|
+
# UPresenter
|
2
|
+
|
3
|
+
Simple Presenter for your Rails App.
|
4
|
+
|
5
|
+
## Why not use other gems?
|
6
|
+
|
7
|
+
All gems is good, but we just need to have a simple presenter layer without a lot of magic.
|
8
|
+
UPresenter - solved our problem.
|
9
|
+
|
10
|
+
## Installation
|
11
|
+
|
12
|
+
Add this line to your application's Gemfile:
|
13
|
+
|
14
|
+
```ruby
|
15
|
+
gem 'u_presenter'
|
16
|
+
```
|
17
|
+
|
18
|
+
And then execute:
|
19
|
+
|
20
|
+
$ bundle
|
21
|
+
|
22
|
+
Or install it yourself as:
|
23
|
+
|
24
|
+
$ gem install u_presenter
|
25
|
+
|
26
|
+
## Usage
|
27
|
+
|
28
|
+
Let's create your first presenter for Article model.
|
29
|
+
|
30
|
+
$ mkdir app/presenters/article_presenter.rb
|
31
|
+
|
32
|
+
And put this in your class:
|
33
|
+
|
34
|
+
```ruby
|
35
|
+
class ArticlePresenter < UPresenter::Base
|
36
|
+
def id_humanize
|
37
|
+
"Article id: #{object.id}"
|
38
|
+
end
|
39
|
+
end
|
40
|
+
```
|
41
|
+
|
42
|
+
Now let's use this presenter:
|
43
|
+
|
44
|
+
```ruby
|
45
|
+
@article = ArticlePresenter.present(Article.last)
|
46
|
+
|
47
|
+
@article.id_humanize # your presenter method works fine
|
48
|
+
@article.created_at # and method from Model also works fine
|
49
|
+
```
|
50
|
+
|
51
|
+
## What about collection?
|
52
|
+
|
53
|
+
To present collection you can do this:
|
54
|
+
|
55
|
+
```ruby
|
56
|
+
@articles = ArticlePresenter.present_collection(current_user.articles)
|
57
|
+
@articles.presented.first.id_humanize # just use presented collection to show record
|
58
|
+
```
|
59
|
+
|
60
|
+
Why we use different method in this case? Just for simplicity. Because now, if you use Kaminari
|
61
|
+
pagination you can easy get access to all methods, without extra delegation setup:
|
62
|
+
|
63
|
+
```ruby
|
64
|
+
@articles.presented.each do |article|
|
65
|
+
@article.id_humanize
|
66
|
+
end
|
67
|
+
|
68
|
+
@article.current_page
|
69
|
+
```
|
70
|
+
|
71
|
+
## Helpers in Presenter
|
72
|
+
|
73
|
+
To use helper methods inside Presenter you just need to add `view_context`:
|
74
|
+
|
75
|
+
```ruby
|
76
|
+
@article = ArticlePresenter.present_collection(article, view_context)
|
77
|
+
```
|
78
|
+
|
79
|
+
## Contributing
|
80
|
+
|
81
|
+
1. Fork it ( https://github.com/[my-github-username]/u_presenter/fork )
|
82
|
+
2. Create your feature branch (`git checkout -b my-new-feature`)
|
83
|
+
3. Commit your changes (`git commit -am 'Add some feature'`)
|
84
|
+
4. Push to the branch (`git push origin my-new-feature`)
|
85
|
+
5. Create a new Pull Request
|
data/Rakefile
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
require "bundler/gem_tasks"
|
data/bin/console
ADDED
@@ -0,0 +1,14 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require "bundler/setup"
|
4
|
+
require "u_presenter"
|
5
|
+
|
6
|
+
# You can add fixtures and/or initialization code here to make experimenting
|
7
|
+
# with your gem easier. You can also use a different console, if you like.
|
8
|
+
|
9
|
+
# (If you use this, don't forget to add pry to your Gemfile!)
|
10
|
+
# require "pry"
|
11
|
+
# Pry.start
|
12
|
+
|
13
|
+
require "irb"
|
14
|
+
IRB.start
|
data/bin/setup
ADDED
data/lib/u_presenter.rb
ADDED
@@ -0,0 +1,19 @@
|
|
1
|
+
module UPresenter
|
2
|
+
class Base < SimpleDelegator
|
3
|
+
attr_reader :object, :view_context
|
4
|
+
|
5
|
+
def initialize(object, view_context = nil)
|
6
|
+
@object = object
|
7
|
+
@view_context = view_context
|
8
|
+
super(@object)
|
9
|
+
end
|
10
|
+
|
11
|
+
class << self
|
12
|
+
alias_method :present, :new
|
13
|
+
|
14
|
+
def present_collection(collection, view_context)
|
15
|
+
CollectionBase.present(collection, self, view_context)
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
@@ -0,0 +1,28 @@
|
|
1
|
+
module UPresenter
|
2
|
+
class CollectionBase < SimpleDelegator
|
3
|
+
attr_reader :collection
|
4
|
+
|
5
|
+
def initialize(collection, presenter_class, view_context = nil)
|
6
|
+
@collection = collection
|
7
|
+
@presenter_class = presenter_class
|
8
|
+
@view_context = view_context
|
9
|
+
super(@collection)
|
10
|
+
end
|
11
|
+
|
12
|
+
def presented
|
13
|
+
@presented ||= present_collection
|
14
|
+
end
|
15
|
+
|
16
|
+
class << self
|
17
|
+
alias_method :present, :new
|
18
|
+
end
|
19
|
+
|
20
|
+
private
|
21
|
+
|
22
|
+
def present_collection
|
23
|
+
@collection.map do |object|
|
24
|
+
@presenter_class.present(object, @view_context)
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|
data/u_presenter.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 'u_presenter/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = "u_presenter"
|
8
|
+
spec.version = UPresenter::VERSION
|
9
|
+
spec.authors = ["Nick Savrov"]
|
10
|
+
spec.email = ["savroff@gmail.com"]
|
11
|
+
|
12
|
+
spec.summary = %q{Add simple presenter Layer to your Rails App}
|
13
|
+
spec.description = %q{Simple Presenter for Rails App}
|
14
|
+
spec.homepage = "https://github.com/savroff/u_presenter"
|
15
|
+
spec.license = "MIT"
|
16
|
+
|
17
|
+
spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
|
18
|
+
spec.bindir = "exe"
|
19
|
+
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
20
|
+
spec.require_paths = ["lib"]
|
21
|
+
|
22
|
+
spec.add_development_dependency "bundler", "~> 1.9"
|
23
|
+
spec.add_development_dependency "rake", "~> 10.0"
|
24
|
+
spec.add_development_dependency "rspec", "~> 3.4.0"
|
25
|
+
spec.add_development_dependency "pry", "~> 0.10.0"
|
26
|
+
end
|
metadata
ADDED
@@ -0,0 +1,116 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: u_presenter
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 1.0.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Nick Savrov
|
8
|
+
autorequire:
|
9
|
+
bindir: exe
|
10
|
+
cert_chain: []
|
11
|
+
date: 2015-11-29 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: bundler
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - "~>"
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '1.9'
|
20
|
+
type: :development
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '1.9'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: rake
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - "~>"
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '10.0'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - "~>"
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '10.0'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: rspec
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - "~>"
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: 3.4.0
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - "~>"
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: 3.4.0
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: pry
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - "~>"
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: 0.10.0
|
62
|
+
type: :development
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - "~>"
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: 0.10.0
|
69
|
+
description: Simple Presenter for Rails App
|
70
|
+
email:
|
71
|
+
- savroff@gmail.com
|
72
|
+
executables: []
|
73
|
+
extensions: []
|
74
|
+
extra_rdoc_files: []
|
75
|
+
files:
|
76
|
+
- ".gitignore"
|
77
|
+
- ".rspec"
|
78
|
+
- ".travis.yml"
|
79
|
+
- CODE_OF_CONDUCT.md
|
80
|
+
- Gemfile
|
81
|
+
- LICENSE.txt
|
82
|
+
- README.md
|
83
|
+
- Rakefile
|
84
|
+
- bin/console
|
85
|
+
- bin/setup
|
86
|
+
- lib/u_presenter.rb
|
87
|
+
- lib/u_presenter/base.rb
|
88
|
+
- lib/u_presenter/collection_base.rb
|
89
|
+
- lib/u_presenter/version.rb
|
90
|
+
- u_presenter.gemspec
|
91
|
+
homepage: https://github.com/savroff/u_presenter
|
92
|
+
licenses:
|
93
|
+
- MIT
|
94
|
+
metadata: {}
|
95
|
+
post_install_message:
|
96
|
+
rdoc_options: []
|
97
|
+
require_paths:
|
98
|
+
- lib
|
99
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
100
|
+
requirements:
|
101
|
+
- - ">="
|
102
|
+
- !ruby/object:Gem::Version
|
103
|
+
version: '0'
|
104
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
105
|
+
requirements:
|
106
|
+
- - ">="
|
107
|
+
- !ruby/object:Gem::Version
|
108
|
+
version: '0'
|
109
|
+
requirements: []
|
110
|
+
rubyforge_project:
|
111
|
+
rubygems_version: 2.4.5
|
112
|
+
signing_key:
|
113
|
+
specification_version: 4
|
114
|
+
summary: Add simple presenter Layer to your Rails App
|
115
|
+
test_files: []
|
116
|
+
has_rdoc:
|