Module: ApplicationHelper

Included in:
ApplicationController, SearchController
Defined in:
lib/nexmo_developer/app/helpers/application_helper.rb

Constant Summary collapse

CONFIG =
{}.freeze

Instance Method Summary collapse

Instance Method Details

#active_sidenav_itemObject



18
19
20
21
22
23
24
# File 'lib/nexmo_developer/app/helpers/application_helper.rb', line 18

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

#canonical_baseObject



36
37
38
39
40
# File 'lib/nexmo_developer/app/helpers/application_helper.rb', line 36

def canonical_base
  return "https://#{ENV['HEROKU_APP_NAME']}.herokuapp.com" if ENV['HEROKU_APP_NAME']

  canonical_base_from_config || request.base_url
end

#canonical_base_from_configObject



65
66
67
# File 'lib/nexmo_developer/app/helpers/application_helper.rb', line 65

def canonical_base_from_config
  CONFIG['base_url']
end

#canonical_pathObject



26
27
28
# File 'lib/nexmo_developer/app/helpers/application_helper.rb', line 26

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

#canonical_urlObject



30
31
32
33
34
# File 'lib/nexmo_developer/app/helpers/application_helper.rb', line 30

def canonical_url
  return @canonical_url if @canonical_url

  canonical_path.prepend(canonical_base)
end


42
43
44
45
46
47
48
49
50
51
52
53
54
55
# File 'lib/nexmo_developer/app/helpers/application_helper.rb', line 42

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

#search_enabled?Boolean

Returns:

  • (Boolean)


8
9
10
# File 'lib/nexmo_developer/app/helpers/application_helper.rb', line 8

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


57
58
59
60
61
62
63
# File 'lib/nexmo_developer/app/helpers/application_helper.rb', line 57

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

#themeObject



12
13
14
15
16
# File 'lib/nexmo_developer/app/helpers/application_helper.rb', line 12

def theme
  return unless ENV['THEME']

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