Module: HeapAPI::Helpers
- Included in:
- Client
- Defined in:
- lib/heap-helpers/helpers.rb
Overview
Helper tags.
Constant Summary collapse
- JS_SNIPPET =
The fragments that make up the Heap JS snippet.
File.read(File.join(File.dirname(__FILE__), 'snippet.js')). split('$$args')
- JS_OPTIONS =
Maps Ruby-esque snake_case heap.js options to JS-esque CamelCase options.
{ :force_ssl => 'forceSSL', :secure_cookie => 'secureCookie', :disable_text_capture => 'disableTextCapture', }
Instance Attribute Summary collapse
-
#js_options ⇒ Hash<Symbol, Object>
Default heap.js advanced options.
Instance Method Summary collapse
-
#javascript_tag(options = {}) ⇒ ActiveSupport::SafeBuffer
Generates a <script> tag that includes and configures heap.js.
Instance Attribute Details
#js_options ⇒ Hash<Symbol, Object>
Returns default heap.js advanced options.
41 42 43 |
# File 'lib/heap-helpers/helpers.rb', line 41 def @js_options end |
Instance Method Details
#javascript_tag(options = {}) ⇒ ActiveSupport::SafeBuffer
Generates a <script> tag that includes and configures heap.js.
The tag should be inserted before the closing </head> tag on each page of the site.
18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 |
# File 'lib/heap-helpers/helpers.rb', line 18 def javascript_tag( = {}) ensure_valid_app_id! app_string = app_id.inspect option_strings = [] .merge().each do |key, value| unless js_key = JS_OPTIONS[key] raise ArgumentError, "Invalid heap.js advanced option #{key.inspect}" end option_strings << "#{js_key}:#{!!value}" end if option_strings.empty? js_args = app_string else js_args = "#{app_string},{#{option_strings.join(',')}}" end JS_SNIPPET.join(js_args).html_safe end |