Sha256: 840a847e9dafb0c1776f02c3bb27744356725623bc68a631b74a70a333e2e835

Contents?: true

Size: 1.26 KB

Versions: 78

Compression:

Stored size: 1.26 KB

Contents

module Brief::Server::Handlers
  class Show
    def self.handle(path_args, briefcase, options={})
      action    = options.fetch(:action)
      request   = options.fetch(:request)
      parts     = path_args.split("/")
      view      = parts.shift.to_s.downcase
      path      = parts.join("/")

      document = begin
                   briefcase.document_at(path)
                 rescue Brief::Repository::InvalidPath
                   :forbidden
                 end

      code          = 200
      content_type  = "application/json"

      case
      when document.nil?
        code = 404
        body = {error: "Not found"}
      when document == :forbidden
        code = 403
        body = {error: "Access denied." }
      when !%w(content rendered details).include?(view)
        code = 400
        body = {error: "Invalid view: must be content, rendered, details" }
      when document && view == "content"
        body = document.combined_data_and_content
        content_type = "text/plain"
      when document && view == "rendered"
        body = document.to_html
        content_type = "text/html"
      when document && view == "details"
        body = document.to_model.as_json(request.params)
      end

      [code, {"Content-Type"=>content_type}, body]
    end
  end
end

Version data entries

78 entries across 78 versions & 1 rubygems

Version Path
brief-1.17.14 lib/brief/server/handlers/show.rb
brief-1.17.13 lib/brief/server/handlers/show.rb
brief-1.17.12 lib/brief/server/handlers/show.rb
brief-1.17.11 lib/brief/server/handlers/show.rb
brief-1.17.10 lib/brief/server/handlers/show.rb
brief-1.17.9 lib/brief/server/handlers/show.rb
brief-1.17.8 lib/brief/server/handlers/show.rb
brief-1.17.7 lib/brief/server/handlers/show.rb
brief-1.17.5 lib/brief/server/handlers/show.rb
brief-1.17.4 lib/brief/server/handlers/show.rb
brief-1.17.3 lib/brief/server/handlers/show.rb
brief-1.17.2 lib/brief/server/handlers/show.rb
brief-1.17.1 lib/brief/server/handlers/show.rb
brief-1.17.0 lib/brief/server/handlers/show.rb
brief-1.16.2 lib/brief/server/handlers/show.rb
brief-1.16.1 lib/brief/server/handlers/show.rb
brief-1.16.0 lib/brief/server/handlers/show.rb
brief-1.15.5 lib/brief/server/handlers/show.rb
brief-1.15.4 lib/brief/server/handlers/show.rb
brief-1.15.3 lib/brief/server/handlers/show.rb