From 97d13d73e80854d967bb045fb45e750de9b84989 Mon Sep 17 00:00:00 2001 From: Emil Karlsson Date: Wed, 6 Dec 2023 14:11:36 +0100 Subject: [PATCH] Add alignment options to widget settings --- README.md | 6 ++++++ lib/intercom-rails/config.rb | 1 + lib/intercom-rails/script_tag.rb | 1 + lib/rails/generators/intercom/config/intercom.rb.erb | 2 ++ spec/config_spec.rb | 5 +++++ spec/script_tag_spec.rb | 4 ++++ 6 files changed, 19 insertions(+) diff --git a/README.md b/README.md index 2e3d8a7..af4e3b4 100644 --- a/README.md +++ b/README.md @@ -261,6 +261,12 @@ You can customize the CSS selector, by setting config.inbox.custom_activator = '.intercom-link' ``` +You can choose widget alignment, by setting + +```ruby + config.alignment = :left +``` + You can hide default launcher button, by setting ```ruby diff --git a/lib/intercom-rails/config.rb b/lib/intercom-rails/config.rb index 1093b2d..13d9475 100644 --- a/lib/intercom-rails/config.rb +++ b/lib/intercom-rails/config.rb @@ -108,6 +108,7 @@ def self.reset! config_accessor :enabled_environments, &ARRAY_VALIDATOR config_accessor :include_for_logged_out_users config_accessor :hide_default_launcher + config_accessor :alignment config_accessor :api_base config_accessor :encrypted_mode diff --git a/lib/intercom-rails/script_tag.rb b/lib/intercom-rails/script_tag.rb index 319f471..7a8cefc 100644 --- a/lib/intercom-rails/script_tag.rb +++ b/lib/intercom-rails/script_tag.rb @@ -71,6 +71,7 @@ def intercom_settings hsh[:widget] = widget_options if widget_options.present? hsh[:company] = company_details if company_details.present? hsh[:hide_default_launcher] = Config.hide_default_launcher if Config.hide_default_launcher + hsh[:alignment] = Config.alignment if Config.alignment hsh[:api_base] = Config.api_base if Config.api_base hsh end diff --git a/lib/rails/generators/intercom/config/intercom.rb.erb b/lib/rails/generators/intercom/config/intercom.rb.erb index cb9a3ff..7e8de4f 100644 --- a/lib/rails/generators/intercom/config/intercom.rb.erb +++ b/lib/rails/generators/intercom/config/intercom.rb.erb @@ -119,6 +119,8 @@ IntercomRails.config do |config| # open the messenger. # # config.inbox.style = :custom + + # config.alignment = :left # # If you'd like to use your own link activator CSS selector # uncomment this line and clicks on any element that matches the query will diff --git a/spec/config_spec.rb b/spec/config_spec.rb index c84fd26..43d37fa 100644 --- a/spec/config_spec.rb +++ b/spec/config_spec.rb @@ -56,6 +56,11 @@ expect(IntercomRails.config.hide_default_launcher).to eq(true) end + it 'gets/sets alignment' do + IntercomRails.config.alignment = :left + expect(IntercomRails.config.alignment).to eq(:left) + end + it 'gets/sets api_base' do IntercomRails.config.api_base = "https://abcde1.intercom-messenger.com" expect(IntercomRails.config.api_base).to eq("https://abcde1.intercom-messenger.com") diff --git a/spec/script_tag_spec.rb b/spec/script_tag_spec.rb index 705fe24..d77a679 100644 --- a/spec/script_tag_spec.rb +++ b/spec/script_tag_spec.rb @@ -146,6 +146,10 @@ def sha256_hmac(secret, input) IntercomRails.config.inbox.custom_activator = '.intercom' expect(ScriptTag.new.intercom_settings['widget']).to eq({'activator' => '.intercom'}) end + it 'knows about :alignment' do + IntercomRails.config.alignment = :left + expect(ScriptTag.new.intercom_settings['hide_default_launcher']).to eq(:left) + 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)