presenters 0.1.0

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.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 69f95c182bc6eda82898058fb35217c4d43048ab
4
+ data.tar.gz: 23d801295ba2931095867ff4c14c96344f9143ac
5
+ SHA512:
6
+ metadata.gz: 99fccf469f532451a20525623a4b632a1cbb5c53c025782fc0390f0e61b3309109b32edbc5b21ea686f076118506d7e726448c5833bac6f2d14ddf9af699f9a4
7
+ data.tar.gz: 3c2d2291cff69d3c2a69c6bdbab71636cdf17764c36475741c6d08d2e173083a07ec606c0650e40c22c69be5dcde833ab24e8fde80659ad9a2dd559a1b2b669e
data/.gitignore ADDED
@@ -0,0 +1,9 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /Gemfile.lock
4
+ /_yardoc/
5
+ /coverage/
6
+ /doc/
7
+ /pkg/
8
+ /spec/reports/
9
+ /tmp/
data/.rspec ADDED
@@ -0,0 +1,2 @@
1
+ --color
2
+ --require spec_helper
data/.travis.yml ADDED
@@ -0,0 +1,4 @@
1
+ language: ruby
2
+ rvm:
3
+ - 2.2.2
4
+ before_install: gem install bundler
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in presenters.gemspec
4
+ gemspec
data/LICENSE.txt ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2015 Chen Yi-Cyuan
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,68 @@
1
+ # Presenters
2
+
3
+ A simple presenter pattern for ruby. It also can work in rails. This is based on [Presenters in Rails](http://nithinbekal.com/posts/rails-presenters/)
4
+
5
+ ## Installation
6
+
7
+ Add this line to your application's Gemfile:
8
+
9
+ ```ruby
10
+ gem 'presenters'
11
+ ```
12
+
13
+ And then execute:
14
+
15
+ bundle
16
+
17
+ Or install it yourself as:
18
+
19
+ gem install presenters
20
+
21
+ ## Usage
22
+
23
+ ### Create presenter class
24
+ Assume you have a class named Post, you can create PostPresenter.
25
+ ```Ruby
26
+ class PostPresenter < Presenter
27
+ def title
28
+ super || 'No Title'
29
+ end
30
+ end
31
+ ```
32
+ And you can wrap object like this:
33
+ ```Ruby
34
+ post = Post.new :title => nil, :content => "My Content"
35
+ presenter = PostPresenter.new post
36
+ presenter.title # "No Title"
37
+ # delegate to Post
38
+ presenter.content # "My Content"
39
+ ```
40
+ You can use `present` and `present_each` method to wrap objects. It will find presenter class in the same name. (Eq: Post => PostPresenter)
41
+ ```Ruby
42
+ present(@post) do |post|
43
+ # do something...
44
+ end
45
+
46
+ present_each(@posts) do |post|
47
+ # do something...
48
+ end
49
+ ```Ruby
50
+ You can specify presenter, too.
51
+ ```Ruby
52
+ present(@post, CustomPresenter) do |post|
53
+ # do something...
54
+ end
55
+
56
+ present_each(@posts, CustomPresenter) do |post|
57
+ # do something...
58
+ end
59
+ ```Ruby
60
+ You can use the helper in the view in rails application.
61
+
62
+ ## License
63
+
64
+ The gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).
65
+
66
+ ## Contact
67
+ The project's website is located at https://github.com/emn178/presenters
68
+ Author: emn178@gmail.com
data/Rakefile ADDED
@@ -0,0 +1,6 @@
1
+ require "bundler/gem_tasks"
2
+ require "rspec/core/rake_task"
3
+
4
+ RSpec::Core::RakeTask.new(:spec)
5
+
6
+ task :default => :spec
@@ -0,0 +1,16 @@
1
+ module Presenters
2
+ module Helper
3
+ def present(instance, class_type = nil, &block)
4
+ class_type = class_type || Object.const_get("#{instance.class}Presenter")
5
+ presenter = class_type.new(instance)
6
+ yield(presenter) if block_given?
7
+ return presenter
8
+ end
9
+
10
+ def present_each(instances, class_type = nil, &block)
11
+ instances.each do |instance|
12
+ present(instance, class_type, &block)
13
+ end
14
+ end
15
+ end
16
+ end
@@ -0,0 +1,4 @@
1
+ module Presenters
2
+ class Presenter < SimpleDelegator
3
+ end
4
+ end
@@ -0,0 +1,3 @@
1
+ module Presenters
2
+ VERSION = "0.1.0"
3
+ end
data/lib/presenters.rb ADDED
@@ -0,0 +1,18 @@
1
+ require "presenters/version"
2
+ require "presenters/presenter"
3
+ require "presenters/helper"
4
+
5
+ module Presenters
6
+ if defined?(::Rails::Engine)
7
+ class Engine < ::Rails::Engine
8
+ initializer "presenters" do
9
+ ActiveSupport.on_load(:action_view) do
10
+ include Presenters::Helper
11
+ end
12
+ Presenter.include ActionView::Helpers
13
+ Presenter.include Rails.application.routes.url_helpers
14
+ end
15
+ end
16
+ end
17
+ end
18
+ Presenter = Presenters::Presenter
@@ -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 'presenters/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "presenters"
8
+ spec.version = Presenters::VERSION
9
+ spec.authors = ["Chen Yi-Cyuan"]
10
+ spec.email = ["emn178@gmail.com"]
11
+
12
+ spec.summary = %q{A simple presenter pattern for ruby. It also can work in rails.}
13
+ spec.description = %q{A simple presenter pattern for ruby. It also can work in rails.}
14
+ spec.homepage = "https://github.com/emn178/presenters"
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.10"
23
+ spec.add_development_dependency "rake", "~> 10.0"
24
+ spec.add_development_dependency "rspec"
25
+ spec.add_development_dependency "rspec-its"
26
+ end
metadata ADDED
@@ -0,0 +1,112 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: presenters
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Chen Yi-Cyuan
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2015-08-23 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.10'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '1.10'
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: '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'
55
+ - !ruby/object:Gem::Dependency
56
+ name: rspec-its
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - ">="
60
+ - !ruby/object:Gem::Version
61
+ version: '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'
69
+ description: A simple presenter pattern for ruby. It also can work in rails.
70
+ email:
71
+ - emn178@gmail.com
72
+ executables: []
73
+ extensions: []
74
+ extra_rdoc_files: []
75
+ files:
76
+ - ".gitignore"
77
+ - ".rspec"
78
+ - ".travis.yml"
79
+ - Gemfile
80
+ - LICENSE.txt
81
+ - README.md
82
+ - Rakefile
83
+ - lib/presenters.rb
84
+ - lib/presenters/helper.rb
85
+ - lib/presenters/presenter.rb
86
+ - lib/presenters/version.rb
87
+ - presenters.gemspec
88
+ homepage: https://github.com/emn178/presenters
89
+ licenses:
90
+ - MIT
91
+ metadata: {}
92
+ post_install_message:
93
+ rdoc_options: []
94
+ require_paths:
95
+ - lib
96
+ required_ruby_version: !ruby/object:Gem::Requirement
97
+ requirements:
98
+ - - ">="
99
+ - !ruby/object:Gem::Version
100
+ version: '0'
101
+ required_rubygems_version: !ruby/object:Gem::Requirement
102
+ requirements:
103
+ - - ">="
104
+ - !ruby/object:Gem::Version
105
+ version: '0'
106
+ requirements: []
107
+ rubyforge_project:
108
+ rubygems_version: 2.4.5
109
+ signing_key:
110
+ specification_version: 4
111
+ summary: A simple presenter pattern for ruby. It also can work in rails.
112
+ test_files: []