From b123293c16ef72552892672898baf61ab22e498c Mon Sep 17 00:00:00 2001 From: Marin Martinic Date: Fri, 30 Sep 2016 18:59:06 +0100 Subject: [PATCH] add hide_default_launcher to config --- README.mdown | 6 ++++++ lib/intercom-rails/config.rb | 1 + lib/intercom-rails/script_tag.rb | 2 +- lib/rails/generators/intercom/config/intercom.rb.erb | 3 +++ spec/config_spec.rb | 5 +++++ spec/script_tag_helper_spec.rb | 2 +- spec/script_tag_spec.rb | 6 ++++-- 7 files changed, 21 insertions(+), 4 deletions(-) diff --git a/README.mdown b/README.mdown index 3167bd7..e485666 100644 --- a/README.mdown +++ b/README.mdown @@ -261,6 +261,12 @@ You can customize the CSS selector, by setting config.inbox.custom_activator = '.intercom-link' ``` +You can hide default launcher button, by setting + +```ruby + config.hide_default_launcher = true +``` + You can read more about configuring the messenger in your applications settings, within Intercom. ### Environments diff --git a/lib/intercom-rails/config.rb b/lib/intercom-rails/config.rb index e8cf6fe..41da69a 100644 --- a/lib/intercom-rails/config.rb +++ b/lib/intercom-rails/config.rb @@ -107,6 +107,7 @@ def self.reset! config_accessor :library_url config_accessor :enabled_environments, &ARRAY_VALIDATOR config_accessor :include_for_logged_out_users + config_accessor :hide_default_launcher def self.api_key=(*) warn "Setting an Intercom API key is no longer supported; remove the `config.api_key = ...` line from config/initializers/intercom.rb" diff --git a/lib/intercom-rails/script_tag.rb b/lib/intercom-rails/script_tag.rb index 7f86747..43fe0dd 100644 --- a/lib/intercom-rails/script_tag.rb +++ b/lib/intercom-rails/script_tag.rb @@ -64,7 +64,7 @@ def intercom_settings hsh[:session_duration] = @session_duration if @session_duration.present? hsh[:widget] = widget_options if widget_options.present? hsh[:company] = company_details if company_details.present? - hsh[:hide_default_launcher] = Config.inbox.style == :custom + hsh[:hide_default_launcher] = Config.hide_default_launcher if Config.hide_default_launcher hsh end diff --git a/lib/rails/generators/intercom/config/intercom.rb.erb b/lib/rails/generators/intercom/config/intercom.rb.erb index 3833c91..0b09132 100644 --- a/lib/rails/generators/intercom/config/intercom.rb.erb +++ b/lib/rails/generators/intercom/config/intercom.rb.erb @@ -124,4 +124,7 @@ IntercomRails.config do |config| # uncomment this line and clicks on any element that matches the query will # open the messenger # config.inbox.custom_activator = '.intercom' + # + # If you'd like to hide default launcher button uncomment this line + # config.hide_default_launcher = true end diff --git a/spec/config_spec.rb b/spec/config_spec.rb index 4fdff41..a4481bf 100644 --- a/spec/config_spec.rb +++ b/spec/config_spec.rb @@ -51,6 +51,11 @@ expect(IntercomRails.config.inbox.custom_activator).to eq('.intercom') end + it 'gets/sets hide_default_launcher' do + IntercomRails.config.hide_default_launcher = true + expect(IntercomRails.config.hide_default_launcher).to eq(true) + end + it 'raises error if current user not a proc' do expect { IntercomRails.config.user.current = 1 }.to raise_error(ArgumentError) end diff --git a/spec/script_tag_helper_spec.rb b/spec/script_tag_helper_spec.rb index ca683de..8fab37a 100644 --- a/spec/script_tag_helper_spec.rb +++ b/spec/script_tag_helper_spec.rb @@ -35,7 +35,7 @@ :email => 'marco@intercom.io', :user_id => 'marco', }) - expect(script_tag.csp_sha256).to eq("'sha256-QmMmBpC2AxZc9zd18FvMACQwKPbnGG/kGMN4dGJeB3w='") + expect(script_tag.csp_sha256).to eq("'sha256-qLRbekKD6dEDMyLKPNFYpokzwYCz+WeNPqJE603mT24='") end it 'inserts a valid nonce if present' do diff --git a/spec/script_tag_spec.rb b/spec/script_tag_spec.rb index f625251..16c2e56 100644 --- a/spec/script_tag_spec.rb +++ b/spec/script_tag_spec.rb @@ -118,12 +118,14 @@ def sha256_hmac(secret, input) it 'knows about :custom' do IntercomRails.config.inbox.style = :custom expect(ScriptTag.new.intercom_settings['widget']).to eq({'activator' => '#Intercom'}) - expect(ScriptTag.new.intercom_settings['hide_default_launcher']).to eq(true) end it 'knows about :custom_activator' do IntercomRails.config.inbox.style = :custom IntercomRails.config.inbox.custom_activator = '.intercom' expect(ScriptTag.new.intercom_settings['widget']).to eq({'activator' => '.intercom'}) + end + it 'knows about :hide_default_launcher' do + IntercomRails.config.hide_default_launcher = true expect(ScriptTag.new.intercom_settings['hide_default_launcher']).to eq(true) end end @@ -171,7 +173,7 @@ def sha256_hmac(secret, input) :email => 'marco@intercom.io', :user_id => 'marco', }) - expect(script_tag.csp_sha256).to eq("'sha256-QmMmBpC2AxZc9zd18FvMACQwKPbnGG/kGMN4dGJeB3w='") + expect(script_tag.csp_sha256).to eq("'sha256-qLRbekKD6dEDMyLKPNFYpokzwYCz+WeNPqJE603mT24='") end it 'inserts a valid nonce if present' do