base_presenter 0.0.5 → 0.0.6
Sign up to get free protection for your applications and to get access to all the features.
- data/README.md +33 -18
- data/lib/base_presenter/version.rb +1 -1
- data/lib/base_presenter.rb +8 -10
- metadata +1 -1
data/README.md
CHANGED
@@ -20,28 +20,43 @@ Or install it yourself as:
|
|
20
20
|
|
21
21
|
In director root_rails/app/presenters create file example_presenter.rb with content
|
22
22
|
|
23
|
-
|
24
|
-
|
25
|
-
|
23
|
+
```ruby
|
24
|
+
class ExamplePresenter < BasePresenter
|
25
|
+
presents :example
|
26
|
+
delegate :name, :example
|
26
27
|
|
27
|
-
|
28
|
-
|
29
|
-
|
28
|
+
def name
|
29
|
+
"Name"
|
30
|
+
end
|
30
31
|
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
32
|
+
def self.class_name
|
33
|
+
"Example"
|
34
|
+
end
|
35
|
+
end
|
36
|
+
```
|
35
37
|
|
36
38
|
and in file show.html.erb with:
|
37
|
-
* object
|
39
|
+
* object `@example`
|
38
40
|
|
39
|
-
|
40
|
-
|
41
|
-
|
41
|
+
```erb
|
42
|
+
<% present @example do |presenter| %>
|
43
|
+
Name: <%= presenter.name %>
|
44
|
+
<% end %>
|
45
|
+
```
|
42
46
|
|
43
|
-
* class Example
|
47
|
+
* class `Example`
|
48
|
+
|
49
|
+
```erb
|
50
|
+
<% present Example do |presenter| %>
|
51
|
+
Class name: <%= presenter.class_name %>
|
52
|
+
<% end %>
|
53
|
+
```
|
54
|
+
## Methods
|
55
|
+
|
56
|
+
Methods of BasePresenter
|
57
|
+
|
58
|
+
Method returns span with 'None given' when value is blank
|
59
|
+
```erb
|
60
|
+
#handle_none(value)
|
61
|
+
```
|
44
62
|
|
45
|
-
<% present Example do |presenter| %>
|
46
|
-
Class name: <%= presenter.class_name %>
|
47
|
-
<% end %>
|
data/lib/base_presenter.rb
CHANGED
@@ -1,5 +1,6 @@
|
|
1
1
|
require "base_presenter/version"
|
2
2
|
require "application_helper"
|
3
|
+
|
3
4
|
class BasePresenter
|
4
5
|
|
5
6
|
def initialize(object, template)
|
@@ -8,14 +9,15 @@ class BasePresenter
|
|
8
9
|
end
|
9
10
|
|
10
11
|
def method_missing(*args, &block)
|
11
|
-
|
12
|
+
@template.send(*args, &block)
|
12
13
|
end
|
13
14
|
|
15
|
+
# Return span with 'None given' when value is blank
|
14
16
|
def handle_none(value)
|
15
17
|
if value.present?
|
16
18
|
yield
|
17
19
|
else
|
18
|
-
|
20
|
+
content_tag :span, "None given", class: "none"
|
19
21
|
end
|
20
22
|
end
|
21
23
|
|
@@ -27,15 +29,11 @@ class BasePresenter
|
|
27
29
|
@object
|
28
30
|
end
|
29
31
|
end
|
30
|
-
end
|
31
|
-
|
32
|
-
private
|
33
32
|
|
34
|
-
def
|
35
|
-
@@template
|
33
|
+
def method_missing(*args, &block)
|
34
|
+
@@template.send(*args, &block)
|
36
35
|
end
|
37
36
|
|
38
|
-
|
39
|
-
|
40
|
-
end
|
37
|
+
end
|
38
|
+
|
41
39
|
end
|