Last active
August 3, 2023 14:35
-
-
Save khoan/10db3971c19c50ffb4889c8b1d5d9b98 to your computer and use it in GitHub Desktop.
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
# When intercom javascript is excluded from HTML, any attempt to invoke `window.Intercom(...)` would | |
# result in runtime error. This patch introduces a callback into the controller, so that a shim can | |
# be inserted, when intercom javascript is excluded. | |
# | |
# Remove this patch and update your code if alternative at https://github.com/intercom/intercom-rails/pull/344 | |
# is accepted. | |
spec = Bundler.definition.specs.find{|s| s.name == 'intercom-rails'} | |
if Gem::Dependency.new(spec.name, '> 0.4.2').match?(spec.name, spec.version) | |
raise Gem::DependencyError, "Check that patch is still applicable for intercom-rails gem version #{spec.version}" | |
else | |
module IntercomRails | |
module AutoInclude | |
module MethodPatch | |
def intercom_rails_auto_include | |
super | |
# Callback to controller#after_intercom_rails_auto_include. Within callback, | |
# instance variable @intercom_rails_include_javascript can be queried to know | |
# if intercom javascript has been included or not. | |
callback = :after_intercom_rails_auto_include | |
send(callback) if respond_to?(callback, true) | |
end | |
end | |
module Method | |
prepend MethodPatch | |
end | |
module FilterPatch | |
def include_javascript? | |
controller.instance_variable_set(:@intercom_rails_include_javascript, super) | |
end | |
end | |
class Filter | |
prepend FilterPatch | |
end | |
end | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment