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鈥檒l occasionally send you account related emails.

Already on GitHub? Sign in to your account

Better support for Turbo Drive (Breaking Change) #26

Merged
merged 1 commit into from
Mar 30, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
# Changelog

## v0.3.0 - 2024-03-30

* Add support for Turbo Drive - See [#25](https://github.com/julienbourdeau/debugbar/pull/25) and [#26](https://github.com/julienbourdeau/debugbar/pull/26)
*

## v0.2.0 - 2024-02-28

* Introduce polling in case someone cannot use ActiveCable - See [8b262be7](https://github.com/julienbourdeau/debugbar/commit/8b262be7b644c7b587a6c3348bb02076053a344f)
Expand Down
27 changes: 23 additions & 4 deletions app/helpers/debugbar/tag_helpers.rb
Original file line number Diff line number Diff line change
@@ -1,18 +1,37 @@
module Debugbar::TagHelpers
def debugbar_javascript(opt = {})
def debugbar_head
raw <<-HTML
<script defer src="#{Debugbar.config.prefix}/assets/script"></script>
HTML
end

def debugbar_body(opt = {})
opt = ActiveSupport::HashWithIndifferentAccess.new(opt)

# See https://github.com/julienbourdeau/debugbar/issues/8
if !defined?(ActionCable) && opt[:mode].nil?
opt[:mode] = 'poll'
end

raw(<<~HTML)
html = <<-HTML
<div id="__debugbar" data-turbo-permanent></div>
<script type="text/javascript">
HTML

html += <<-HTML
<script type="text/javascript" data-turbo-permanent>
window._debugbarConfigOptions = #{opt.to_json}
</script>
<script defer src="#{Debugbar.config.prefix}/assets/script"></script>
HTML

raw html
end

def debugbar_javascript(opt = {})
errors = []
errors << "debugbar_javascript was removed in 0.3.0."
errors << "Please use `debugbar_head` inside <head> and `debugbar_body(opt_hash)` at the end of <body> instead."
errors << "It was split to support Turbo Drive."
errors << "See https://debugbar.dev/changelog/ for more information."
raise errors.join("\n")
end
end