Sha256: ea5d8b941cdef8fe160ad62fe9a75c086a01f3525e9e8c1bc001923760a98b26

Contents?: true

Size: 1.71 KB

Versions: 11

Compression:

Stored size: 1.71 KB

Contents

module ApplicationHelper
  if ENV['DOCS_BASE_PATH']
    CONFIG = YAML.load_file("#{Rails.configuration.docs_base_path}/config/business_info.yml")
  else
    CONFIG = {}.freeze
  end

  def search_enabled?
    defined?(ALGOLIA_CONFIG) && ENV['ALGOLIA_SEARCH_KEY']
  end

  def theme
    return unless ENV['THEME']

    "theme--#{ENV['THEME']}"
  end

  def active_sidenav_item
    if params[:tutorial_name]
      url_for(controller: :tutorial, action: :index, product: params[:product], tutorial_name: params[:tutorial_name])
    else
      request.path.chomp("/#{params[:code_language]}")
    end
  end

  def canonical_path
    request.path.chomp("/#{params[:code_language]}")
  end

  def canonical_url
    return @canonical_url if @canonical_url

    canonical_path.prepend(canonical_base)
  end

  def canonical_base
    canonical_base_from_config || request.base_url
  end

  def dashboard_cookie(campaign)
    # This is the first touch time so we only want to set it if it's not already set
    set_utm_cookie('ft', Time.now.getutc.to_i) unless cookies[:ft]

    # These are the things we'll be tracking through the customer dashboard
    set_utm_cookie('utm_source', 'developer.nexmo.com')
    set_utm_cookie('utm_medium', 'referral')
    set_utm_cookie('utm_campaign', campaign)

    # We don't use term or content as it's not paid, but they may have been set by other things
    # If they were, delete them so our data isn't tainted
    cookies.delete('utm_term', domain: :all)
    cookies.delete('utm_content', domain: :all)
  end

  def set_utm_cookie(name, value)
    cookies[name] = {
      value: value,
      expires: 1.year.from_now,
      domain: :all,
    }
  end

  def canonical_base_from_config
    CONFIG['base_url']
  end
end

Version data entries

11 entries across 11 versions & 1 rubygems

Version Path
station-0.0.106 lib/nexmo_developer/app/helpers/application_helper.rb
station-0.0.105 lib/nexmo_developer/app/helpers/application_helper.rb
station-0.0.104 lib/nexmo_developer/app/helpers/application_helper.rb
station-0.0.103 lib/nexmo_developer/app/helpers/application_helper.rb
station-0.0.102 lib/nexmo_developer/app/helpers/application_helper.rb
station-0.0.101 lib/nexmo_developer/app/helpers/application_helper.rb
station-0.0.100 lib/nexmo_developer/app/helpers/application_helper.rb
station-0.0.97 lib/nexmo_developer/app/helpers/application_helper.rb
station-0.0.96 lib/nexmo_developer/app/helpers/application_helper.rb
station-0.0.95 lib/nexmo_developer/app/helpers/application_helper.rb
station-0.0.93 lib/nexmo_developer/app/helpers/application_helper.rb