Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add compatibility with turbo-rails #30

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions app/assets/javascripts/heavens_door.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@
}
} else { // no turbolinks
document.addEventListener('DOMContentLoaded', fn);
// Turbo is not yet available for detection here, need to attach the listener anyway
document.documentElement.addEventListener('turbo:load', fn);
}
}
})(() => {
Expand Down
4 changes: 3 additions & 1 deletion lib/heavens_door/engine.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,9 @@ class Engine < ::Rails::Engine #:nodoc:
initializer 'HeavensDoor' do |app|
app.middleware.use HeavensDoor::Middleware

app.config.assets.precompile += %w(heavens_door.js heavens_door.css)
if !defined?(Propshaft)
app.config.assets.precompile += %w(heavens_door.js heavens_door.css)
end
end
end
end
4 changes: 3 additions & 1 deletion lib/heavens_door/middleware.rb
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,9 @@ def call(env)
end

body = body.dup if body.frozen?
body.sub!(/<\/head[^>]*>/) { %Q[<link rel="stylesheet" href="#{Rails.application.config.assets.prefix}/heavens_door.css" /><script src="#{Rails.application.config.assets.prefix}/heavens_door.js"></script>\n#{$~}] }
if !defined?(Propshaft)
body.sub!(/<\/head[^>]*>/) { %Q[<link rel="stylesheet" href="#{Rails.application.config.assets.prefix}/heavens_door.css" /><script src="#{Rails.application.config.assets.prefix}/heavens_door.js"></script>\n#{$~}] }
end
body.sub!(/<body[^>]*>/) { %Q[#{$~}\n<div id="heavens-door" class="heavens-door-custom"><span id="heavens-door-open" class="heavens-door-button">⏺</span><span id="heavens-door-close" class="heavens-door-button">⏹</span><span id="heavens-door-copy" class="heavens-door-button">📋</span></div>] }

[status, headers, [body]]
Expand Down