module Render::Editor

Editor allows a document to be displayed in an editing form @author Bryan T. Meyers

Public Class Methods

do_read(actions, context) click to toggle source

Open an editor for a document @param [Array] actions the allowed actions for this URI @param [Hash] context the context for this request @return [Response] the Editor with containing document, or status code

# File lib/app/render/editor.rb, line 27
def self.do_read(actions, context)
  response = context.forward(:read)
  body     = (response[0] == 200) ? response[2] : ''
  if context.query[:type]
    mime = context.query[:type]
  elsif response[1]['content-type']
    mime = response[1]['content-type']
  else
    return [404, {}, 'EDITOR: Document type not set for new document']
  end
  template = nil
  context.closet.editors.each do |k, v|
    if v['mimes'].include? mime
      template = v['file']
      break
    end
  end
  if template
    template.render(self, { actions:  actions,
                            resource: context.resource,
                            id:       context.id,
                            mime:     mime,
                            response: body })
  else
    return [404, {}, 'EDITOR: Editing of this file type is not supported']
  end
end
invoke(actions, context) click to toggle source

Proxy method used when routing @param [Array] actions the allowed actions for this URI @param [Hash] context the context for this request @return [Response] a Rack Response triplet, or status code

# File lib/app/render/editor.rb, line 59
def self.invoke(actions, context)
  case context.action
    when :create, :update
      context.forward(context.action)
    when :read
      do_read(actions, context)
    else
      405
  end
end