base_presenter 0.0.6 → 0.0.7
Sign up to get free protection for your applications and to get access to all the features.
- data/README.md +10 -1
- data/base_presenter.gemspec +1 -1
- data/lib/application_helper.rb +1 -0
- data/lib/base_presenter/version.rb +1 -1
- data/spec/dummy/app/models/dummy_model.rb +4 -0
- data/spec/helpers/base_presenter_spec.rb +29 -23
- metadata +2 -2
data/README.md
CHANGED
@@ -23,7 +23,7 @@ In director root_rails/app/presenters create file example_presenter.rb with cont
|
|
23
23
|
```ruby
|
24
24
|
class ExamplePresenter < BasePresenter
|
25
25
|
presents :example
|
26
|
-
delegate :
|
26
|
+
delegate :id, to: :example
|
27
27
|
|
28
28
|
def name
|
29
29
|
"Name"
|
@@ -32,6 +32,13 @@ class ExamplePresenter < BasePresenter
|
|
32
32
|
def self.class_name
|
33
33
|
"Example"
|
34
34
|
end
|
35
|
+
|
36
|
+
def link_to_example
|
37
|
+
handle_none example.name do
|
38
|
+
link_to(example.name, example_path(example))
|
39
|
+
end
|
40
|
+
end
|
41
|
+
|
35
42
|
end
|
36
43
|
```
|
37
44
|
|
@@ -40,7 +47,9 @@ and in file show.html.erb with:
|
|
40
47
|
|
41
48
|
```erb
|
42
49
|
<% present @example do |presenter| %>
|
50
|
+
Id: <%= presenter.id %>
|
43
51
|
Name: <%= presenter.name %>
|
52
|
+
Url: <%= presenter.link_to_example %>
|
44
53
|
<% end %>
|
45
54
|
```
|
46
55
|
|
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-11'
|
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}
|
data/lib/application_helper.rb
CHANGED
@@ -1,6 +1,7 @@
|
|
1
1
|
require 'spec_helper'
|
2
2
|
class DummyModelPresenter < BasePresenter
|
3
3
|
presents :dummy
|
4
|
+
delegate :id, to: :dummy
|
4
5
|
|
5
6
|
def name
|
6
7
|
dummy.name.upcase
|
@@ -18,34 +19,39 @@ describe ApplicationHelper do
|
|
18
19
|
helper.present(dummy_model)
|
19
20
|
end
|
20
21
|
|
21
|
-
|
22
|
-
|
23
|
-
|
22
|
+
describe "without block" do
|
23
|
+
it "should initialize presenter" do
|
24
|
+
dummy_presenter
|
25
|
+
end
|
24
26
|
|
25
|
-
|
26
|
-
|
27
|
-
|
27
|
+
it "#presents" do
|
28
|
+
dummy_presenter.dummy.should eq dummy_model
|
29
|
+
end
|
28
30
|
|
29
|
-
|
30
|
-
|
31
|
-
|
31
|
+
it "should show formated name" do
|
32
|
+
dummy_presenter.name.should eq("EXAMPLE NAME")
|
33
|
+
end
|
32
34
|
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
end
|
35
|
+
it "should show id of dummy using delegation" do
|
36
|
+
dummy_presenter.id.should eq(123)
|
37
|
+
end
|
37
38
|
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
39
|
+
it "#handle_none with not blank of value" do
|
40
|
+
value = "no empty"
|
41
|
+
dummy_presenter.handle_none(value) {value}.should eq(value)
|
42
|
+
end
|
42
43
|
|
43
|
-
|
44
|
-
|
45
|
-
|
44
|
+
it "#handle_none with not blank of value" do
|
45
|
+
value = nil
|
46
|
+
dummy_presenter.handle_none(value) {value}.should match('<span class')
|
47
|
+
end
|
46
48
|
|
47
|
-
|
48
|
-
|
49
|
-
|
49
|
+
it ".template" do
|
50
|
+
helper.present(DummyModel).template.should_not be_nil
|
51
|
+
end
|
50
52
|
|
53
|
+
it "should show class name" do
|
54
|
+
helper.present(DummyModel).name.should eq("Class name")
|
55
|
+
end
|
56
|
+
end
|
51
57
|
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.7
|
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-11 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: bundler
|