base_presenter 0.0.1 → 0.0.2
Sign up to get free protection for your applications and to get access to all the features.
- data/README.md +14 -7
- data/lib/base_presenter/version.rb +1 -1
- data/lib/base_presenter.rb +16 -1
- metadata +1 -1
data/README.md
CHANGED
@@ -18,12 +18,19 @@ Or install it yourself as:
|
|
18
18
|
|
19
19
|
## Usage
|
20
20
|
|
21
|
-
|
21
|
+
In director root_rails/app/presenters create file example_presenter.rb with content
|
22
22
|
|
23
|
-
|
23
|
+
class ExamplePresenter < BasePresenter
|
24
|
+
presents :example
|
25
|
+
delegate :name, :example
|
24
26
|
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
27
|
+
def name
|
28
|
+
"Name"
|
29
|
+
end
|
30
|
+
end
|
31
|
+
|
32
|
+
and in file show.html.erb
|
33
|
+
|
34
|
+
<% present @example do |presenter| %>
|
35
|
+
Name: <%= presenter.name %>
|
36
|
+
<% end %>
|
data/lib/base_presenter.rb
CHANGED
@@ -1,5 +1,20 @@
|
|
1
1
|
require "base_presenter/version"
|
2
2
|
|
3
3
|
class BasePresenter
|
4
|
-
|
4
|
+
|
5
|
+
def initialize(object, template)
|
6
|
+
@object = object
|
7
|
+
@template = template
|
8
|
+
end
|
9
|
+
|
10
|
+
def self.presents(name)
|
11
|
+
define_method(name) do
|
12
|
+
@object
|
13
|
+
end
|
14
|
+
end
|
15
|
+
|
16
|
+
def method_missing(*args, &block)
|
17
|
+
@template.send(*args, &block)
|
18
|
+
end
|
19
|
+
|
5
20
|
end
|