From c6b1febce46998953d0962f0ce4b1baa0af62707 Mon Sep 17 00:00:00 2001 From: Florian Hanke Date: Mon, 30 May 2011 14:02:38 +1000 Subject: [PATCH] + Hi stupid, meet stupid --- README.textile | 58 +++++++++++++++----------------------------------- 1 file changed, 17 insertions(+), 41 deletions(-) diff --git a/README.textile b/README.textile index 69ac196..edb11e9 100644 --- a/README.textile +++ b/README.textile @@ -30,47 +30,37 @@ h2. Usage In the view, e.g. application.haml call -```ruby -render_context context_category_name -``` +
render_context context_category_name
h3. Examples h4. Context chosen defined in the controller. -```ruby -render_context :left_sidebar -``` +
render_context :left_sidebar
In this case, the specific context is determined by the controller, just define the context for this controller as follows: -```ruby - +

 context context_category_name,
   default_context_name,
   [action_name, other_action_name] => action_specific_context_name,
-  some_other_action_name => yet_another_action_specific_context_name
-```
+  some_other_action_name => yet_another_action_specific_context_name
*OR* by using a block -```ruby -context context_category_name do +
context context_category_name do
   # determine a context type as you wish (e.g. randomly),
   # then return the context name
-end
-```
+end
Use @top_ten_books@ as context for the context category @left_sidebar@ in _all_ actions: -```ruby -context :left_sidebar, :top_ten_books -``` +
context :left_sidebar, :top_ten_books
@@ -78,17 +68,13 @@ Use top_ten_books as context for the context category @left_sidebar@ in all actions _except_ @buy@, @browse@ and @login@. Use @other_books_you_might_like@ for @buy@ and @browse@, and @welcome@ for the @login@ action: -```ruby -context :left_sidebar, :top_ten_books, +
context :left_sidebar, :top_ten_books,
   [:buy, :browse] => :other_books_you_might_like,
-  :login => :welcome
-```
+  :login => :welcome
*OR* if the specific context type should _not_ be determined by the controller. -```ruby -render_context context_category_name, context_type_name -``` +
render_context context_category_name, context_type_name
h4. Explicit context (Context not determined in the controller). @@ -96,9 +82,7 @@ The following just renders the context for the top ten books in the left sidebar without asking the controller to determine which context type should be used for the left sidebar. -```ruby -render_context :left_sidebar, :top_ten_books -``` +
render_context :left_sidebar, :top_ten_books
h4. Loading variables for your contexts. @@ -107,33 +91,25 @@ Loading variables for your contexts is done in the ApplicationController In your ApplicationController call the following to load instance variables for the context in category and type. -```ruby -load_context(category, type, options = {}, &loading_instance_variables_block) -``` +
load_context(category, type, options = {}, &loading_instance_variables_block)
Currently supported options are @cache@, e.g.: -```ruby -:cache => 7.minutes -``` +
:cache => 7.minutes
This loads the top ten books into the variable @@books@: -```ruby -load_context :left_sidebar, :top_ten_books, :cache => 5.minutes do +
load_context :left_sidebar, :top_ten_books, :cache => 5.minutes do
   @books = Books.top(10)
-end
-```
+end
which can then be used in the partial @contexts/left_sidebar/_top_ten_books.html.haml@: -```ruby -%h1 Top Ten Books +
%h1 Top Ten Books
 - for book in @books do
   %h2= book.title
   %p= book.description
-  = link_to_add_to_cart(book)
-```
+  = link_to_add_to_cart(book)
The context view files should be in @views/contexts//.html.haml@ (or @.text.erb@ or what have you, depending on the request format)