Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

+ README

  • Loading branch information...
commit f8c741a1982e80c65cd50cfc7274743378ed2938 1 parent 3deb40c
Florian Hanke authored
Showing with 61 additions and 0 deletions.
  1. +1 −0  .gitignore
  2. +60 −0 README
View
1  .gitignore
@@ -0,0 +1 @@
+.DS_Store
View
60 README
@@ -0,0 +1,60 @@
+# This plugin is a simple alternative for components.
+# It is not a full replacement, however. It aims lower, namely:
+# - Sub-per-action component definitions.
+# - Built-in caching.
+#
+# It is good, when:
+# 1. You wish to define certain view parts that are used for many controller actions.
+# 2. You wish to cache these view parts.
+# 3. You wish to not have specific controllers to load the content for these view parts.
+#
+# Good use cases:
+# - Checkout Cart displayed in site sidebar.
+# - Explorative Elements (e.g. Top Ten Books) in Sidebars.
+# - Navigational Elements on almost all pages.
+# - And so on…
+
+# In the view, e.g. application.haml call
+render_context(category)
+
+# Example:
+render_context(:left_sidebar)
+# In this case, the specific context is determined by the controller, just
+# define the context for this controller as follows:
+context :left_sidebar, :top_ten_books
+# if you wish to differentiate between actions, define the default first, then specific contexts
+# for specific actions
+context :left_sidebar, :top_ten_books,
+ [:buy, :browse] => :other_books_you_might_like,
+ :login => :welcome
+# For the login action you wish to display the welcome context in the left sidebar, for the buy and browse action, some exploratory books are shown. For all other actions, e.g. index, edit, show, just show the current top ten books.
+
+# OR if the specific context type should not be determined by the controller:
+render_context(category, type)
+
+# Example
+render_context(:left_sidebar, :top_ten_books)
+# This just renders the context for the top ten books in the left sidebar
+
+# Loading variables for your contexts is done in the ApplicationController (or in the Controller needed)
+#
+# In your ApplicationController call
+load_context(category, type, [options], &loading_instance_variables_block)
+
+# Currently supported options are:
+# :cache => true
+
+# Example:
+load_context :left_sidebar, :top_ten_books, :cache => true do
+ @books = Books.top(10)
+end
+# This loads the top ten books into the variable @books, which can then be used in the view file top_ten_books.haml:
+%h1 Top Ten Books
+- for book in @books do
+ %h2= book.title
+ %p= book.description
+ = link_to_add_to_cart(book)
+# The context view files should be in views/contexts/<category>/<type>.haml (or .erb)
+#
+# Example: The above file would be in
+# app/views/contexts/left_sidebar/top_ten_books.haml
Please sign in to comment.
Something went wrong with that request. Please try again.