Class: StaticController

Inherits:
ApplicationController show all
Defined in:
lib/nexmo_developer/app/controllers/static_controller.rb

Constant Summary

Constants included from ApplicationHelper

ApplicationHelper::CONFIG

Instance Method Summary collapse

Methods inherited from ApplicationController

#authenticate_admin!, #not_found, #redirect_vonage_domain

Methods included from ApplicationHelper

#active_sidenav_item, #canonical_base, #canonical_base_from_config, #canonical_path, #canonical_url, #dashboard_cookie, #search_enabled?, #set_utm_cookie, #theme

Instance Method Details



163
164
165
166
167
168
169
170
171
172
173
174
175
# File 'lib/nexmo_developer/app/controllers/static_controller.rb', line 163

def blog_cookie
  # These are the things we'll be tracking through the customer dashboard
  utm_params = {
    'utm_medium' => 'dev_education',
    'utm_source' => 'blog',
  }

  utm_params.merge!('utm_campaign' => params['c']) if params['c']
  utm_params.merge!('utm_content'  => params['ct']) if params['ct']
  utm_params.merge!('utm_term'     => params['t']) if params['t']

  redirect_to "https://dashboard.nexmo.com/sign-up?#{utm_params.to_query}"
end

#communityObject



114
115
116
117
118
119
120
121
# File 'lib/nexmo_developer/app/controllers/static_controller.rb', line 114

def community
  @navigation = :community
  @document_title = 'Community'
  @upcoming_events = Event.upcoming
  @past_events_count = Event.past.count
  @sessions = Session.visible_to(current_user).order(created_at: :desc)
  render layout: 'page'
end

#default_landingObject



4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
# File 'lib/nexmo_developer/app/controllers/static_controller.rb', line 4

def default_landing
  yaml_name = request[:landing_page]

  if File.exist?("#{Rails.configuration.docs_base_path}/custom/landing_pages/#{yaml_name}.yml")
    @landing_config = YAML.load_file("#{Rails.configuration.docs_base_path}/custom/landing_pages/#{yaml_name}.yml")
  else
    @landing_config = YAML.load_file("#{Rails.root}/config/landing_pages/#{yaml_name}.yml")
  end

  @landing_config['page'].each do |row|
    some_columns_have_widths = row['row'].select { |c| c['width'] }.count.positive?
    if some_columns_have_widths
      row['row'] = row['row'].map do |c|
        c['width'] ||= 1
        c
      end
      row['column_count'] = row['row'].map { |c| c['width'] }.sum
    end
  end

  if request.path.delete('/') == 'community'
    @upcoming_events = Event.upcoming
    @past_events_count = Event.past.count
    @navigation = :community

    @hash = Gmaps4rails.build_markers(@upcoming_events.reject(&:remote?)) do |event, marker|
      event.geocode
      marker.lat event.latitude
      marker.lng event.longitude
      marker.infowindow event.title
    end
  end

  if request.path.delete('/') == 'team'
    @team ||= LoadConfig.load_file('config/team.yml')

    @team['current'] = @team['current'].map do |member|
      Blog::Author.new(AuthorParser.fetch_author(member['short-name']))
    end

    @careers = Greenhouse.devrel_careers
  end

  if request.path.sub!('/', '') == 'migrate/tropo/sms'
    migrate_tropo
  elsif request.path.sub!('/', '') == 'migrate/tropo/voice'
    migrate_tropo
  end

  @frontmatter = @landing_config
  @document_title = @landing_config['title']
  @navigation = yaml_name.to_sym
  render layout: 'landing'
end

#documentationObject



79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
# File 'lib/nexmo_developer/app/controllers/static_controller.rb', line 79

def documentation
  document ||= Nexmo::Markdown::DocFinder.find(
    root: "#{Rails.configuration.docs_base_path}/_documentation",
    document: 'index',
    language: params[:locale]
  )

  @document_path = document.path

  # Parse frontmatter
  @frontmatter = YAML.safe_load(document.path)

  @document_title = @frontmatter['title']

  @content = Nexmo::Markdown::Renderer.new(locale: params[:locale]).call(File.read(document.path))

  @navigation = :documentation

  @sidenav = Sidenav.new(
    request_path: request.path,
    navigation: @navigation,
    product: @product,
    locale: params[:locale]
  )

  render layout: 'documentation'
end

#event_searchObject



59
60
61
62
63
64
65
66
67
68
69
70
71
72
# File 'lib/nexmo_developer/app/controllers/static_controller.rb', line 59

def event_search
  @events = Event.search(params[:query]) if params[:query]

  @hash = Gmaps4rails.build_markers(@events.reject(&:remote?)) do |event, marker|
    event.geocode
    marker.lat event.latitude
    marker.lng event.longitude
    marker.infowindow event.title
  end

  respond_to do |format|
    format.js { render partial: 'static/default_landing/partials/event_search_results.js.erb' }
  end
end

#landingObject



74
75
76
77
# File 'lib/nexmo_developer/app/controllers/static_controller.rb', line 74

def landing
  @homepage = true
  render layout: 'landing'
end

#landing_page_documentationObject



107
108
109
110
111
112
# File 'lib/nexmo_developer/app/controllers/static_controller.rb', line 107

def landing_page_documentation
  @homepage = true
  @landing_info ||= LoadConfig.load_file('config/documentation_page/en/doc_landing.yml')

  render layout: 'landing_page_documentation'
end

#migrate_tropoObject



143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
# File 'lib/nexmo_developer/app/controllers/static_controller.rb', line 143

def migrate_tropo
  @active_title = 'Migrate from Tropo'

  @building_blocks = @landing_config['page'][0]['row'][0]['column'][0]['migrate_details']['blocks'].map do |block|
    block['nexmo'] = "<h2>Nexmo</h2>
      ```code_snippets
        code_only: true
        source: #{block['nexmo']}
      ```"

    block['tropo'] = "<h2>Tropo</h2>
      ```code_snippets
        code_only: true
        source: #{block['tropo']}
      ```"

    block
  end
end

#past_eventsObject



123
124
125
126
127
128
# File 'lib/nexmo_developer/app/controllers/static_controller.rb', line 123

def past_events
  @navigation = :community
  @document_title = 'Community'
  @past_events = Event.past
  render layout: 'page'
end

#robotsObject



130
131
132
133
134
# File 'lib/nexmo_developer/app/controllers/static_controller.rb', line 130

def robots
  respond_to do |format|
    format.any { render plain: 'robots', layout: false, content_type: 'text/plain' }
  end
end

#teamObject



136
137
138
139
140
141
# File 'lib/nexmo_developer/app/controllers/static_controller.rb', line 136

def team
  @team ||= LoadConfig.load_file('config/team.yml')
  @careers = Greenhouse.devrel_careers

  render layout: 'page'
end