decent_decoration 0.0.1 → 0.0.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
data/README.md
CHANGED
@@ -1,24 +1,63 @@
|
|
1
|
-
#
|
1
|
+
# decent_decoration
|
2
2
|
|
3
|
-
|
3
|
+
decent_decoration allows you to use excellent [decent_exposure][decent_exposure] gem with decorators.
|
4
4
|
|
5
5
|
## Installation
|
6
6
|
|
7
7
|
Add this line to your application's Gemfile:
|
8
8
|
|
9
|
-
|
9
|
+
```
|
10
|
+
gem 'decent_decoration'
|
11
|
+
```
|
10
12
|
|
11
13
|
And then execute:
|
12
14
|
|
13
|
-
|
15
|
+
```
|
16
|
+
$ bundle
|
17
|
+
```
|
14
18
|
|
15
|
-
|
19
|
+
## Usage
|
16
20
|
|
17
|
-
|
21
|
+
``` ruby
|
22
|
+
# app/controllers/conferences_controller.rb
|
23
|
+
# with decent_exposure
|
24
|
+
class ConferencesController < ApplicationController
|
25
|
+
expose(:conference) { ConferenceDecorator.new(build_conference) }
|
18
26
|
|
19
|
-
|
27
|
+
private
|
28
|
+
|
29
|
+
def build_conference
|
30
|
+
# create new conference or fetch existing one
|
31
|
+
end
|
32
|
+
end
|
33
|
+
|
34
|
+
# with decent_decoration
|
35
|
+
class ConferencesController < ApplicationController
|
36
|
+
expose_decorated(:conference)
|
37
|
+
end
|
38
|
+
|
39
|
+
```
|
20
40
|
|
21
|
-
|
41
|
+
Define a decorator explicitly:
|
42
|
+
|
43
|
+
``` ruby
|
44
|
+
# app/controllers/conferences_controller.rb
|
45
|
+
class ConferencesController < ApplicationController
|
46
|
+
expose_decorated(:conference, decorator: SponsoredConferenceDecorator)
|
47
|
+
end
|
48
|
+
```
|
49
|
+
|
50
|
+
decent_decoration supports most of the awesome [decent_exposure api][decent_exposure_api]. Read [more about it!][decent_exposure_api]
|
51
|
+
|
52
|
+
``` ruby
|
53
|
+
# app/controllers/attendees_controller.rb
|
54
|
+
class AttendeesController < ApplicationController
|
55
|
+
expose_decorated(:conference)
|
56
|
+
expose_decorated(:attendees, ancestor: :conference)
|
57
|
+
end
|
58
|
+
```
|
59
|
+
|
60
|
+
You can use any decorator mechanism as long as `ConferenceDecorator` responds to `#decorate` or `#new`. Try [draper][draper].
|
22
61
|
|
23
62
|
## Contributing
|
24
63
|
|
@@ -27,3 +66,7 @@ TODO: Write usage instructions here
|
|
27
66
|
3. Commit your changes (`git commit -am 'Add some feature'`)
|
28
67
|
4. Push to the branch (`git push origin my-new-feature`)
|
29
68
|
5. Create new Pull Request
|
69
|
+
|
70
|
+
[decent_exposure]: https://github.com/voxdolo/decent_exposure
|
71
|
+
[decent_exposure_api]: https://github.com/voxdolo/decent_exposure#usage
|
72
|
+
[draper]: https://github.com/drapergem/draper
|
data/decent_decoration.gemspec
CHANGED
@@ -10,7 +10,7 @@ Gem::Specification.new do |gem|
|
|
10
10
|
gem.email = ["pewniak747@gmail.com"]
|
11
11
|
gem.description = %q{Use decent_exposure with decorators (e.g. Draper)}
|
12
12
|
gem.summary = %q{Use decent_exposure with decorators (e.g. Draper)}
|
13
|
-
gem.homepage = "https://github.com/
|
13
|
+
gem.homepage = "https://github.com/netguru/decent_decoration"
|
14
14
|
|
15
15
|
gem.files = `git ls-files`.split($/)
|
16
16
|
gem.executables = gem.files.grep(%r{^bin/}).map{ |f| File.basename(f) }
|
@@ -1,13 +1,14 @@
|
|
1
1
|
module DecentDecoration
|
2
2
|
module Decorate
|
3
|
-
def
|
4
|
-
decorator_class = "#{name.to_s.singularize.classify}Decorator".constantize
|
3
|
+
def expose_decorated(name, options = {}, &block)
|
4
|
+
decorator_class = options.delete(:decorator) || "#{name.to_s.singularize.classify}Decorator".constantize
|
5
5
|
decorated_name = name.to_sym
|
6
6
|
undecorated_name = "undecorated_#{name}".to_sym
|
7
7
|
|
8
8
|
options[:model] ||= decorated_name
|
9
|
+
decorate_method = decorator_class.respond_to?(:decorate) ? :decorate : :new
|
9
10
|
expose(undecorated_name, options, &block)
|
10
|
-
expose(decorated_name) { decorator_class.
|
11
|
+
expose(decorated_name) { decorator_class.public_send(decorate_method, public_send(undecorated_name)) }
|
11
12
|
end
|
12
13
|
end
|
13
14
|
end
|
@@ -17,7 +17,8 @@ end
|
|
17
17
|
class ConferencesController < ActionController::Base
|
18
18
|
include Rails.application.routes.url_helpers
|
19
19
|
|
20
|
-
|
20
|
+
expose_decorated(:conference)
|
21
|
+
expose_decorated(:other_conference, model: Conference, decorator: CoolConferenceDecorator)
|
21
22
|
|
22
23
|
def show
|
23
24
|
render :text => "foo"
|
data/spec/fixtures/decorators.rb
CHANGED
@@ -12,4 +12,9 @@ describe ConferencesController, type: :controller do
|
|
12
12
|
get '/conference/RuPy'
|
13
13
|
controller.conference.decorated_object.should be_instance_of(Conference)
|
14
14
|
end
|
15
|
+
|
16
|
+
it "should be specified decorator" do
|
17
|
+
get '/conference/RuPy'
|
18
|
+
controller.other_conference.should be_instance_of(CoolConferenceDecorator)
|
19
|
+
end
|
15
20
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: decent_decoration
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.2
|
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: 2012-11-
|
12
|
+
date: 2012-11-28 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: decent_exposure
|
@@ -111,7 +111,7 @@ files:
|
|
111
111
|
- spec/fixtures/decorators.rb
|
112
112
|
- spec/fixtures/fake_rails_application.rb
|
113
113
|
- spec/integration/rails_application_spec.rb
|
114
|
-
homepage: https://github.com/
|
114
|
+
homepage: https://github.com/netguru/decent_decoration
|
115
115
|
licenses: []
|
116
116
|
post_install_message:
|
117
117
|
rdoc_options: []
|