Skip to content

Commit

Permalink
updated README and added danish cream locale file
Browse files Browse the repository at this point in the history
  • Loading branch information
kristianmandrup committed Jan 4, 2011
1 parent 0fa4a7e commit 5a56318
Show file tree
Hide file tree
Showing 5 changed files with 140 additions and 25 deletions.
56 changes: 38 additions & 18 deletions README.textile
Original file line number Diff line number Diff line change
@@ -1,26 +1,45 @@
h1. Cream

This project aims to assist you in setting up a complete Authentication and Authorization system for your Rails 3 app and supports multiple ORMs.
Just run the *full_config* generator with arguments specifying: roles available, the role strategy to use and the ORM to target and you are set to go.
This project aims to assist in setting up a Rails 3 app with an integrated Authentication and Authorization solution for your ORM of choice.

Cream targets smooth integration of the following systems:
Execute the *full_config* generator with arguments specifying:

* The User roles in the app
* The role strategy to use (both single and multiple roles for each user)
* ORM to use (Relational or Document based datastores)

The generator will do its magic to your app and (hopefully) you should be set to go with implementing the remainder of your app ;)

Cream targets smooth integration of the following main systems:

* "Devise":http://github.com/plataformatec/devise - Authentication
* "CanCan":http://github.com/ryanb/cancan - Authorization
* "Roles Generic":http://github.com/kristianmandrup/roles_generic - Roles
* "Roles":http://github.com/kristianmandrup/roles_generic - Roles

Cream also uses "CanCan permits":http://github.com/kristianmandrup/cancan-permits to enable use of *Permits* and *Licenses*.

The gems "devise-links":http://github.com/kristianmandrup/devise-links and "cancan-rest-links":http://github.com/kristianmandrup/cancan-rest-links provide helpers to facilitate working with authentication links and REST links with automatic execution of user permission logic!

For more advanced Authorization configuration, cream uses *cancan-permits* to enable use of *Permits* and *Licenses*.
The gems *devise-links* and *cancan-rest-links* provide view helpers to facilitate working with authentication links and to enable REST links with permission logic.
Cream itself provides generators to easily configure your Rails 3 app with these gems and also includes various view and controller helpers to guard specific view and/or controller logic with permission requirements. Cream targets a set of common ORMs for Rails for Relational and Document based datastores.
Cream comes with a suite of specialized generators that should let you configure your Rails 3 app with these systems to a large degree.

The objectives of this project:
h2. Objectives

* Integrate all these sub-systems
* Integrate a set of widely accepted sub-systems for a fully integrated solution
* Provide generators that can auto-configure your Rails 3 app with these systems for a given ORM

For more information also see the "Cream Wiki":https://github.com/kristianmandrup/cream/wiki, which includes Cream status notes and a complete listing and usage examples of the latest *Roles Generic API*. The wiki also contains an overview of the full Cream API, which contains various helper methods to facilitate working with Users, Sessions, Roles and Permissions in both your views and controllers. Please let me know of other areas that you think should be covered in the Wiki or on this main page ;)
h2. More info

_Note_: Cream leverages an extensive set of framework components I have created specifically to make it much easier/faster to create Rails 3 plugins and spec/test them, using more natural DSLs. Look into the code to see the magic!
For more information see the "Cream Wiki":https://github.com/kristianmandrup/cream/wiki, which includes overviews of the:

* "Roles read API":https://github.com/kristianmandrup/cream/wiki/Roles-Read-API and "Roles write API":https://github.com/kristianmandrup/cream/wiki/Roles-Read-API.
* Various "Cream APIs"::https://github.com/kristianmandrup/cream/wiki (helper methods to facilitate working with Users, Sessions, Roles and Permissions).

Please let me know of other areas that you think should be covered in the Wiki or on page.

h2. The magic behind the curtain...

Cream leverages an extensive "Tool suite":https://github.com/kristianmandrup/cream/wiki/Tool-suite-for-designing-powerful-generators-and-gems-for-Rails-3 I have created specifically to make it much easier/faster to create gems and generators for Rails 3 and spec/test them with RSpec 2, all using more natural DSLs and APIs.
If you look into the Cream code you can see extensive usage of this "magic" (especially in the generators).

h2. Cream user group

Expand Down Expand Up @@ -136,6 +155,8 @@ A User subclass is now generated for each role by default in order to allow more

h2. Generators

Please see "Cream generators overview and walk-through":https://github.com/kristianmandrup/cream/wiki/Cream-generators-overview-and-walk-through for more details.

The following generators are currently available:

Main generator:
Expand Down Expand Up @@ -164,14 +185,13 @@ h3. Full Config Generator

Master cream generator which calls the sub-generators in succession.

* --strategy : role strategy to use (see *roles_generic* gem)
* --admin-user : create admin user model with separate devise configuration
* --orm : orm to be used
* --roles : list of valid roles and permits to use
* strategy : role strategy to use (see *roles_generic* gem)
* orm : orm to be used
* roles : list of valid roles and permits to use

Example
Example:

<code>rails g cream:full_config --strategy admin_flag --admin-user --orm AR</code>
<code>rails g cream:full_config --strategy admin_flag --orm AR</code>

By default creates :guest and :admin roles.

Expand All @@ -188,7 +208,7 @@ Moves 'user menu' partials views into app/views/_user_menu
<code>rails g cream:views [scope] [--haml]</code>

* scope : The scope folder under views to copy the partials to, fx 'admin'
* --haml : Use HAML as template language
* (haml) : Use HAML as template language

