Sha256: 74c61e6e872ae54c3101efc1db404a10a4c8df5c7300edf8c9fe6b6460d72e51

Contents?: true

Size: 1.81 KB

Versions: 18

Compression:

Stored size: 1.81 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] || @sidenav_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
    return "https://#{ENV['HEROKU_APP_NAME']}.herokuapp.com" if ENV['HEROKU_APP_NAME']

    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

18 entries across 18 versions & 1 rubygems

Version Path
station-0.5.16 lib/nexmo_developer/app/helpers/application_helper.rb
station-0.5.15 lib/nexmo_developer/app/helpers/application_helper.rb
station-0.5.14 lib/nexmo_developer/app/helpers/application_helper.rb
station-0.5.13 lib/nexmo_developer/app/helpers/application_helper.rb
station-0.5.12 lib/nexmo_developer/app/helpers/application_helper.rb
station-0.5.11 lib/nexmo_developer/app/helpers/application_helper.rb
station-0.5.10 lib/nexmo_developer/app/helpers/application_helper.rb
station-0.5.9 lib/nexmo_developer/app/helpers/application_helper.rb
station-0.5.8 lib/nexmo_developer/app/helpers/application_helper.rb
station-0.5.7 lib/nexmo_developer/app/helpers/application_helper.rb
station-0.5.6 lib/nexmo_developer/app/helpers/application_helper.rb
station-0.5.5 lib/nexmo_developer/app/helpers/application_helper.rb
station-0.5.4 lib/nexmo_developer/app/helpers/application_helper.rb
station-0.5.3 lib/nexmo_developer/app/helpers/application_helper.rb
station-0.5.2 lib/nexmo_developer/app/helpers/application_helper.rb
station-0.5.1 lib/nexmo_developer/app/helpers/application_helper.rb
station-0.5.0 lib/nexmo_developer/app/helpers/application_helper.rb
station-0.4.9 lib/nexmo_developer/app/helpers/application_helper.rb