Skip to content
Browse files

adding notes about using Rails gems like simple_form in the README an…

…d releasing 3.8.5.
  • Loading branch information...
1 parent b5578b0 commit 00329724526e460a9096ccafbadc85d6f15d0ea7 @apotonick committed Jun 25, 2012
Showing with 48 additions and 5 deletions.
  1. +5 −0 CHANGES.textile
  2. +39 −1 README.rdoc
  3. +1 −1 lib/cells/version.rb
  4. +3 −3 test/rails_helper_api_test.rb
View
5 CHANGES.textile
@@ -1,3 +1,8 @@
+h2. 3.8.5
+
+* Added @Cell::Rails::HelperAPI@ module to provide the entire Rails view "API" (quotes on purpose!) in cells running completely outside of Rails. This makes it possible to use gems like simple_form in any Ruby environment, especially interesting for people using Sinatra, webmachine, etc.
+* Moved @Caching.expire_cache_key@ to @Rails@. Use @Caching.expire_cache_key_for(key, cache_store, ..)@ if you want to expire caches outside of Rails.
+
h2. 3.8.4
* Added @Cell::Rack@ for request-dependent Cells. This is also the new base class for @Cells::Rails@.
View
40 README.rdoc
@@ -186,11 +186,49 @@ In your <tt>routes.rb</tt> file, mount the cell like a Rack app.
[ 200, {}, [ Cell::Base.render_cell_for(:post, :show) ]]
}
+
+== Using Rails Gems Like simple_form Outside Of Rails
+
+Cells can be used outside of Rails. A new module brought in 3.8.5 provides the Rails view "API" making it possible to use gems like the popular {simple_form}[https://github.com/plataformatec/simple_form] outside Rails!
+
+All you need to do is providing the cell with some helpers, usually it's the polymorphic routing paths required by the gems.
+
+ module RoutingHelpers
+ def musician_path(model)
+ "/musicians/#{model.id}"
+ end
+ end
+
+Then, use the @Cell::Rails::HelperAPI@ module and it should work fine (depending on the quality of the gem you're desiring to use).
+
+ require 'cell/base'
+ require "cell/rails/helper_api"
+ require "simple_form"
+
+ class BassistCell < Cell::Base
+ include Cell::Rails::HelperAPI
+
+ self._helpers = RoutingHelpers
+
+ def show
+ @musician = Musician.find(:first)
+ end
+ end
+
+Your views can now use the gem's helpers.
+
+ <%= simple_form_for @musician do |f| %>
+ <%= f.input :name %>
+ <%= f.button :submit %>
+ <% end %>
+
+Note that this currently "only" works with Rails 3.2.
+
== Cells is Rails::Engine aware!
Now <tt>Rails::Engine</tt>s can contribute to Cells view paths. By default, any 'app/cells' found inside any Engine is automatically included into Cells view paths. If you need to, you can customize the view paths changing/appending to the <tt>'app/cell_views'</tt> path configuration. See the @Cell::EngineIntegration@ for more details.
-== Custom base class
+== Generators
By default, generated cells inherit from <code>Cell::Rails</code>. If you want to change this, specify your new class name in <code>config/application.rb</code>:
View
2 lib/cells/version.rb
@@ -1,3 +1,3 @@
module Cells
- VERSION = '3.8.4'
+ VERSION = '3.8.5'
end
View
6 test/rails_helper_api_test.rb
@@ -21,7 +21,7 @@ def persisted?
end
- class FakeRoutes # should be sinatra's url helper instance
+ class FakeUrlFor # should be sinatra's url helper instance
def url_for(*)
end
end
@@ -37,7 +37,7 @@ class BassistCell < Cell::Base
include Cell::Rails::HelperAPI
self._helpers = FakeHelpers
- self._routes = FakeRoutes.new
+ self._routes = FakeUrlFor.new
def edit
@tone = "C"
@@ -53,7 +53,7 @@ def edit
<div class="input string required"><label class="string required" for="fruit_title"><abbr title="required">*</abbr> Title</label><input class="string required" id="fruit_title" name="fruit[title]" required="required" size="50" type="text" value="Banana" /></div>
<input class="button" name="commit" type="submit" value="Create Fruit" />
</form>
-', BassistCell.new.render_state(:edit)
+', BassistCell.new.render_state(:edit) if Cell.rails3_1_or_more? and Rails::VERSION::MINOR == 2
end
end
end

0 comments on commit 0032972

Please sign in to comment.
Something went wrong with that request. Please try again.