The *views* generator is based on a similar generator from the devise project. This generator might be removed in the near future, as the menu items would make more sense as simple view helpers (suggestions welcome).

Expand Down
16 changes: 16 additions & 0 deletions config/locales/cream.da.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
en:
cream:
confirm: 'Er du sikker?'
actions:
rest:
index: "Indeks"
new: "Ny"
edit: "Rediger"
delete: "Slet"
show: "Vis"
auth:
sign_in: "Log ind"
sign_out: "Log ud"
sign_up: "Registrer"
edit_registration: "Rediger brugerdata"

9 changes: 5 additions & 4 deletions lib/generators/cream/app/app_generator.rb
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,9 @@ class AppGenerator < ::Rails::Generators::Base

def configure_application
logger.add_logfile :logfile => logfile if logfile
app_orm

app_orm unless orm.to_sym == :active_record

app_routes
app_layout
end
Expand Down Expand Up @@ -44,8 +46,7 @@ def execute command
run command
end

def app_orm
return if orm == 'active_record'
def app_orm
File.replace_content_from application_file, :where => "require 'rails/all'" do
%q{
require "action_controller/railtie"
Expand All @@ -61,8 +62,8 @@ def app_routes
# if no :welcome controller
if !(routes =~ /root\s+:/)
# create one with an 'index' view.
File.insert_into routes_file, :after => 'do', :content => 'root :to => "welcome#index"'
rgen "controller Welcome index"
File.insert_into routes_file, :after => 'do', :content => 'root :to => "welcome#index"'
end
end

Expand Down
4 changes: 2 additions & 2 deletions lib/generators/cream/full_config/full_config_generator.rb
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ def main

def execute_generator
cream_initializer
# cream_locale
run_generators
run_migrations if run_migrations?
end
Expand Down Expand Up @@ -109,8 +110,7 @@ def cream_initializer

def cream_locale
src = File.expand_path "config/locales/cream.en.yml".path.up(2)
# src = "config/locales/en.yml"
logger.debug "configure_locale, copy from: #{src}"
logger.debug "Generate Cream locale file"
copy_file src, "config/locales/cream.en.yml"
end

Expand Down
80 changes: 79 additions & 1 deletion wiki/Cream-generators-overview.textile
Original file line number Diff line number Diff line change
@@ -1 +1,79 @@
Perhaps the most powerful part of Cream is the set of generators that work to configure your application for your requirements.
Perhaps the most powerful part of Cream is the set of generators that work to configure your application for your requirements.

h2. Full application configuration

The _full_config_ generator is the main generator and attempts to configure an application with Devise, CanCan, Roles and Permits for a given ORM.

As of 2011, it now also supports options to set which class names to use for the main model classes generated, including the abstract User, Role and for relational databases
the model for the join table between User and Role (default: UserRole).

The generator will only run if you pass it a valid strategy and orm combination.

1. Create Cream initializer - which sets up the roles available to Cream (for use in Roles configuration)
2. Optionally generate default locale files for Cream labels (please provide other translations)
3. Run sub generators
4. Optionally run migrations (currently only for Active Record)

h3. Sub generators

The _full_config_ generator executes the following generators in succession:

1. Cream application configuration
2. Devise configuration
3. CanCan configuration
4. Roles configuration
5. Permits configuration

The order is very important!

Note: the Devise configuration is split into 'general configuration' followed by a special _devise users__ generator which sets up User models with devise strategies.

h2. Cream application configuration

1. Remove AR code from application if non-AR ORM is used
2. Add Welcome controller and view and setup root route if no such exists
3. Add flash message logic to application layout file (as required by devise)

In case an ORM is specified other than Active Record (A.R) the generator will attempt to strip A.R code from the application by replacing A.R specific code from the _application.rb_ file.
For the application to demonstrate that it works in the end, it is ensured that root route is defined and linked to a Welcome controller action with page.
This Welcome controller will be set up with a :before filter to redirect to the login page if the user is not logged in.

h2. Devise configuration

Consists of:

* Devise basic configuration
* Devise User configuration

h3. Devise basic configuration

1. Run _Devise installer_ (if it hasn't been run before - i.e no _devise.rb_ initializer present)
2. Configure Devise for ORM chosen (installing relevant ORM adapter for Devise)
3. Insert default mailer configuration in _application.rb_ (localhost:3000) - change this for production!
4. Insert a before filter in the Application controller to always require authenticated user (customize this later)

As part of this configuration, relevant gem files will be added to the _Gemfile_ and <pre>$ bundle install</pre> will be run to install them and make them available to the app :)

h3. Devise users configuration

1. Create devise base User model (note: name of model can be customized) if the user model doesn't already exist
2. Optionally insert default devise strategy in the User model (if not exist)
3. Optionally create an Admin user. The Admin user will always inherit from the base User (using Single Table Inheritance strategy if using Active Record)
4. Create similar models for each role as for Admin user
5. Create special devise routes for each User role with code and notes to aid in further customization if needed

With regard to item 3 (creating Admin model), I'm not sure if it makes sense to treat the Admin user as something special or just let it be like any other role?
Suggestions and comments welcome!

h2. Roles configuration

1. Rune the _Roles generator_ for the ORM selected
2. Replace the valid_roles_are statement in the base User class as generated by the Roles generator with a reference to the roles available defined in Cream initializer (see Cream app generator)

h2. Permits configuration

1. Run _CanCan permits_ generator to generate permits for each role for the ORM selected
2. Generate default licenses



0 comments on commit 5a56318

Please sign in to comment.