Class: ChangelogsController

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



2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
# File 'lib/nexmo_developer/app/controllers/changelogs_controller.rb', line 2

def index
  return if ENV['CHANGELOGS_PATH'].blank?

  @titles = Dir.glob("#{ENV['CHANGELOGS_PATH']}/**")
               .select { |e| File.directory? e }
               .map do |folder_path|
    {
      title: File.basename(folder_path),
      files: Dir.glob("#{folder_path}/*.md").map do |md_file|
        {
          file_title: File.basename(md_file, '.md'),
          frontmatter: File.read(md_file).match(/\A(---.+?---)/mo) ? YAML.safe_load(File.read(md_file)) : {},
        }
      end,
    }
  end
end

#showObject



20
21
22
23
24
25
26
27
28
29
30
31
32
# File 'lib/nexmo_developer/app/controllers/changelogs_controller.rb', line 20

def show
  page_title  = helpers.sanitize(params[:name])
  folder_name = helpers.sanitize(params[:folder])

  if File.exist?("#{ENV['CHANGELOGS_PATH']}/#{folder_name}/#{page_title}.md")
    page = Dir.glob("#{ENV['CHANGELOGS_PATH']}/#{folder_name}/#{page_title}.md").first
    document = File.read(page).gsub(/\A(---.+?---)/mo, '')
  else
    document = "<h3>Sorry, this file doesn't exist!</h3><code><strong>/_changelogs/#{folder_name}/#{page_title}.md</strong></code>"
  end

  @content = Nexmo::Markdown::Renderer.new({}).call(document)
end