Sha256: d1be71400242976d5c1e538d0134e41b1987ae639abf728fc039e5ee41d9b7b4

Contents?: true

Size: 1.14 KB

Versions: 4

Compression:

Stored size: 1.14 KB

Contents

class ChangelogsController < ApplicationController
  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

  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
end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
station-0.5.16 lib/nexmo_developer/app/controllers/changelogs_controller.rb
station-0.5.15 lib/nexmo_developer/app/controllers/changelogs_controller.rb
station-0.5.14 lib/nexmo_developer/app/controllers/changelogs_controller.rb
station-0.5.13 lib/nexmo_developer/app/controllers/changelogs_controller.rb