Class: TutorialController

Inherits:
ApplicationController show all
Defined in:
lib/nexmo_developer/app/controllers/tutorial_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

#indexObject



25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
# File 'lib/nexmo_developer/app/controllers/tutorial_controller.rb', line 25

def index
  if @tutorial_step == 'prerequisites'
    @content = render_to_string(partial: 'prerequisites', layout: false)
  else
    @content = Nexmo::Markdown::Renderer.new({
      code_language: @code_language,
      current_user: current_user,
    }).call(@tutorial.content_for(@tutorial_step))
  end

  # If it's an intro/conclusion we can't link to a specific task, so make sure that
  # we're linking to a non-product tutorial link as the canonical link
  if ['introduction', 'conclusion'].include?(@tutorial_step)
    @canonical_url = helpers.canonical_base + request.original_fullpath.gsub(%r{^/#{params[:product]}}, '')
  else
    # Otherwise it's a single step, which we can link to
    @canonical_url = "#{helpers.canonical_base}/task/#{@tutorial_step}"
  end

  render layout: 'documentation'
end

#listObject



9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
# File 'lib/nexmo_developer/app/controllers/tutorial_controller.rb', line 9

def list
  @product = params['product']
  @code_language = params['code_language']

  if @product
    @tutorials = TutorialList.tasks_for_product(@product)
  else
    @tutorials = TutorialList.all
  end
  @tutorials = @tutorials.select { |t| t.languages.include?(@code_language) } if @code_language

  @document_title = 'Tutorials'

  render layout: 'page'
end

#singleObject



47
48
49
50
51
52
53
54
55
# File 'lib/nexmo_developer/app/controllers/tutorial_controller.rb', line 47

def single
  path = "#{Rails.configuration.docs_base_path}/_tutorials/#{I18n.default_locale}/#{params[:tutorial_step]}.md"
  @content = File.read(path)
  @content = Nexmo::Markdown::Renderer.new({
                                    code_language: @code_language,
                                    current_user: current_user,
                                  }).call(@content)
  render layout: 'documentation'
end