Permalink
Browse files

moving Rack to separate file.

  • Loading branch information...
1 parent 34eaf6e commit 9822db453b88654936795b14cd82d5edee6df8b0 @apotonick apotonick committed Apr 24, 2012
Showing with 36 additions and 0 deletions.
  1. +36 −0 lib/cell/rack.rb
View
@@ -0,0 +1,36 @@
+require 'cell/base'
+
+module Cell
+ # Use Cell::Rack to mount your cell to a rack-route with a working +session+ and +params+ reference
+ # in the cell. This is especially useful when using gems like devise with your cell, without the
+ # entire Cell::Rails overhead.
+ #
+ # The only dependency these kinds of cells have is a rack-compatible request object.
+ #
+ # Example:
+ #
+ # match "/dashboard/comments" => proc { |env|
+ # request = ActionDispatch::Request.new(env)
+ # [ 200, {}, [ Cell::Rack.render_cell_for(:comments, :show, request) ]]
+ # }
+ class Rack < Base
+ attr_reader :request
+ delegate :session, :params, :to => :request
+
+ class << self
+ # DISCUSS: i don't like these class methods. maybe a RenderingStrategy?
+ def create_cell(request, *args) # defined in Builder.
+ new(request)
+ end
+
+ def render_cell_state(cell, state, request, *args) # defined in Rendering.
+ super(cell, state, *args)
+ end
+ end
+
+ def initialize(request)
+ super()
+ @request = request
+ end
+ end
+end

0 comments on commit 9822db4

Please sign in to comment.