forked from drapergem/draper
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Integration with
Turbo::Broadcastable
Overriding defaults for Turbo broadcast jobs allows one to get decorated objects in model partials by default. Resolves drapergem#910. Requires drapergem#928.
- Loading branch information
1 parent
7e35cda
commit 7009fc3
Showing
7 changed files
with
58 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
# frozen_string_literal: true | ||
|
||
module Draper | ||
module Compatibility | ||
# It would look consistent to use decorated objects inside templates broadcasted with | ||
# Turbo::Broadcastable. | ||
# | ||
# This compatibility patch fixes the issue by overriding the original defaults to decorate the | ||
# object, that's passed to the partial in a local variable. | ||
module Broadcastable | ||
private | ||
|
||
def broadcast_rendering_with_defaults(options) | ||
return super unless decorator_class? | ||
|
||
# Add the decorated current instance into the locals (see original method for details). | ||
options[:locals] = | ||
(options[:locals] || {}).reverse_merge!(model_name.element.to_sym => decorate) | ||
|
||
super | ||
end | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,5 @@ | ||
class Post < ApplicationRecord | ||
# attr_accessible :title, :body | ||
|
||
broadcasts if defined? Turbo::Broadcastable | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
# production: | ||
# url: redis://redis.example.com:6379 | ||
|
||
local: &local | ||
url: redis://localhost:6379 | ||
|
||
development: *local | ||
test: *local |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters