draper 3.0.0.pre1 → 3.0.0
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.
- checksums.yaml +4 -4
- data/.codeclimate.yml +16 -0
- data/.github/PULL_REQUEST_TEMPLATE.md +24 -0
- data/.rubocop.yml +11 -0
- data/.travis.yml +3 -2
- data/CHANGELOG.md +20 -0
- data/Guardfile +5 -5
- data/README.md +27 -5
- data/Rakefile +1 -2
- data/draper.gemspec +1 -0
- data/lib/draper.rb +7 -2
- data/lib/draper/automatic_delegation.rb +5 -3
- data/lib/draper/collection_decorator.rb +1 -11
- data/lib/draper/compatibility/api_only.rb +23 -0
- data/lib/draper/configuration.rb +15 -0
- data/lib/draper/decoratable.rb +2 -2
- data/lib/draper/decorator.rb +4 -12
- data/lib/draper/finders.rb +0 -0
- data/lib/draper/helper_proxy.rb +1 -8
- data/lib/draper/railtie.rb +12 -13
- data/lib/draper/tasks/test.rake +1 -1
- data/lib/draper/test/devise_helper.rb +1 -8
- data/lib/draper/test/minitest_integration.rb +0 -0
- data/lib/draper/test/rspec_integration.rb +0 -0
- data/lib/draper/undecorate.rb +8 -0
- data/lib/draper/version.rb +1 -1
- data/lib/draper/view_context.rb +3 -19
- data/lib/draper/view_context/build_strategy.rb +11 -2
- data/lib/generators/controller_override.rb +2 -2
- data/lib/generators/draper/install_generator.rb +14 -0
- data/lib/generators/draper/templates/application_decorator.rb +8 -0
- data/lib/generators/mini_test/decorator_generator.rb +1 -1
- data/lib/generators/rails/decorator_generator.rb +1 -8
- data/lib/generators/rspec/templates/decorator_spec.rb +1 -1
- data/spec/draper/collection_decorator_spec.rb +11 -26
- data/spec/draper/configuration_spec.rb +25 -0
- data/spec/draper/decoratable_spec.rb +28 -13
- data/spec/draper/decorated_association_spec.rb +9 -9
- data/spec/draper/decorates_assigned_spec.rb +6 -6
- data/spec/draper/decorator_spec.rb +104 -89
- data/spec/draper/draper_spec.rb +24 -0
- data/spec/draper/factory_spec.rb +24 -24
- data/spec/draper/finders_spec.rb +21 -21
- data/spec/draper/helper_proxy_spec.rb +2 -2
- data/spec/draper/lazy_helpers_spec.rb +2 -2
- data/spec/draper/undecorate_chain_spec.rb +20 -0
- data/spec/draper/view_context/build_strategy_spec.rb +26 -10
- data/spec/draper/view_context_spec.rb +49 -21
- data/spec/dummy/app/controllers/base_controller.rb +4 -0
- data/spec/dummy/app/controllers/posts_controller.rb +2 -2
- data/spec/dummy/app/decorators/post_decorator.rb +0 -0
- data/spec/dummy/config/boot.rb +1 -1
- data/spec/dummy/config/initializers/draper.rb +3 -0
- data/spec/dummy/db/schema.rb +4 -4
- data/spec/dummy/fast_spec/post_decorator_spec.rb +1 -1
- data/spec/dummy/lib/tasks/test.rake +1 -1
- data/spec/dummy/spec/decorators/devise_spec.rb +0 -9
- data/spec/dummy/spec/decorators/post_decorator_spec.rb +2 -2
- data/spec/dummy/test/decorators/minitest/devise_test.rb +0 -9
- data/spec/dummy/test/decorators/minitest/view_context_test.rb +3 -3
- data/spec/dummy/test/decorators/test_unit/devise_test.rb +0 -9
- data/spec/generators/controller/controller_generator_spec.rb +3 -3
- data/spec/generators/decorator/decorator_generator_spec.rb +11 -10
- data/spec/generators/install/install_generator_spec.rb +19 -0
- data/spec/spec_helper.rb +4 -3
- data/spec/support/shared_examples/view_helpers.rb +8 -8
- metadata +38 -7
- data/spec/dummy/app/controllers/application_controller.rb +0 -4
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 6f2c896cc71e7e4e654a5d65907dd0ec4cefed7f
|
4
|
+
data.tar.gz: ce50051cf161e9416483a40797d38ae2d2da3384
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 527adb1c71ce28f23bb9be4186fe857c543a26edd8d20404f1e2a6db51e819143dd9c7973f7735746457c2a8a392e7a6d5b8a79232d26a1694035e09441a98f4
|
7
|
+
data.tar.gz: 0ed34d19d3b0300ea733392aab2c4cceaa1b284efc71e84452331fea4c9c11c68c7dc00baa7802a864d60f69bfb42beb8f5cecf959ed5ebf01b8a24c7e676f3f
|
data/.codeclimate.yml
ADDED
@@ -0,0 +1,24 @@
|
|
1
|
+
## Description
|
2
|
+
Detail your changes here.
|
3
|
+
A few sentences describing the overall goals of the pull request's commits will suffice.
|
4
|
+
Some questions you might answer:
|
5
|
+
|
6
|
+
* Why was this change required?
|
7
|
+
* Did you have any tough decisions to make? Which one(s) did you go with and why?
|
8
|
+
* Are there any deployment impacts to this change?
|
9
|
+
* Is there something you aren't happy with or that needs extra attention?
|
10
|
+
|
11
|
+
## Testing
|
12
|
+
Outline steps to test your changes.
|
13
|
+
|
14
|
+
1. Go here.
|
15
|
+
1. Click this.
|
16
|
+
1. See that.
|
17
|
+
|
18
|
+
## To-Dos
|
19
|
+
- [ ] tests
|
20
|
+
- [ ] documentation
|
21
|
+
|
22
|
+
## References
|
23
|
+
* [GitHub Issue ####](https://github.com/drapergem/draper/issues/####)
|
24
|
+
* [GitHub Pull Request ####](https://github.com/drapergem/draper/pull/####)
|
data/.rubocop.yml
ADDED
data/.travis.yml
CHANGED
data/CHANGELOG.md
CHANGED
@@ -1,5 +1,25 @@
|
|
1
1
|
# Draper Changelog
|
2
2
|
|
3
|
+
## 3.0.0 - 2017
|
4
|
+
|
5
|
+
### Breaking Changes
|
6
|
+
* Rename UninferrableSourceError to UninferrableObjectError [#768](https://github.com/drapergem/draper/pull/768)
|
7
|
+
* Remove conflicting source aliases: `source`, `to_source`, `source_class` and `source_class?` [#786](https://github.com/drapergem/draper/pull/786)
|
8
|
+
|
9
|
+
### New Features
|
10
|
+
* Generator for creating `ApplicationDecorator` that other decorators inherit from [#796](https://github.com/drapergem/draper/pull/796)
|
11
|
+
* Draper configuration with ability to customize the controller Draper uses [#788](https://github.com/drapergem/draper/pull/788)
|
12
|
+
* Added support for Rails 5 API-only applications [#793](https://github.com/drapergem/draper/pull/793)
|
13
|
+
* Added support for Rails runner [#739](https://github.com/drapergem/draper/pull/739)
|
14
|
+
|
15
|
+
### Other Changes
|
16
|
+
* Clear view context when the controller changes [#799](https://github.com/drapergem/draper/pull/799)
|
17
|
+
* Removed previously deprecated functionality [#785](https://github.com/drapergem/draper/pull/785)
|
18
|
+
* Only delegate === if other is an instance of a class that inherits from `Decorator` [#720](https://github.com/drapergem/draper/pull/720)
|
19
|
+
* Always default to `CollectionDecorator` when `NameError` is raised [#795](https://github.com/drapergem/draper/pull/795)
|
20
|
+
* Fixed issues in order to support Rails 5.1
|
21
|
+
* Fixed a bug where helpers were used inside a decorator and this decorator was used outside of controller context
|
22
|
+
|
3
23
|
## 3.0.0.pre1 - 2016-07-10
|
4
24
|
|
5
25
|
* Added support for Rails 5, dropped 4.0 - 4.2
|
data/Guardfile
CHANGED
@@ -1,25 +1,25 @@
|
|
1
1
|
def rspec_guard(options = {}, &block)
|
2
2
|
options = {
|
3
|
-
:
|
4
|
-
:
|
3
|
+
version: 2,
|
4
|
+
notification: false
|
5
5
|
}.merge(options)
|
6
6
|
|
7
7
|
guard 'rspec', options, &block
|
8
8
|
end
|
9
9
|
|
10
|
-
rspec_guard :
|
10
|
+
rspec_guard spec_paths: %w{spec/draper spec/generators} do
|
11
11
|
watch(%r{^spec/.+_spec\.rb$})
|
12
12
|
watch(%r{^lib/(.+)\.rb$}) { |m| "spec/#{m[1]}_spec.rb" }
|
13
13
|
watch('spec/spec_helper.rb') { "spec" }
|
14
14
|
end
|
15
15
|
|
16
|
-
rspec_guard :
|
16
|
+
rspec_guard spec_paths: 'spec/integration', env: {'RAILS_ENV' => 'development'} do
|
17
17
|
watch(%r{^spec/.+_spec\.rb$})
|
18
18
|
watch(%r{^lib/(.+)\.rb$}) { |m| "spec/#{m[1]}_spec.rb" }
|
19
19
|
watch('spec/spec_helper.rb') { "spec" }
|
20
20
|
end
|
21
21
|
|
22
|
-
rspec_guard :
|
22
|
+
rspec_guard spec_paths: 'spec/integration', env: {'RAILS_ENV' => 'production'} do
|
23
23
|
watch(%r{^spec/.+_spec\.rb$})
|
24
24
|
watch(%r{^lib/(.+)\.rb$}) { |m| "spec/#{m[1]}_spec.rb" }
|
25
25
|
watch('spec/spec_helper.rb') { "spec" }
|
data/README.md
CHANGED
@@ -107,13 +107,13 @@ Decorators are the ideal place to:
|
|
107
107
|
|
108
108
|
## Installation
|
109
109
|
|
110
|
-
Add Draper to your Gemfile
|
110
|
+
As of version 3.0.0, Draper is only compatible with Rails 5 / Ruby 2.2 and later. Add Draper to your Gemfile.
|
111
111
|
|
112
112
|
```ruby
|
113
|
-
gem 'draper'
|
113
|
+
gem 'draper'
|
114
114
|
```
|
115
115
|
|
116
|
-
|
116
|
+
After that, run `bundle install` within your app's directory.
|
117
117
|
|
118
118
|
If you're upgrading from a 0.x release, the major changes are outlined [in the
|
119
119
|
wiki](https://github.com/drapergem/draper/wiki/Upgrading-to-1.0).
|
@@ -132,6 +132,12 @@ end
|
|
132
132
|
|
133
133
|
### Generators
|
134
134
|
|
135
|
+
To create an `ApplicationDecorator` that all generated decorators inherit from, run...
|
136
|
+
|
137
|
+
```
|
138
|
+
rails generate draper:install
|
139
|
+
```
|
140
|
+
|
135
141
|
When you have Draper installed and generate a controller...
|
136
142
|
|
137
143
|
```
|
@@ -361,6 +367,18 @@ you'll have access to an ArticleDecorator object instead. In your controller you
|
|
361
367
|
can continue to use the `@article` instance variable to manipulate the model -
|
362
368
|
for example, `@article.comments.build` to add a new blank comment for a form.
|
363
369
|
|
370
|
+
## Configuration
|
371
|
+
Draper works out the box well, but also provides a hook for you to configure its
|
372
|
+
default functionality. For example, Draper assumes you have a base `ApplicationController`.
|
373
|
+
If your base controller is named something different (e.g. `BaseController`),
|
374
|
+
you can tell Draper to use it by adding the following to an initializer:
|
375
|
+
|
376
|
+
```ruby
|
377
|
+
Draper.configure do |config|
|
378
|
+
config.default_controller = BaseController
|
379
|
+
end
|
380
|
+
```
|
381
|
+
|
364
382
|
## Testing
|
365
383
|
|
366
384
|
Draper supports RSpec, MiniTest::Rails, and Test::Unit, and will add the
|
@@ -477,7 +495,10 @@ end
|
|
477
495
|
|
478
496
|
When your decorator calls `delegate_all`, any method called on the decorator not
|
479
497
|
defined in the decorator itself will be delegated to the decorated object. This
|
480
|
-
|
498
|
+
includes calling `super` from within the decorator. A call to `super` from within
|
499
|
+
the decorator will first try to call the method on the parent decorator class. If
|
500
|
+
the method does not exist on the parent decorator class, it will then try to call
|
501
|
+
the method on the decorated `object`. This is a very permissive interface.
|
481
502
|
|
482
503
|
If you want to strictly control which methods are called within views, you can
|
483
504
|
choose to only delegate certain methods from the decorator to the source model:
|
@@ -605,7 +626,7 @@ great community of open source
|
|
605
626
|
|
606
627
|
### Current maintainers
|
607
628
|
|
608
|
-
*
|
629
|
+
* Cliff Braton (cliff.braton@gmail.com)
|
609
630
|
|
610
631
|
### Historical maintainers
|
611
632
|
|
@@ -613,3 +634,4 @@ great community of open source
|
|
613
634
|
* Steve Klabnik (steve@jumpstartlab.com)
|
614
635
|
* Vasiliy Ermolovich
|
615
636
|
* Andrew Haines
|
637
|
+
* Sean Linsley
|
data/Rakefile
CHANGED
@@ -16,8 +16,7 @@ desc "Run all specs"
|
|
16
16
|
task "spec" => "spec:all"
|
17
17
|
|
18
18
|
namespace "spec" do
|
19
|
-
|
20
|
-
task "all" => ["draper", "integration"]
|
19
|
+
task "all" => ["draper", "generators", "integration"]
|
21
20
|
|
22
21
|
def spec_task(name)
|
23
22
|
desc "Run #{name} specs"
|
data/draper.gemspec
CHANGED
data/lib/draper.rb
CHANGED
@@ -9,7 +9,9 @@ require 'active_support/core_ext/hash/reverse_merge'
|
|
9
9
|
require 'active_support/core_ext/name_error'
|
10
10
|
|
11
11
|
require 'draper/version'
|
12
|
+
require 'draper/configuration'
|
12
13
|
require 'draper/view_helpers'
|
14
|
+
require 'draper/compatibility/api_only'
|
13
15
|
require 'draper/delegation'
|
14
16
|
require 'draper/automatic_delegation'
|
15
17
|
require 'draper/finders'
|
@@ -27,8 +29,11 @@ require 'draper/decorates_assigned'
|
|
27
29
|
require 'draper/railtie' if defined?(Rails)
|
28
30
|
|
29
31
|
module Draper
|
32
|
+
extend Draper::Configuration
|
33
|
+
|
30
34
|
def self.setup_action_controller(base)
|
31
35
|
base.class_eval do
|
36
|
+
include Draper::Compatibility::ApiOnly if base == ActionController::API
|
32
37
|
include Draper::ViewContext
|
33
38
|
extend Draper::HelperSupport
|
34
39
|
extend Draper::DecoratesAssigned
|
@@ -55,9 +60,9 @@ module Draper
|
|
55
60
|
end
|
56
61
|
end
|
57
62
|
|
58
|
-
class
|
63
|
+
class UninferrableObjectError < NameError
|
59
64
|
def initialize(klass)
|
60
|
-
super("Could not infer
|
65
|
+
super("Could not infer an object for #{klass}.")
|
61
66
|
end
|
62
67
|
end
|
63
68
|
end
|
@@ -2,12 +2,14 @@ module Draper
|
|
2
2
|
module AutomaticDelegation
|
3
3
|
extend ActiveSupport::Concern
|
4
4
|
|
5
|
-
# Delegates missing instance methods to the source object.
|
5
|
+
# Delegates missing instance methods to the source object. Note: This will delegate `super`
|
6
|
+
# method calls to `object` as well. Calling `super` will first try to call the method on
|
7
|
+
# the parent decorator class. If no method exists on the parent class, it will then try
|
8
|
+
# to call the method on the `object`.
|
6
9
|
def method_missing(method, *args, &block)
|
7
10
|
return super unless delegatable?(method)
|
8
11
|
|
9
|
-
|
10
|
-
send(method, *args, &block)
|
12
|
+
object.send(method, *args, &block)
|
11
13
|
end
|
12
14
|
|
13
15
|
# Checks if the decorator responds to an instance method, or is able to
|
@@ -42,17 +42,7 @@ module Draper
|
|
42
42
|
@decorated_collection ||= object.map{|item| decorate_item(item)}
|
43
43
|
end
|
44
44
|
|
45
|
-
|
46
|
-
# (`Enumerable#find`) or to the decorator class if not
|
47
|
-
# (`ActiveRecord::FinderMethods#find`)
|
48
|
-
def find(*args, &block)
|
49
|
-
if block_given?
|
50
|
-
decorated_collection.find(*args, &block)
|
51
|
-
else
|
52
|
-
ActiveSupport::Deprecation.warn("Using ActiveRecord's `find` on a CollectionDecorator is deprecated. Call `find` on a model, and then decorate the result", caller)
|
53
|
-
decorate_item(object.find(*args))
|
54
|
-
end
|
55
|
-
end
|
45
|
+
delegate :find, to: :decorated_collection
|
56
46
|
|
57
47
|
def to_s
|
58
48
|
"#<#{self.class.name} of #{decorator_class || "inferred decorators"} for #{object.inspect}>"
|
@@ -0,0 +1,23 @@
|
|
1
|
+
module Draper
|
2
|
+
module Compatibility
|
3
|
+
# Draper expects your `ApplicationController` to include `ActionView::Rendering`. The
|
4
|
+
# `ApplicationController` generated by Rails 5 API-only applications (created with
|
5
|
+
# `rails new --api`) don't by default. However, including `ActionView::Rendering` in
|
6
|
+
# `ApplicatonController` breaks `render :json` due to `render_to_body` being overridden.
|
7
|
+
#
|
8
|
+
# This compatibility patch fixes the issue by restoring the original `render_to_body`
|
9
|
+
# method after including `ActionView::Rendering`. Ultimately, including `ActionView::Rendering`
|
10
|
+
# in an ActionController::API may not be supported functionality by Rails (see Rails issue
|
11
|
+
# for more detail: https://github.com/rails/rails/issues/27211). This hack is meant to be a
|
12
|
+
# temporary solution until we can find a way to not rely on the controller layer.
|
13
|
+
module ApiOnly
|
14
|
+
extend ActiveSupport::Concern
|
15
|
+
|
16
|
+
included do
|
17
|
+
alias :previous_render_to_body :render_to_body
|
18
|
+
include ActionView::Rendering
|
19
|
+
alias :render_to_body :previous_render_to_body
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
@@ -0,0 +1,15 @@
|
|
1
|
+
module Draper
|
2
|
+
module Configuration
|
3
|
+
def configure
|
4
|
+
yield self
|
5
|
+
end
|
6
|
+
|
7
|
+
def default_controller
|
8
|
+
@@default_controller ||= ApplicationController
|
9
|
+
end
|
10
|
+
|
11
|
+
def default_controller=(controller)
|
12
|
+
@@default_controller = controller
|
13
|
+
end
|
14
|
+
end
|
15
|
+
end
|
data/lib/draper/decoratable.rb
CHANGED
@@ -74,10 +74,10 @@ module Draper
|
|
74
74
|
decorator_name = "#{prefix}Decorator"
|
75
75
|
decorator_name.constantize
|
76
76
|
rescue NameError => error
|
77
|
+
raise unless error.missing_name?(decorator_name)
|
77
78
|
if superclass.respond_to?(:decorator_class)
|
78
79
|
superclass.decorator_class
|
79
80
|
else
|
80
|
-
raise unless error.missing_name?(decorator_name)
|
81
81
|
raise Draper::UninferrableDecoratorError.new(self)
|
82
82
|
end
|
83
83
|
end
|
@@ -86,7 +86,7 @@ module Draper
|
|
86
86
|
#
|
87
87
|
# @return [Boolean]
|
88
88
|
def ===(other)
|
89
|
-
super || (other.
|
89
|
+
super || (other.is_a?(Draper::Decorator) && super(other.object))
|
90
90
|
end
|
91
91
|
|
92
92
|
end
|
data/lib/draper/decorator.rb
CHANGED
@@ -10,8 +10,6 @@ module Draper
|
|
10
10
|
# @return the object being decorated.
|
11
11
|
attr_reader :object
|
12
12
|
alias_method :model, :object
|
13
|
-
alias_method :source, :object # TODO: deprecate this
|
14
|
-
alias_method :to_source, :object # TODO: deprecate this
|
15
13
|
|
16
14
|
# @return [Hash] extra data to be used in user-defined methods.
|
17
15
|
attr_accessor :context
|
@@ -72,15 +70,10 @@ module Draper
|
|
72
70
|
# Checks whether this decorator class has a corresponding {object_class}.
|
73
71
|
def self.object_class?
|
74
72
|
object_class
|
75
|
-
rescue Draper::
|
73
|
+
rescue Draper::UninferrableObjectError
|
76
74
|
false
|
77
75
|
end
|
78
76
|
|
79
|
-
class << self # TODO deprecate this
|
80
|
-
alias_method :source_class, :object_class
|
81
|
-
alias_method :source_class?, :object_class?
|
82
|
-
end
|
83
|
-
|
84
77
|
# Automatically decorates ActiveRecord finder methods, so that you can use
|
85
78
|
# `ProductDecorator.find(id)` instead of
|
86
79
|
# `ProductDecorator.decorate(Product.find(id))`.
|
@@ -182,7 +175,7 @@ module Draper
|
|
182
175
|
|
183
176
|
# Returns a unique hash for a decorated object based on
|
184
177
|
# the decorator class and the object being decorated.
|
185
|
-
#
|
178
|
+
#
|
186
179
|
# @return [Fixnum]
|
187
180
|
def hash
|
188
181
|
self.class.hash ^ object.hash
|
@@ -230,8 +223,7 @@ module Draper
|
|
230
223
|
def self.collection_decorator_class
|
231
224
|
name = collection_decorator_name
|
232
225
|
name.constantize
|
233
|
-
rescue NameError
|
234
|
-
raise if name && !error.missing_name?(name)
|
226
|
+
rescue NameError
|
235
227
|
Draper::CollectionDecorator
|
236
228
|
end
|
237
229
|
|
@@ -256,7 +248,7 @@ module Draper
|
|
256
248
|
name.constantize
|
257
249
|
rescue NameError => error
|
258
250
|
raise if name && !error.missing_name?(name)
|
259
|
-
raise Draper::
|
251
|
+
raise Draper::UninferrableObjectError.new(self)
|
260
252
|
end
|
261
253
|
|
262
254
|
def self.collection_decorator_name
|
data/lib/draper/finders.rb
CHANGED
File without changes
|
data/lib/draper/helper_proxy.rb
CHANGED
@@ -4,9 +4,7 @@ module Draper
|
|
4
4
|
class HelperProxy
|
5
5
|
|
6
6
|
# @overload initialize(view_context)
|
7
|
-
def initialize(view_context
|
8
|
-
view_context ||= current_view_context # backwards compatibility
|
9
|
-
|
7
|
+
def initialize(view_context)
|
10
8
|
@view_context = view_context
|
11
9
|
end
|
12
10
|
|
@@ -35,10 +33,5 @@ module Draper
|
|
35
33
|
view_context.send(name, *args, &block)
|
36
34
|
end
|
37
35
|
end
|
38
|
-
|
39
|
-
def current_view_context
|
40
|
-
ActiveSupport::Deprecation.warn("wrong number of arguments (0 for 1) passed to Draper::HelperProxy.new", caller[1..-1])
|
41
|
-
Draper::ViewContext.current.view_context
|
42
|
-
end
|
43
36
|
end
|
44
37
|
end
|
data/lib/draper/railtie.rb
CHANGED
@@ -3,8 +3,6 @@ require 'rails/railtie'
|
|
3
3
|
module ActiveModel
|
4
4
|
class Railtie < Rails::Railtie
|
5
5
|
generators do |app|
|
6
|
-
app ||= Rails.application # Rails 3.0.x does not yield `app`
|
7
|
-
|
8
6
|
Rails::Generators.configure! app.config.generators
|
9
7
|
require_relative '../generators/controller_override'
|
10
8
|
end
|
@@ -13,7 +11,6 @@ end
|
|
13
11
|
|
14
12
|
module Draper
|
15
13
|
class Railtie < Rails::Railtie
|
16
|
-
|
17
14
|
config.after_initialize do |app|
|
18
15
|
app.config.paths.add 'app/decorators', eager_load: true
|
19
16
|
|
@@ -23,19 +20,19 @@ module Draper
|
|
23
20
|
end
|
24
21
|
end
|
25
22
|
|
26
|
-
initializer
|
23
|
+
initializer 'draper.setup_action_controller' do
|
27
24
|
ActiveSupport.on_load :action_controller do
|
28
25
|
Draper.setup_action_controller self
|
29
26
|
end
|
30
27
|
end
|
31
28
|
|
32
|
-
initializer
|
29
|
+
initializer 'draper.setup_action_mailer' do
|
33
30
|
ActiveSupport.on_load :action_mailer do
|
34
31
|
Draper.setup_action_mailer self
|
35
32
|
end
|
36
33
|
end
|
37
34
|
|
38
|
-
initializer
|
35
|
+
initializer 'draper.setup_orm' do
|
39
36
|
[:active_record, :mongoid].each do |orm|
|
40
37
|
ActiveSupport.on_load orm do
|
41
38
|
Draper.setup_orm self
|
@@ -43,20 +40,22 @@ module Draper
|
|
43
40
|
end
|
44
41
|
end
|
45
42
|
|
46
|
-
initializer
|
43
|
+
initializer 'draper.minitest-rails_integration' do
|
47
44
|
ActiveSupport.on_load :minitest do
|
48
|
-
require
|
45
|
+
require 'draper/test/minitest_integration'
|
49
46
|
end
|
50
47
|
end
|
51
48
|
|
52
|
-
|
49
|
+
def initialize_view_context
|
53
50
|
require 'action_controller/test_case'
|
54
|
-
|
51
|
+
Draper.default_controller.new.view_context
|
55
52
|
Draper::ViewContext.build
|
56
53
|
end
|
57
54
|
|
58
|
-
|
59
|
-
|
60
|
-
|
55
|
+
console { initialize_view_context }
|
56
|
+
|
57
|
+
runner { initialize_view_context }
|
58
|
+
|
59
|
+
rake_tasks { Dir[File.join(File.dirname(__FILE__), 'tasks/*.rake')].each { |f| load f } }
|
61
60
|
end
|
62
61
|
end
|