actionpresenter 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.document +5 -0
- data/Gemfile +12 -0
- data/Gemfile.lock +164 -0
- data/LICENSE.txt +20 -0
- data/README.rdoc +21 -0
- data/Rakefile +38 -0
- data/VERSION +1 -0
- data/actionpresenter.gemspec +71 -0
- data/lib/action_presenter.rb +14 -0
- data/lib/action_presenter/base.rb +59 -0
- data/lib/action_presenter/helpers.rb +22 -0
- data/lib/action_presenter/template_delegation.rb +23 -0
- data/lib/actionpresenter.rb +1 -0
- data/spec/helpers/helpers_spec.rb +52 -0
- data/spec/presenters/.keep +0 -0
- data/spec/spec_helper.rb +9 -0
- data/spec/support/faked_view_context.rb +3 -0
- data/spec/support/models.rb +7 -0
- data/spec/support/presenters.rb +7 -0
- metadata +134 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 0d8b47e1b57874329395b699e63f2e0f98f45a28
|
4
|
+
data.tar.gz: 304807c82fee9a63015e74b9cf49f78c18e50d14
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 22ec512986082c67bf4a8370f0f158462716b72b89d3198e69c815f3cee4009a765859af99568f56d4a8115b40807d6a5ab853c0615103171cde543e3aa88760
|
7
|
+
data.tar.gz: 5825f13f5edf01adcd9c270ce07c78b431f2c8249b0581d770e9922a2898efe14481645bd24741d7a4793b3e1a6a2c8786f36e900ee36e1ee76bffe2f0d300dc
|
data/.document
ADDED
data/Gemfile
ADDED
@@ -0,0 +1,12 @@
|
|
1
|
+
source 'http://rubygems.org'
|
2
|
+
|
3
|
+
gem 'rails', '~> 4.0'
|
4
|
+
|
5
|
+
# Add dependencies to develop your gem here.
|
6
|
+
# Include everything needed to run rake, tests, features, etc.
|
7
|
+
group :development do
|
8
|
+
gem 'bundler', '~> 1.0'
|
9
|
+
gem 'jeweler', '~> 2.0.1'
|
10
|
+
gem 'rspec-rails', '~> 3.0'
|
11
|
+
gem 'pry-byebug'
|
12
|
+
end
|
data/Gemfile.lock
ADDED
@@ -0,0 +1,164 @@
|
|
1
|
+
GEM
|
2
|
+
remote: http://rubygems.org/
|
3
|
+
specs:
|
4
|
+
actionmailer (4.1.8)
|
5
|
+
actionpack (= 4.1.8)
|
6
|
+
actionview (= 4.1.8)
|
7
|
+
mail (~> 2.5, >= 2.5.4)
|
8
|
+
actionpack (4.1.8)
|
9
|
+
actionview (= 4.1.8)
|
10
|
+
activesupport (= 4.1.8)
|
11
|
+
rack (~> 1.5.2)
|
12
|
+
rack-test (~> 0.6.2)
|
13
|
+
actionview (4.1.8)
|
14
|
+
activesupport (= 4.1.8)
|
15
|
+
builder (~> 3.1)
|
16
|
+
erubis (~> 2.7.0)
|
17
|
+
activemodel (4.1.8)
|
18
|
+
activesupport (= 4.1.8)
|
19
|
+
builder (~> 3.1)
|
20
|
+
activerecord (4.1.8)
|
21
|
+
activemodel (= 4.1.8)
|
22
|
+
activesupport (= 4.1.8)
|
23
|
+
arel (~> 5.0.0)
|
24
|
+
activesupport (4.1.8)
|
25
|
+
i18n (~> 0.6, >= 0.6.9)
|
26
|
+
json (~> 1.7, >= 1.7.7)
|
27
|
+
minitest (~> 5.1)
|
28
|
+
thread_safe (~> 0.1)
|
29
|
+
tzinfo (~> 1.1)
|
30
|
+
addressable (2.3.6)
|
31
|
+
arel (5.0.1.20140414130214)
|
32
|
+
builder (3.2.2)
|
33
|
+
byebug (3.5.1)
|
34
|
+
columnize (~> 0.8)
|
35
|
+
debugger-linecache (~> 1.2)
|
36
|
+
slop (~> 3.6)
|
37
|
+
coderay (1.1.0)
|
38
|
+
columnize (0.8.9)
|
39
|
+
debugger-linecache (1.2.0)
|
40
|
+
descendants_tracker (0.0.4)
|
41
|
+
thread_safe (~> 0.3, >= 0.3.1)
|
42
|
+
diff-lcs (1.2.5)
|
43
|
+
erubis (2.7.0)
|
44
|
+
faraday (0.9.0)
|
45
|
+
multipart-post (>= 1.2, < 3)
|
46
|
+
git (1.2.8)
|
47
|
+
github_api (0.12.2)
|
48
|
+
addressable (~> 2.3)
|
49
|
+
descendants_tracker (~> 0.0.4)
|
50
|
+
faraday (~> 0.8, < 0.10)
|
51
|
+
hashie (>= 3.3)
|
52
|
+
multi_json (>= 1.7.5, < 2.0)
|
53
|
+
nokogiri (~> 1.6.3)
|
54
|
+
oauth2
|
55
|
+
hashie (3.3.2)
|
56
|
+
highline (1.6.21)
|
57
|
+
hike (1.2.3)
|
58
|
+
i18n (0.6.11)
|
59
|
+
jeweler (2.0.1)
|
60
|
+
builder
|
61
|
+
bundler (>= 1.0)
|
62
|
+
git (>= 1.2.5)
|
63
|
+
github_api
|
64
|
+
highline (>= 1.6.15)
|
65
|
+
nokogiri (>= 1.5.10)
|
66
|
+
rake
|
67
|
+
rdoc
|
68
|
+
json (1.8.1)
|
69
|
+
jwt (1.2.0)
|
70
|
+
mail (2.6.3)
|
71
|
+
mime-types (>= 1.16, < 3)
|
72
|
+
method_source (0.8.2)
|
73
|
+
mime-types (2.4.3)
|
74
|
+
mini_portile (0.6.1)
|
75
|
+
minitest (5.4.3)
|
76
|
+
multi_json (1.10.1)
|
77
|
+
multi_xml (0.5.5)
|
78
|
+
multipart-post (2.0.0)
|
79
|
+
nokogiri (1.6.5)
|
80
|
+
mini_portile (~> 0.6.0)
|
81
|
+
nokogiri (1.6.5-x64-mingw32)
|
82
|
+
mini_portile (~> 0.6.0)
|
83
|
+
oauth2 (1.0.0)
|
84
|
+
faraday (>= 0.8, < 0.10)
|
85
|
+
jwt (~> 1.0)
|
86
|
+
multi_json (~> 1.3)
|
87
|
+
multi_xml (~> 0.5)
|
88
|
+
rack (~> 1.2)
|
89
|
+
pry (0.10.1)
|
90
|
+
coderay (~> 1.1.0)
|
91
|
+
method_source (~> 0.8.1)
|
92
|
+
slop (~> 3.4)
|
93
|
+
pry (0.10.1-x64-mingw32)
|
94
|
+
coderay (~> 1.1.0)
|
95
|
+
method_source (~> 0.8.1)
|
96
|
+
slop (~> 3.4)
|
97
|
+
win32console (~> 1.3)
|
98
|
+
pry-byebug (2.0.0)
|
99
|
+
byebug (~> 3.4)
|
100
|
+
pry (~> 0.10)
|
101
|
+
rack (1.5.2)
|
102
|
+
rack-test (0.6.2)
|
103
|
+
rack (>= 1.0)
|
104
|
+
rails (4.1.8)
|
105
|
+
actionmailer (= 4.1.8)
|
106
|
+
actionpack (= 4.1.8)
|
107
|
+
actionview (= 4.1.8)
|
108
|
+
activemodel (= 4.1.8)
|
109
|
+
activerecord (= 4.1.8)
|
110
|
+
activesupport (= 4.1.8)
|
111
|
+
bundler (>= 1.3.0, < 2.0)
|
112
|
+
railties (= 4.1.8)
|
113
|
+
sprockets-rails (~> 2.0)
|
114
|
+
railties (4.1.8)
|
115
|
+
actionpack (= 4.1.8)
|
116
|
+
activesupport (= 4.1.8)
|
117
|
+
rake (>= 0.8.7)
|
118
|
+
thor (>= 0.18.1, < 2.0)
|
119
|
+
rake (10.4.1)
|
120
|
+
rdoc (4.1.2)
|
121
|
+
json (~> 1.4)
|
122
|
+
rspec-core (3.1.7)
|
123
|
+
rspec-support (~> 3.1.0)
|
124
|
+
rspec-expectations (3.1.2)
|
125
|
+
diff-lcs (>= 1.2.0, < 2.0)
|
126
|
+
rspec-support (~> 3.1.0)
|
127
|
+
rspec-mocks (3.1.3)
|
128
|
+
rspec-support (~> 3.1.0)
|
129
|
+
rspec-rails (3.1.0)
|
130
|
+
actionpack (>= 3.0)
|
131
|
+
activesupport (>= 3.0)
|
132
|
+
railties (>= 3.0)
|
133
|
+
rspec-core (~> 3.1.0)
|
134
|
+
rspec-expectations (~> 3.1.0)
|
135
|
+
rspec-mocks (~> 3.1.0)
|
136
|
+
rspec-support (~> 3.1.0)
|
137
|
+
rspec-support (3.1.2)
|
138
|
+
slop (3.6.0)
|
139
|
+
sprockets (2.12.3)
|
140
|
+
hike (~> 1.2)
|
141
|
+
multi_json (~> 1.0)
|
142
|
+
rack (~> 1.0)
|
143
|
+
tilt (~> 1.1, != 1.3.0)
|
144
|
+
sprockets-rails (2.2.2)
|
145
|
+
actionpack (>= 3.0)
|
146
|
+
activesupport (>= 3.0)
|
147
|
+
sprockets (>= 2.8, < 4.0)
|
148
|
+
thor (0.19.1)
|
149
|
+
thread_safe (0.3.4)
|
150
|
+
tilt (1.4.1)
|
151
|
+
tzinfo (1.2.2)
|
152
|
+
thread_safe (~> 0.1)
|
153
|
+
win32console (1.3.2)
|
154
|
+
|
155
|
+
PLATFORMS
|
156
|
+
ruby
|
157
|
+
x64-mingw32
|
158
|
+
|
159
|
+
DEPENDENCIES
|
160
|
+
bundler (~> 1.0)
|
161
|
+
jeweler (~> 2.0.1)
|
162
|
+
pry-byebug
|
163
|
+
rails (~> 4.0)
|
164
|
+
rspec-rails (~> 3.0)
|
data/LICENSE.txt
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
Copyright (c) 2014 Tobias Casper
|
2
|
+
|
3
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
4
|
+
a copy of this software and associated documentation files (the
|
5
|
+
"Software"), to deal in the Software without restriction, including
|
6
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
7
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
8
|
+
permit persons to whom the Software is furnished to do so, subject to
|
9
|
+
the following conditions:
|
10
|
+
|
11
|
+
The above copyright notice and this permission notice shall be
|
12
|
+
included in all copies or substantial portions of the Software.
|
13
|
+
|
14
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
15
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
16
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
17
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
18
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
19
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
20
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.rdoc
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
= ActionPresenter
|
2
|
+
|
3
|
+
{<img src="https://codeclimate.com/github/tlux/actionpresenter/badges/gpa.svg" />}[https://codeclimate.com/github/tlux/actionpresenter]
|
4
|
+
|
5
|
+
A lightweight presenter implementation for Ruby on Rails.
|
6
|
+
|
7
|
+
== Contributing to actionpresenter
|
8
|
+
|
9
|
+
* Check out the latest master to make sure the feature hasn't been implemented or the bug hasn't been fixed yet.
|
10
|
+
* Check out the issue tracker to make sure someone already hasn't requested it and/or contributed it.
|
11
|
+
* Fork the project.
|
12
|
+
* Start a feature/bugfix branch.
|
13
|
+
* Commit and push until you are happy with your contribution.
|
14
|
+
* Make sure to add tests for it. This is important so I don't break it in a future version unintentionally.
|
15
|
+
* Please try not to mess with the Rakefile, version, or history. If you want to have your own version, or is otherwise necessary, that is fine, but please isolate to its own commit so I can cherry-pick around it.
|
16
|
+
|
17
|
+
== Copyright
|
18
|
+
|
19
|
+
Copyright (c) 2014 Tobias Casper. See LICENSE.txt for
|
20
|
+
further details.
|
21
|
+
|
data/Rakefile
ADDED
@@ -0,0 +1,38 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
|
3
|
+
require 'rubygems'
|
4
|
+
require 'bundler'
|
5
|
+
begin
|
6
|
+
Bundler.setup(:default, :development)
|
7
|
+
rescue Bundler::BundlerError => e
|
8
|
+
$stderr.puts e.message
|
9
|
+
$stderr.puts 'Run `bundle install` to install missing gems'
|
10
|
+
exit e.status_code
|
11
|
+
end
|
12
|
+
require 'rake'
|
13
|
+
|
14
|
+
require 'jeweler'
|
15
|
+
Jeweler::Tasks.new do |gem|
|
16
|
+
# gem is a Gem::Specification... see http://guides.rubygems.org/specification-reference/ for more options
|
17
|
+
gem.name = 'actionpresenter'
|
18
|
+
gem.homepage = 'http://github.com/tlux/actionpresenter'
|
19
|
+
gem.license = 'MIT'
|
20
|
+
gem.summary = %Q{A lightweight presenter implementation for Ruby on Rails.}
|
21
|
+
gem.description = gem.summary
|
22
|
+
gem.email = 'tobias.casper@gmail.com'
|
23
|
+
gem.authors = ['Tobias Casper']
|
24
|
+
# dependencies defined in Gemfile
|
25
|
+
end
|
26
|
+
Jeweler::RubygemsDotOrgTasks.new
|
27
|
+
|
28
|
+
task default: :spec
|
29
|
+
|
30
|
+
require 'rdoc/task'
|
31
|
+
Rake::RDocTask.new do |rdoc|
|
32
|
+
version = File.exist?('VERSION') ? File.read('VERSION') : ""
|
33
|
+
|
34
|
+
rdoc.rdoc_dir = 'rdoc'
|
35
|
+
rdoc.title = "ActionPresenter #{version}"
|
36
|
+
rdoc.rdoc_files.include('README*')
|
37
|
+
rdoc.rdoc_files.include('lib/**/*.rb')
|
38
|
+
end
|
data/VERSION
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
0.1.0
|
@@ -0,0 +1,71 @@
|
|
1
|
+
# Generated by jeweler
|
2
|
+
# DO NOT EDIT THIS FILE DIRECTLY
|
3
|
+
# Instead, edit Jeweler::Tasks in Rakefile, and run 'rake gemspec'
|
4
|
+
# -*- encoding: utf-8 -*-
|
5
|
+
# stub: actionpresenter 0.1.0 ruby lib
|
6
|
+
|
7
|
+
Gem::Specification.new do |s|
|
8
|
+
s.name = "actionpresenter"
|
9
|
+
s.version = "0.1.0"
|
10
|
+
|
11
|
+
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
12
|
+
s.require_paths = ["lib"]
|
13
|
+
s.authors = ["Tobias Casper"]
|
14
|
+
s.date = "2014-12-02"
|
15
|
+
s.description = "A lightweight presenter implementation for Ruby on Rails."
|
16
|
+
s.email = "tobias.casper@gmail.com"
|
17
|
+
s.extra_rdoc_files = [
|
18
|
+
"LICENSE.txt",
|
19
|
+
"README.rdoc"
|
20
|
+
]
|
21
|
+
s.files = [
|
22
|
+
".document",
|
23
|
+
"Gemfile",
|
24
|
+
"Gemfile.lock",
|
25
|
+
"LICENSE.txt",
|
26
|
+
"README.rdoc",
|
27
|
+
"Rakefile",
|
28
|
+
"VERSION",
|
29
|
+
"actionpresenter.gemspec",
|
30
|
+
"lib/action_presenter.rb",
|
31
|
+
"lib/action_presenter/base.rb",
|
32
|
+
"lib/action_presenter/helpers.rb",
|
33
|
+
"lib/action_presenter/template_delegation.rb",
|
34
|
+
"lib/actionpresenter.rb",
|
35
|
+
"spec/helpers/helpers_spec.rb",
|
36
|
+
"spec/presenters/.keep",
|
37
|
+
"spec/spec_helper.rb",
|
38
|
+
"spec/support/faked_view_context.rb",
|
39
|
+
"spec/support/models.rb",
|
40
|
+
"spec/support/presenters.rb"
|
41
|
+
]
|
42
|
+
s.homepage = "http://github.com/tlux/actionpresenter"
|
43
|
+
s.licenses = ["MIT"]
|
44
|
+
s.rubygems_version = "2.4.3"
|
45
|
+
s.summary = "A lightweight presenter implementation for Ruby on Rails."
|
46
|
+
|
47
|
+
if s.respond_to? :specification_version then
|
48
|
+
s.specification_version = 4
|
49
|
+
|
50
|
+
if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
|
51
|
+
s.add_runtime_dependency(%q<rails>, ["~> 4.0"])
|
52
|
+
s.add_development_dependency(%q<bundler>, ["~> 1.0"])
|
53
|
+
s.add_development_dependency(%q<jeweler>, ["~> 2.0.1"])
|
54
|
+
s.add_development_dependency(%q<rspec-rails>, ["~> 3.0"])
|
55
|
+
s.add_development_dependency(%q<pry-byebug>, [">= 0"])
|
56
|
+
else
|
57
|
+
s.add_dependency(%q<rails>, ["~> 4.0"])
|
58
|
+
s.add_dependency(%q<bundler>, ["~> 1.0"])
|
59
|
+
s.add_dependency(%q<jeweler>, ["~> 2.0.1"])
|
60
|
+
s.add_dependency(%q<rspec-rails>, ["~> 3.0"])
|
61
|
+
s.add_dependency(%q<pry-byebug>, [">= 0"])
|
62
|
+
end
|
63
|
+
else
|
64
|
+
s.add_dependency(%q<rails>, ["~> 4.0"])
|
65
|
+
s.add_dependency(%q<bundler>, ["~> 1.0"])
|
66
|
+
s.add_dependency(%q<jeweler>, ["~> 2.0.1"])
|
67
|
+
s.add_dependency(%q<rspec-rails>, ["~> 3.0"])
|
68
|
+
s.add_dependency(%q<pry-byebug>, [">= 0"])
|
69
|
+
end
|
70
|
+
end
|
71
|
+
|
@@ -0,0 +1,14 @@
|
|
1
|
+
require 'rubygems'
|
2
|
+
require 'pathname'
|
3
|
+
require 'active_support/all'
|
4
|
+
require 'action_view'
|
5
|
+
|
6
|
+
module ActionPresenter
|
7
|
+
def self.root
|
8
|
+
Pathname.new(File.expand_path('../..', __FILE__))
|
9
|
+
end
|
10
|
+
end
|
11
|
+
|
12
|
+
Dir[ActionPresenter.root.join('lib', 'action_presenter', '*.rb')].each do |filename|
|
13
|
+
require filename
|
14
|
+
end
|
@@ -0,0 +1,59 @@
|
|
1
|
+
class ActionPresenter::Base
|
2
|
+
def initialize(template, *args)
|
3
|
+
@_template = template
|
4
|
+
@options = args.extract_options!
|
5
|
+
@object = args.first
|
6
|
+
end
|
7
|
+
|
8
|
+
attr_reader :object, :options
|
9
|
+
delegate :present, to: :h
|
10
|
+
protected :present, :options
|
11
|
+
|
12
|
+
def self.presents(name)
|
13
|
+
define_method name do
|
14
|
+
self.object
|
15
|
+
end
|
16
|
+
end
|
17
|
+
|
18
|
+
def self.delegate_presented(name, options = {})
|
19
|
+
delegate_opts = options.slice(:to, :prefix, :allow_nil).reverse_merge(to: :object)
|
20
|
+
delegate name, delegate_opts
|
21
|
+
|
22
|
+
define_method "#{name}_with_presenter" do
|
23
|
+
delegated_obj = self.public_send("#{name}_without_presenter")
|
24
|
+
present delegated_obj, options.except(*delegate_opts.keys) unless delegated_obj.nil?
|
25
|
+
end
|
26
|
+
|
27
|
+
alias_method_chain name, :presenter
|
28
|
+
end
|
29
|
+
|
30
|
+
def inspect
|
31
|
+
if object.nil?
|
32
|
+
"#<#{self.class.name}>"
|
33
|
+
else
|
34
|
+
"#<#{self.class.name} object: #{object.inspect}>"
|
35
|
+
end
|
36
|
+
end
|
37
|
+
|
38
|
+
def method_missing(name, *args, &block)
|
39
|
+
if object and object.respond_to?(name, false)
|
40
|
+
object.send(name, *args, &block)
|
41
|
+
else
|
42
|
+
super
|
43
|
+
end
|
44
|
+
end
|
45
|
+
|
46
|
+
def respond_to_missing?(name, include_private = false)
|
47
|
+
(object && object.respond_to?(name, include_private)) || super
|
48
|
+
end
|
49
|
+
|
50
|
+
def to_model
|
51
|
+
object
|
52
|
+
end
|
53
|
+
|
54
|
+
protected
|
55
|
+
def template
|
56
|
+
@_template
|
57
|
+
end
|
58
|
+
alias_method :h, :template
|
59
|
+
end
|
@@ -0,0 +1,22 @@
|
|
1
|
+
require 'action_view/base'
|
2
|
+
|
3
|
+
module ActionPresenter::Helpers
|
4
|
+
def present(*args)
|
5
|
+
options = args.extract_options!
|
6
|
+
scope = Array(args.first)
|
7
|
+
object = scope.last
|
8
|
+
presenter_class = options.delete(:with) do
|
9
|
+
raise ArgumentError, 'Neither object nor presenter class specified' if object.nil?
|
10
|
+
scoped_class_name = scope.map { |item|
|
11
|
+
item.is_a?(Symbol) ? item.to_s.camelize : item.class.name
|
12
|
+
}.join('::')
|
13
|
+
"#{scoped_class_name}Presenter"
|
14
|
+
end
|
15
|
+
presenter_class = presenter_class.to_s.constantize unless presenter_class.is_a?(Class)
|
16
|
+
presenter = presenter_class.new(self, object, options)
|
17
|
+
yield(presenter) if block_given?
|
18
|
+
presenter
|
19
|
+
end
|
20
|
+
end
|
21
|
+
|
22
|
+
ActionView::Base.send :include, ActionPresenter::Helpers
|
@@ -0,0 +1,23 @@
|
|
1
|
+
module ActionPresenter::TemplateDelegation
|
2
|
+
extend ActiveSupport::Concern
|
3
|
+
|
4
|
+
included do
|
5
|
+
alias_method_chain :method_missing, :template_delegation
|
6
|
+
alias_method_chain :respond_to_missing?, :template_delegation
|
7
|
+
end
|
8
|
+
|
9
|
+
def method_missing_with_template_delegation(name, *args, &block)
|
10
|
+
if respond_to_missing_without_template_delegation?(name)
|
11
|
+
method_missing_without_template_delegation(name, *args, &block)
|
12
|
+
elsif @_template.respond_to?(name, false)
|
13
|
+
@_template.send(name, *args, &block)
|
14
|
+
else
|
15
|
+
super
|
16
|
+
end
|
17
|
+
end
|
18
|
+
|
19
|
+
def respond_to_missing_with_template_delegation?(name, include_private = false)
|
20
|
+
@_template.respond_to?(name, include_private) ||
|
21
|
+
respond_to_missing_without_template_delegation?(name, include_private)
|
22
|
+
end
|
23
|
+
end
|
@@ -0,0 +1 @@
|
|
1
|
+
require 'action_presenter'
|
@@ -0,0 +1,52 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe ActionPresenter::Helpers do
|
4
|
+
let(:helper) { FakedViewContext.new }
|
5
|
+
|
6
|
+
describe '#present' do
|
7
|
+
it 'is available in view context' do
|
8
|
+
expect(helper).to respond_to(:present)
|
9
|
+
end
|
10
|
+
|
11
|
+
it 'cannot be invoked without arguments' do
|
12
|
+
expect { helper.present }.to raise_error ArgumentError, 'Neither object nor presenter class specified'
|
13
|
+
end
|
14
|
+
|
15
|
+
it 'initializes a presenter by a given object' do
|
16
|
+
presenter = helper.present(Person.new)
|
17
|
+
expect(presenter).to be_a PersonPresenter
|
18
|
+
end
|
19
|
+
|
20
|
+
it 'fails initialization if no matching presenter class could be found' do
|
21
|
+
expect { helper.present(Location.new) }.to raise_error(/uninitialized constant/)
|
22
|
+
end
|
23
|
+
|
24
|
+
it 'initializes a presenter by a given object and presenter class' do
|
25
|
+
presenter = helper.present(Person.new, with: Admin::PersonPresenter)
|
26
|
+
expect(presenter).to be_an Admin::PersonPresenter
|
27
|
+
end
|
28
|
+
|
29
|
+
it 'initializes a presenter by a given object and presenter class name' do
|
30
|
+
presenter = helper.present(Person.new, with: 'Admin::PersonPresenter')
|
31
|
+
expect(presenter).to be_an Admin::PersonPresenter
|
32
|
+
end
|
33
|
+
|
34
|
+
it 'initializes a presenter by a given scoped object' do
|
35
|
+
presenter = helper.present([:admin, Person.new])
|
36
|
+
expect(presenter).to be_an Admin::PersonPresenter
|
37
|
+
end
|
38
|
+
|
39
|
+
it 'initializes a presenter by a given scoped object and presenter class name (ignoring the scope)' do
|
40
|
+
presenter = helper.present([:unknown, :scope, Person.new], with: Admin::PersonPresenter)
|
41
|
+
expect(presenter).to be_an Admin::PersonPresenter
|
42
|
+
end
|
43
|
+
|
44
|
+
it 'fails initializing a presenter with an invalidly scoped object' do
|
45
|
+
expect { helper.present([:unknown, :scope, Person.new]) }.to raise_error(/uninitialized constant/)
|
46
|
+
end
|
47
|
+
|
48
|
+
it 'takes a block and yields the just initialized presenter instance as argument' do
|
49
|
+
expect { |block| helper.present(Person.new, &block) }.to yield_with_args(PersonPresenter)
|
50
|
+
end
|
51
|
+
end
|
52
|
+
end
|
File without changes
|
data/spec/spec_helper.rb
ADDED
metadata
ADDED
@@ -0,0 +1,134 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: actionpresenter
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Tobias Casper
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2014-12-02 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: rails
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - "~>"
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '4.0'
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '4.0'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: bundler
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - "~>"
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '1.0'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - "~>"
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '1.0'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: jeweler
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - "~>"
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: 2.0.1
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - "~>"
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: 2.0.1
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: rspec-rails
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - "~>"
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '3.0'
|
62
|
+
type: :development
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - "~>"
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '3.0'
|
69
|
+
- !ruby/object:Gem::Dependency
|
70
|
+
name: pry-byebug
|
71
|
+
requirement: !ruby/object:Gem::Requirement
|
72
|
+
requirements:
|
73
|
+
- - ">="
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
version: '0'
|
76
|
+
type: :development
|
77
|
+
prerelease: false
|
78
|
+
version_requirements: !ruby/object:Gem::Requirement
|
79
|
+
requirements:
|
80
|
+
- - ">="
|
81
|
+
- !ruby/object:Gem::Version
|
82
|
+
version: '0'
|
83
|
+
description: A lightweight presenter implementation for Ruby on Rails.
|
84
|
+
email: tobias.casper@gmail.com
|
85
|
+
executables: []
|
86
|
+
extensions: []
|
87
|
+
extra_rdoc_files:
|
88
|
+
- LICENSE.txt
|
89
|
+
- README.rdoc
|
90
|
+
files:
|
91
|
+
- ".document"
|
92
|
+
- Gemfile
|
93
|
+
- Gemfile.lock
|
94
|
+
- LICENSE.txt
|
95
|
+
- README.rdoc
|
96
|
+
- Rakefile
|
97
|
+
- VERSION
|
98
|
+
- actionpresenter.gemspec
|
99
|
+
- lib/action_presenter.rb
|
100
|
+
- lib/action_presenter/base.rb
|
101
|
+
- lib/action_presenter/helpers.rb
|
102
|
+
- lib/action_presenter/template_delegation.rb
|
103
|
+
- lib/actionpresenter.rb
|
104
|
+
- spec/helpers/helpers_spec.rb
|
105
|
+
- spec/presenters/.keep
|
106
|
+
- spec/spec_helper.rb
|
107
|
+
- spec/support/faked_view_context.rb
|
108
|
+
- spec/support/models.rb
|
109
|
+
- spec/support/presenters.rb
|
110
|
+
homepage: http://github.com/tlux/actionpresenter
|
111
|
+
licenses:
|
112
|
+
- MIT
|
113
|
+
metadata: {}
|
114
|
+
post_install_message:
|
115
|
+
rdoc_options: []
|
116
|
+
require_paths:
|
117
|
+
- lib
|
118
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
119
|
+
requirements:
|
120
|
+
- - ">="
|
121
|
+
- !ruby/object:Gem::Version
|
122
|
+
version: '0'
|
123
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
124
|
+
requirements:
|
125
|
+
- - ">="
|
126
|
+
- !ruby/object:Gem::Version
|
127
|
+
version: '0'
|
128
|
+
requirements: []
|
129
|
+
rubyforge_project:
|
130
|
+
rubygems_version: 2.4.3
|
131
|
+
signing_key:
|
132
|
+
specification_version: 4
|
133
|
+
summary: A lightweight presenter implementation for Ruby on Rails.
|
134
|
+
test_files: []
|