action_presenter 1.0.2 → 1.1
Sign up to get free protection for your applications and to get access to all the features.
- data/CHANGELOG.md +5 -0
- data/README.md +24 -2
- data/lib/action_presenter.rb +3 -0
- data/lib/action_presenter/base.rb +2 -0
- data/lib/action_presenter/utilities/let.rb +16 -0
- data/lib/action_presenter/version.rb +1 -1
- data/lib/action_presenter/view_helper.rb +4 -1
- data/spec/action_presenter/utilities/let_spec.rb +20 -0
- data/spec/action_presenter/view_helper_spec.rb +6 -6
- metadata +15 -12
data/CHANGELOG.md
CHANGED
@@ -10,3 +10,8 @@
|
|
10
10
|
|
11
11
|
* add rails generators
|
12
12
|
* allow to change timestamps format
|
13
|
+
|
14
|
+
## Version 1.1
|
15
|
+
|
16
|
+
* fix `present` helper to return presenter instance if no block is given (test braking change - release new minor version)
|
17
|
+
* RSpec inspired way to define short and consise methods
|
data/README.md
CHANGED
@@ -71,8 +71,7 @@ All that without any change in any model or controller
|
|
71
71
|
|
72
72
|
There're some default presenter methods. They're generated if object respond to those methods
|
73
73
|
|
74
|
-
|
75
|
-
* `updated_at` - localized date of last update
|
74
|
+
### `created_at` and `updated_at`
|
76
75
|
|
77
76
|
```haml
|
78
77
|
- present @article do |p|
|
@@ -88,6 +87,29 @@ It's also possible to change timestamps format
|
|
88
87
|
= p.updated_at :long
|
89
88
|
```
|
90
89
|
|
90
|
+
## Utilities
|
91
|
+
|
92
|
+
### Let
|
93
|
+
|
94
|
+
There's RSpec inspired way to define methods
|
95
|
+
|
96
|
+
```ruby
|
97
|
+
class ArticlePresenter < ActionPresenter::Base
|
98
|
+
presents :article
|
99
|
+
|
100
|
+
let(:link_to_title) { link_to_unless_current article.title, article_path(article) }
|
101
|
+
|
102
|
+
let(:render_article) do
|
103
|
+
html = ''.html_safe
|
104
|
+
|
105
|
+
html += content_tag :h1, article.title
|
106
|
+
html += content_tag :p, article.content
|
107
|
+
|
108
|
+
html
|
109
|
+
end
|
110
|
+
end
|
111
|
+
```
|
112
|
+
|
91
113
|
## Testing
|
92
114
|
|
93
115
|
### RSpec
|
data/lib/action_presenter.rb
CHANGED
@@ -10,6 +10,9 @@ require 'action_presenter/version'
|
|
10
10
|
## Default fields
|
11
11
|
require 'action_presenter/defaults/timestamps'
|
12
12
|
|
13
|
+
## Utilities
|
14
|
+
require 'action_presenter/utilities/let'
|
15
|
+
|
13
16
|
## Base presenter class and view helpers
|
14
17
|
require 'action_presenter/base'
|
15
18
|
require 'action_presenter/view_helper'
|
@@ -7,7 +7,10 @@ module ActionPresenter
|
|
7
7
|
end
|
8
8
|
|
9
9
|
def present(object, klass = "#{object.class}Presenter".constantize)
|
10
|
-
|
10
|
+
presenter = klass.new(object, view_context)
|
11
|
+
|
12
|
+
return yield presenter if block_given?
|
13
|
+
presenter
|
11
14
|
end
|
12
15
|
end
|
13
16
|
end
|
@@ -0,0 +1,20 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
require 'support/dummy_presenter'
|
3
|
+
|
4
|
+
|
5
|
+
describe ActionPresenter::Utilities::Let do
|
6
|
+
let(:presenter) { DummyPresenter }
|
7
|
+
|
8
|
+
it 'should create new method' do
|
9
|
+
presenter.should_receive :define_method do |name, block|
|
10
|
+
name.should == :created_with_let
|
11
|
+
|
12
|
+
block.should be_instance_of Proc
|
13
|
+
block.call.should == 'I can create methods!!!'
|
14
|
+
end
|
15
|
+
|
16
|
+
presenter.class_eval do
|
17
|
+
let(:created_with_let) { 'I can create methods!!!' }
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
@@ -8,17 +8,17 @@ describe ActionPresenter::ViewHelper do
|
|
8
8
|
|
9
9
|
it 'should call default presenter if presenter class is not given' do
|
10
10
|
helper.present('foobar') do |p|
|
11
|
-
p.
|
12
|
-
end
|
11
|
+
p.should be_instance_of StringPresenter
|
12
|
+
end
|
13
13
|
end
|
14
14
|
|
15
15
|
it 'should call given presenter class' do
|
16
16
|
helper.present('foobar', FoobarPresenter) do |p|
|
17
|
-
p.
|
18
|
-
end
|
17
|
+
p.should be_instance_of FoobarPresenter
|
18
|
+
end
|
19
19
|
end
|
20
20
|
|
21
|
-
it 'should return
|
22
|
-
helper.present('foobar').should
|
21
|
+
it 'should return presenter instance if no block is given' do
|
22
|
+
helper.present('foobar').should be_instance_of StringPresenter
|
23
23
|
end
|
24
24
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: action_presenter
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.
|
4
|
+
version: '1.1'
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,11 +9,11 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2012-02-
|
12
|
+
date: 2012-02-27 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: actionpack
|
16
|
-
requirement: &
|
16
|
+
requirement: &70356359315720 !ruby/object:Gem::Requirement
|
17
17
|
none: false
|
18
18
|
requirements:
|
19
19
|
- - ! '>='
|
@@ -21,10 +21,10 @@ dependencies:
|
|
21
21
|
version: '0'
|
22
22
|
type: :runtime
|
23
23
|
prerelease: false
|
24
|
-
version_requirements: *
|
24
|
+
version_requirements: *70356359315720
|
25
25
|
- !ruby/object:Gem::Dependency
|
26
26
|
name: named_accessors
|
27
|
-
requirement: &
|
27
|
+
requirement: &70356359300080 !ruby/object:Gem::Requirement
|
28
28
|
none: false
|
29
29
|
requirements:
|
30
30
|
- - ! '>='
|
@@ -32,10 +32,10 @@ dependencies:
|
|
32
32
|
version: '0'
|
33
33
|
type: :runtime
|
34
34
|
prerelease: false
|
35
|
-
version_requirements: *
|
35
|
+
version_requirements: *70356359300080
|
36
36
|
- !ruby/object:Gem::Dependency
|
37
37
|
name: rake
|
38
|
-
requirement: &
|
38
|
+
requirement: &70356359299600 !ruby/object:Gem::Requirement
|
39
39
|
none: false
|
40
40
|
requirements:
|
41
41
|
- - ! '>='
|
@@ -43,10 +43,10 @@ dependencies:
|
|
43
43
|
version: '0'
|
44
44
|
type: :development
|
45
45
|
prerelease: false
|
46
|
-
version_requirements: *
|
46
|
+
version_requirements: *70356359299600
|
47
47
|
- !ruby/object:Gem::Dependency
|
48
48
|
name: rspec
|
49
|
-
requirement: &
|
49
|
+
requirement: &70356359299140 !ruby/object:Gem::Requirement
|
50
50
|
none: false
|
51
51
|
requirements:
|
52
52
|
- - ! '>='
|
@@ -54,7 +54,7 @@ dependencies:
|
|
54
54
|
version: '0'
|
55
55
|
type: :development
|
56
56
|
prerelease: false
|
57
|
-
version_requirements: *
|
57
|
+
version_requirements: *70356359299140
|
58
58
|
description: Missing link between models and views. Use presenter pattern in Rails
|
59
59
|
application without changing controllers.
|
60
60
|
email:
|
@@ -74,11 +74,13 @@ files:
|
|
74
74
|
- lib/action_presenter/base.rb
|
75
75
|
- lib/action_presenter/defaults/timestamps.rb
|
76
76
|
- lib/action_presenter/railtie.rb
|
77
|
+
- lib/action_presenter/utilities/let.rb
|
77
78
|
- lib/action_presenter/version.rb
|
78
79
|
- lib/action_presenter/view_helper.rb
|
79
80
|
- lib/generators/action_presenter/install/install_generator.rb
|
80
81
|
- spec/action_presenter/base_spec.rb
|
81
82
|
- spec/action_presenter/defaults/timestamps_spec.rb
|
83
|
+
- spec/action_presenter/utilities/let_spec.rb
|
82
84
|
- spec/action_presenter/view_helper_spec.rb
|
83
85
|
- spec/spec_helper.rb
|
84
86
|
- spec/support/dummy_action_controller.rb
|
@@ -98,7 +100,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
98
100
|
version: '0'
|
99
101
|
segments:
|
100
102
|
- 0
|
101
|
-
hash:
|
103
|
+
hash: 3423536328799258601
|
102
104
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
103
105
|
none: false
|
104
106
|
requirements:
|
@@ -107,7 +109,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
107
109
|
version: '0'
|
108
110
|
segments:
|
109
111
|
- 0
|
110
|
-
hash:
|
112
|
+
hash: 3423536328799258601
|
111
113
|
requirements: []
|
112
114
|
rubyforge_project: action_presenter
|
113
115
|
rubygems_version: 1.8.16
|
@@ -118,6 +120,7 @@ summary: Missing link between models and views. Use presenter pattern in Rails a
|
|
118
120
|
test_files:
|
119
121
|
- spec/action_presenter/base_spec.rb
|
120
122
|
- spec/action_presenter/defaults/timestamps_spec.rb
|
123
|
+
- spec/action_presenter/utilities/let_spec.rb
|
121
124
|
- spec/action_presenter/view_helper_spec.rb
|
122
125
|
- spec/spec_helper.rb
|
123
126
|
- spec/support/dummy_action_controller.rb
|