README.md in lolita-3.2.0.rc.7 vs README.md in lolita-3.2.0.rc.9
- old
+ new
@@ -16,22 +16,28 @@
rails g lolita:install
That will create initializer and copy all assets.
Also it will call *install* on all added modules to lolita.
So if you in Gemfile have following
-
- gem "lolita"
- gem "lolita-file-upload"
+
+```ruby
+gem "lolita"
+gem "lolita-file-upload"
+```
+
It will also call *lolita_file_upload:install*.
##Usage
To make your model use Lolita do like this
- class Post < ActiveRecord::Base
- include Lolita::Configuration
- lolita
- end
+```ruby
+class Post < ActiveRecord::Base
+ include Lolita::Configuration
+ lolita
+end
+```
+
Then in routes.rb file make resources accessable for lolita with
lolita_for :posts
This will make routes like
`/lolita/posts`
@@ -44,17 +50,23 @@
###Add authorization to Lolita
Easiest way to add authentication is with Devise. First install Devise as gem, than add it to your project.
Make Devise model, lets say, *User*. After that add these lines in */config/initializers/lolita.rb*
- config.user_classes << User
- config.authentication = :authenticate_user!
+```ruby
+config.user_classes << User
+config.authentication = :authenticate_user!
+```
+
This will make before each Lolita requests call before filter, that than will call *authenticate_user!*
that is Devise method for authenticating user. Without it Lolita will be acessable for everyone.
You can also add any other authentication method like
-
- config.authentication = :authenticate_admin
+
+```ruby
+config.authentication = :authenticate_admin
+```
+
And than put this method for common use in *ApplicationController* or in some other place that is accessable
to all controllers.
###Using hooks
@@ -63,47 +75,62 @@
There are two kind of hooks for all actions - *before_[action name]* and *after_[action name]*.
Define callbacks for those hooks outside of controller. This will call User#log_action each time when #destroy
action is requested.
- Lolita::RestController.before_destroy do
- User.log_action("Going to delete #{params[:id]}")
- end
+```ruby
+Lolita::RestController.before_destroy do
+ User.log_action("Going to delete #{params[:id]}")
+end
+```
+
Also you can define callbacks in your controllers that extend Lolita::RestController. This will call #set\_default\_params
each time #new action is requested.
- class PostController < Lolita::RestController
- before_new :set_default_params
+```ruby
+class PostController < Lolita::RestController
+ before_new :set_default_params
- private
+ private
- def set_default_params
- params[:post][:title]="-Your title goes here-"
- end
- end
+ def set_default_params
+ params[:post][:title]="-Your title goes here-"
+ end
+end
+```
+
####Component hooks
Components have three hooks - *before*, *after* and *around*.
Component hooks are different from controller hooks with names. Each component has it's own name, that is used to
call component, like
- render_component :"lolita/configuration/list/display"
- #same as
- render_component :"lolita/configuration/list", :display
+```ruby
+render_component :"lolita/configuration/list/display"
+#same as
+render_component :"lolita/configuration/list", :display
+```
+
and this name is used to add callback for component. As components is not related to specific class, then there
are only one way to define callback for them.
- Lolita::Hooks.component(:"/lolita/configuration/list/display").before do
- "<div>My Custom text</div>"
- end
+```ruby
+Lolita::Hooks.component(:"/lolita/configuration/list/display").before do
+ "<div>My Custom text</div>"
+end
+```
+
That what are inside of blocks depends on place where you define callback if it is in _.rb_ file, than you
should put HTML in quotes, if in _.erb_ and similar files then there is no need for that. Also blocks with
Ruby code only return last line, so you should probably define HTML as shown in previous example.
For _around_ callback if you pass block, then original content will be replaced with that, but if you want
to let original content inside of your block content than it is done like this with #let_content method.
- Lolita::Hooks.component(:"/lolita/configuration/list/display").around do
- "<div style='color:red'>#{let_content}</div>"
- end
+```ruby
+Lolita::Hooks.component(:"/lolita/configuration/list/display").around do
+ "<div style='color:red'>#{let_content}</div>"
+end
+```
+
##License
Lolita is under MIT license. See [LICENSE.txt](https://github.com/ithouse/lolita/blob/master/LICENSE.txt)
\ No newline at end of file