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 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 :name, :example
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
 
@@ -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-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}
@@ -12,6 +12,7 @@ module ApplicationHelper
12
12
  end
13
13
 
14
14
  yield presenter if block_given?
15
+ #block.arity > 0 ? yield(presenter) : presenter.instance_eval(&block)
15
16
  return presenter
16
17
  end
17
18
  end
@@ -1,3 +1,3 @@
1
1
  class BasePresenter
2
- VERSION = "0.0.6"
2
+ VERSION = "0.0.7"
3
3
  end
@@ -2,4 +2,8 @@ class DummyModel
2
2
  def name
3
3
  "example name"
4
4
  end
5
+
6
+ def id
7
+ 123
8
+ end
5
9
  end
@@ -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
- it "should initialize presenter" do
22
- dummy_presenter
23
- end
22
+ describe "without block" do
23
+ it "should initialize presenter" do
24
+ dummy_presenter
25
+ end
24
26
 
25
- it "#presents" do
26
- dummy_presenter.dummy.should eq dummy_model
27
- end
27
+ it "#presents" do
28
+ dummy_presenter.dummy.should eq dummy_model
29
+ end
28
30
 
29
- it "should show formated name" do
30
- dummy_presenter.name.should eq("EXAMPLE NAME")
31
- end
31
+ it "should show formated name" do
32
+ dummy_presenter.name.should eq("EXAMPLE NAME")
33
+ end
32
34
 
33
- it "#handle_none with not blank of value" do
34
- value = "no empty"
35
- dummy_presenter.handle_none(value) {value}.should eq(value)
36
- end
35
+ it "should show id of dummy using delegation" do
36
+ dummy_presenter.id.should eq(123)
37
+ end
37
38
 
38
- it "#handle_none with not blank of value" do
39
- value = nil
40
- dummy_presenter.handle_none(value) {value}.should match('<span class')
41
- end
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
- it ".template" do
44
- helper.present(DummyModel).template.should_not be_nil
45
- end
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
- it "should show class name" do
48
- helper.present(DummyModel).name.should eq("Class name")
49
- end
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.6
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-10 00:00:00.000000000 Z
12
+ date: 2013-10-11 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: bundler