base_presenter 0.0.9 → 0.0.10
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/.travis.yml +8 -0
- data/README.md +2 -1
- data/base_presenter.gemspec +6 -4
- data/lib/application_helper.rb +1 -1
- data/lib/base_presenter.rb +16 -14
- data/lib/base_presenter/version.rb +1 -1
- data/spec/helpers/application_helper_spec.rb +27 -21
- data/spec/presenters/base_presenter_spec.rb +2 -14
- data/spec/spec_helper.rb +4 -0
- data/spec/support/dummy_model_presenter.rb +40 -0
- metadata +20 -2
data/.travis.yml
CHANGED
data/README.md
CHANGED
@@ -1,6 +1,7 @@
|
|
1
1
|
# BasePresenter
|
2
|
-
[](http://badge.fury.io/rb/base_presenter)
|
2
|
+
[](http://badge.fury.io/rb/base_presenter)
|
3
3
|
[](https://travis-ci.org/raglub/base_presenter)
|
4
|
+
[](https://codeclimate.com/github/raglub/base_presenter)
|
4
5
|
|
5
6
|
The gem adds "Presenter" functionality into Rails application.
|
6
7
|
|
data/base_presenter.gemspec
CHANGED
@@ -6,7 +6,7 @@ require 'base_presenter/version'
|
|
6
6
|
Gem::Specification.new do |spec|
|
7
7
|
spec.name = "base_presenter"
|
8
8
|
spec.version = BasePresenter::VERSION
|
9
|
-
spec.date = '2013-10-
|
9
|
+
spec.date = '2013-10-28'
|
10
10
|
spec.authors = ["Michał Szyma"]
|
11
11
|
spec.email = ["raglub.ruby@gmail.com"]
|
12
12
|
spec.description = %q{The gem adds "Presenter" functionality into Rails application.}
|
@@ -19,8 +19,10 @@ Gem::Specification.new do |spec|
|
|
19
19
|
spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
|
20
20
|
spec.require_paths = ["lib"]
|
21
21
|
|
22
|
-
spec.add_development_dependency
|
23
|
-
spec.add_development_dependency
|
22
|
+
spec.add_development_dependency 'bundler', '~> 1.3'
|
23
|
+
spec.add_development_dependency 'rake'
|
24
24
|
spec.add_development_dependency 'rspec-rails'
|
25
|
-
spec.add_development_dependency 'rails',
|
25
|
+
spec.add_development_dependency 'rails', '>= 3.0.0'
|
26
|
+
spec.add_development_dependency 'simplecov'
|
27
|
+
|
26
28
|
end
|
data/lib/application_helper.rb
CHANGED
data/lib/base_presenter.rb
CHANGED
@@ -8,22 +8,19 @@ class BasePresenter
|
|
8
8
|
@template = template
|
9
9
|
end
|
10
10
|
|
11
|
-
def
|
12
|
-
|
11
|
+
def self.initialize(object, template)
|
12
|
+
@@object = object
|
13
|
+
@@template = template
|
13
14
|
end
|
14
15
|
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
else
|
20
|
-
content_tag :span, "None given", class: "none"
|
21
|
-
end
|
16
|
+
private
|
17
|
+
|
18
|
+
def method_missing(*args, &block)
|
19
|
+
@template.send(*args, &block)
|
22
20
|
end
|
23
21
|
|
24
|
-
def self.
|
25
|
-
@@
|
26
|
-
@@template = template
|
22
|
+
def self.method_missing(*args, &block)
|
23
|
+
@@template.send(*args, &block)
|
27
24
|
end
|
28
25
|
|
29
26
|
def self.presents(name)
|
@@ -32,8 +29,13 @@ class BasePresenter
|
|
32
29
|
end
|
33
30
|
end
|
34
31
|
|
35
|
-
|
36
|
-
|
32
|
+
# Return span with 'None given' when value is blank
|
33
|
+
def handle_none(value)
|
34
|
+
if value.present?
|
35
|
+
yield
|
36
|
+
else
|
37
|
+
content_tag :span, "None given", class: "none"
|
38
|
+
end
|
37
39
|
end
|
38
40
|
|
39
41
|
end
|
@@ -1,23 +1,4 @@
|
|
1
1
|
require 'spec_helper'
|
2
|
-
class DummyModelPresenter < BasePresenter
|
3
|
-
presents :dummy
|
4
|
-
|
5
|
-
def get_object
|
6
|
-
dummy
|
7
|
-
end
|
8
|
-
|
9
|
-
def get_template
|
10
|
-
@template
|
11
|
-
end
|
12
|
-
|
13
|
-
def self.get_object
|
14
|
-
@@object
|
15
|
-
end
|
16
|
-
|
17
|
-
def self.get_template
|
18
|
-
@@template
|
19
|
-
end
|
20
|
-
end
|
21
2
|
|
22
3
|
describe ApplicationHelper do
|
23
4
|
|
@@ -29,7 +10,23 @@ describe ApplicationHelper do
|
|
29
10
|
end
|
30
11
|
|
31
12
|
it "should initialize presenter with properly object model" do
|
32
|
-
|
13
|
+
present(dummy_model).get_object.should eq dummy_model
|
14
|
+
end
|
15
|
+
|
16
|
+
it "should valid presenter method using block without variable" do
|
17
|
+
result = ""
|
18
|
+
present(dummy_model) do
|
19
|
+
result += dummy_name
|
20
|
+
end
|
21
|
+
result.should eq "DUMMY"
|
22
|
+
end
|
23
|
+
|
24
|
+
it "should valid presenter method using block with variable" do
|
25
|
+
result = ""
|
26
|
+
present(dummy_model) do |dummy_presenter|
|
27
|
+
result += dummy_presenter.dummy_name
|
28
|
+
end
|
29
|
+
result.should eq "DUMMY"
|
33
30
|
end
|
34
31
|
end
|
35
32
|
|
@@ -39,7 +36,16 @@ describe ApplicationHelper do
|
|
39
36
|
end
|
40
37
|
|
41
38
|
it "should initialize presenter with properly object model" do
|
42
|
-
|
39
|
+
present(DummyModel).get_object.should eq DummyModel
|
43
40
|
end
|
41
|
+
|
42
|
+
it "should valid presenter method using block" do
|
43
|
+
expect do
|
44
|
+
helper.present(DummyModel) do |dummy_presenter|
|
45
|
+
|
46
|
+
end
|
47
|
+
end.to_not raise_error
|
48
|
+
end
|
49
|
+
|
44
50
|
end
|
45
51
|
end
|
@@ -1,16 +1,4 @@
|
|
1
1
|
require 'spec_helper'
|
2
|
-
class DummyModelPresenter < BasePresenter
|
3
|
-
presents :dummy
|
4
|
-
delegate :id, to: :dummy
|
5
|
-
|
6
|
-
def name
|
7
|
-
dummy.name.upcase
|
8
|
-
end
|
9
|
-
|
10
|
-
def self.name
|
11
|
-
"Class name"
|
12
|
-
end
|
13
|
-
end
|
14
2
|
|
15
3
|
describe ApplicationHelper do
|
16
4
|
let(:dummy_model) { DummyModel.new }
|
@@ -35,12 +23,12 @@ describe ApplicationHelper do
|
|
35
23
|
|
36
24
|
it "#handle_none with not blank of value" do
|
37
25
|
value = "no empty"
|
38
|
-
dummy_presenter.
|
26
|
+
dummy_presenter.show_value(value).should eq(value)
|
39
27
|
end
|
40
28
|
|
41
29
|
it "#handle_none with not blank of value" do
|
42
30
|
value = nil
|
43
|
-
dummy_presenter.
|
31
|
+
dummy_presenter.show_value(value).should match('<span class')
|
44
32
|
end
|
45
33
|
end
|
46
34
|
end
|
data/spec/spec_helper.rb
CHANGED
@@ -3,6 +3,10 @@ ENV["RAILS_ENV"] ||= 'test'
|
|
3
3
|
require ::File.expand_path('../dummy/config/environment', __FILE__)
|
4
4
|
require 'rspec/rails'
|
5
5
|
require 'base_presenter'
|
6
|
+
require_relative 'support/dummy_model_presenter'
|
7
|
+
|
8
|
+
require 'simplecov'
|
9
|
+
SimpleCov.start
|
6
10
|
|
7
11
|
RSpec.configure do |config|
|
8
12
|
config.color_enabled = true
|
@@ -0,0 +1,40 @@
|
|
1
|
+
class DummyModelPresenter < BasePresenter
|
2
|
+
presents :dummy
|
3
|
+
|
4
|
+
delegate :id, to: :dummy
|
5
|
+
|
6
|
+
def show_value(value)
|
7
|
+
handle_none(value) do
|
8
|
+
value
|
9
|
+
end
|
10
|
+
end
|
11
|
+
|
12
|
+
def name
|
13
|
+
dummy.name.upcase
|
14
|
+
end
|
15
|
+
|
16
|
+
def self.name
|
17
|
+
"Class name"
|
18
|
+
end
|
19
|
+
|
20
|
+
def dummy_name
|
21
|
+
"DUMMY"
|
22
|
+
end
|
23
|
+
|
24
|
+
def get_object
|
25
|
+
dummy
|
26
|
+
end
|
27
|
+
|
28
|
+
def get_template
|
29
|
+
@template
|
30
|
+
end
|
31
|
+
|
32
|
+
def self.get_object
|
33
|
+
@@object
|
34
|
+
end
|
35
|
+
|
36
|
+
def self.get_template
|
37
|
+
@@template
|
38
|
+
end
|
39
|
+
|
40
|
+
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: base_presenter
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.10
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2013-10-
|
12
|
+
date: 2013-10-28 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: bundler
|
@@ -75,6 +75,22 @@ dependencies:
|
|
75
75
|
- - ! '>='
|
76
76
|
- !ruby/object:Gem::Version
|
77
77
|
version: 3.0.0
|
78
|
+
- !ruby/object:Gem::Dependency
|
79
|
+
name: simplecov
|
80
|
+
requirement: !ruby/object:Gem::Requirement
|
81
|
+
none: false
|
82
|
+
requirements:
|
83
|
+
- - ! '>='
|
84
|
+
- !ruby/object:Gem::Version
|
85
|
+
version: '0'
|
86
|
+
type: :development
|
87
|
+
prerelease: false
|
88
|
+
version_requirements: !ruby/object:Gem::Requirement
|
89
|
+
none: false
|
90
|
+
requirements:
|
91
|
+
- - ! '>='
|
92
|
+
- !ruby/object:Gem::Version
|
93
|
+
version: '0'
|
78
94
|
description: The gem adds "Presenter" functionality into Rails application.
|
79
95
|
email:
|
80
96
|
- raglub.ruby@gmail.com
|
@@ -120,6 +136,7 @@ files:
|
|
120
136
|
- spec/helpers/application_helper_spec.rb
|
121
137
|
- spec/presenters/base_presenter_spec.rb
|
122
138
|
- spec/spec_helper.rb
|
139
|
+
- spec/support/dummy_model_presenter.rb
|
123
140
|
homepage: https://github.com/raglub/base_presenter
|
124
141
|
licenses:
|
125
142
|
- MIT
|
@@ -171,3 +188,4 @@ test_files:
|
|
171
188
|
- spec/helpers/application_helper_spec.rb
|
172
189
|
- spec/presenters/base_presenter_spec.rb
|
173
190
|
- spec/spec_helper.rb
|
191
|
+
- spec/support/dummy_model_presenter.rb
|