Sha256: 53a63459ceb462b2947383a5cadce90e3a292ca1b7d95abac351d1b326171e12

Contents?: true

Size: 780 Bytes

Versions: 2

Compression:

Stored size: 780 Bytes

Contents

require_dependency 'docs_api/application_controller'

module DocsApi
  class DocsController < ApplicationController
    def index
      @versions = []
      doc_dir = Rails.root.join('app', 'docs', '*')
      Dir.glob(doc_dir).each do |entry|
        @versions.push(entry.split('/').last) if File.directory? entry
      end
    end

    def show
      docs = Dir.glob(Rails.root.join('app', 'docs', params[:id], '*.md'))
      raise ActiveRecord::RecordNotFound if docs.blank?

      url = request.protocol + request.host_with_port
      @api_text = "FORMAT: 1A\nHOST: #{url}\n# #{url}\nAPI doc\n"

      docs.sort_by { |d| d.split('/').last }.each do |doc|
        @api_text += File.read(doc) + "\n"
      end
      @api_text.gsub!('"', '\"').gsub!("\n", '\n')
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
docs_api-0.0.2 app/controllers/docs_api/docs_controller.rb
docs_api-0.0.1 app/controllers/docs_api/docs_controller.rb