Module: ClankerSupport
- Defined in:
- lib/clankersupport/railtie.rb,
lib/clankersupport.rb,
lib/clankersupport/version.rb
Overview
Rails integration. This file is only required from lib/clankersupport.rb when Rails::Railtie is defined, and every constant reference below is guarded, so the gem loads fine without Rails.
Defined Under Namespace
Modules: Helper Classes: Railtie
Constant Summary collapse
- DEFAULT_API_URL =
"https://api.clankersupport.com"- MODES =
data-modevalues the widget understands.bubble(the default) is the floating launcher;inlinemounts the panel in place. ["bubble", "inline"].freeze
- THEMES =
data-themevalues the widget understands. Absent meanslight. ["light", "dark", "auto"].freeze
- VERSION =
"1.0.0"
Class Method Summary collapse
-
.script_tag(project_key, api_url: DEFAULT_API_URL, brand_color: nil, mode: nil, theme: nil, escalation_threshold: nil) ⇒ String
Build the Clanker Support widget
<script>tag.
Class Method Details
.script_tag(project_key, api_url: DEFAULT_API_URL, brand_color: nil, mode: nil, theme: nil, escalation_threshold: nil) ⇒ String
Build the Clanker Support widget <script> tag.
48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 |
# File 'lib/clankersupport.rb', line 48 def self.script_tag( project_key, api_url: DEFAULT_API_URL, brand_color: nil, mode: nil, theme: nil, escalation_threshold: nil ) key = project_key.to_s raise ArgumentError, "project_key is required" if key.strip.empty? if !mode.nil? && !MODES.include?(mode) raise ArgumentError, "mode must be one of #{MODES.inspect}, got #{mode.inspect}" end if !theme.nil? && !THEMES.include?(theme) raise ArgumentError, "theme must be one of #{THEMES.inspect}, got #{theme.inspect}" end if !escalation_threshold.nil? unless escalation_threshold.is_a?(Integer) && escalation_threshold >= 1 raise ArgumentError, "escalation_threshold must be a positive Integer, got #{escalation_threshold.inspect}" end end base = api_url.to_s.sub(%r{/+\z}, "") parts = [ %(<script src="#{escape_attr(base)}/widget.js"), %(data-project="#{escape_attr(key)}"), %(data-api="#{escape_attr(base)}"), ] parts << %(data-brand="#{escape_attr(brand_color)}") unless brand_color.nil? parts << %(data-mode="#{escape_attr(mode)}") unless mode.nil? parts << %(data-theme="#{escape_attr(theme)}") unless theme.nil? unless escalation_threshold.nil? parts << %(data-escalation-threshold="#{escalation_threshold}") end parts << "async></script>" parts.join(" ") end |