Sha256: ca9a476404ca74b232c862d18a615f746dcfac90089875ae89e7dd542c645688

Contents?: true

Size: 843 Bytes

Versions: 1

Compression:

Stored size: 843 Bytes

Contents

module Seymour

  class RenderError < RuntimeError
  end

  module Renderable
    extend ActiveSupport::Concern

    def render_html
      render("seymour/render", "activity", "seymour.activity" => self)
    rescue RenderError
      return nil
    end

    def render(controller_name, action_name, env = {})
      # TODO define proper server name
        # { "REQUEST_URI" => "", "SERVER_NAME" => 'http://www.example.com' }.merge(env))

      env = Rack::MockRequest.env_for("/",
        { "REQUEST_URI" => "", "SERVER_NAME" => '' }.merge(env))

      controller_class = "#{controller_name}_controller".classify.constantize

      status, headers, response = controller_class.action(action_name.to_sym).call(env)
      raise RenderError.new("#{controller_name}##{action_name}") unless status.to_i == 200
      response.body
    end

  end

end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
seymour-0.0.9 lib/seymour/renderable.rb