Skip to content

Commit

Permalink
v0.0.4 now
Browse files Browse the repository at this point in the history
  • Loading branch information
tian-im committed Jan 18, 2016
1 parent 24a6294 commit 6b51f7e
Show file tree
Hide file tree
Showing 5 changed files with 189 additions and 90 deletions.
36 changes: 27 additions & 9 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,18 +1,36 @@
# History:

## v0.0.4

1. Basic search for collection
2. Kaminari pagination for collection.
3. Basic flash message.
4. Authentication. It can be configured.
5. Basic form errors

# WIP Feature list
- Form errors
- Authentication (use device)
- Pagination for collection
- Search for collection

## v0.0.2
1. Moved and refactored core methods from resources controller to core controller.
2. Moved prefix builder to core controller.
2. Created general tempaltes for resources index action.
3. Created a wrapper to speed up view rendering by caching the `find_template` result.
- Abstract all resources controller action
- Page rendering performance improvement
- Sorting for collection (maybe)
- Authorization (use cancan/cancancan)
- Data Audit (use papertrail)

# Knonw issues

- Autoload is not working for finding out all subclasses in development mode
- Form partial is not rendering in development mode
- Missing assets for kaminari and bootstrap-sass if kaminari and bootstrap-sass are not in the `Gemfile`

## v0.0.3

1. Refactored model decorator and use `fields` as base information for all fields
2. Included association fields and exclude those foreign keys for these associations
3. Created general templates for show/form

## v0.0.2

1. Moved and refactored core methods from resources controller to core controller.
2. Moved prefix builder to core controller.
2. Created general tempaltes for resources index action.
3. Created a wrapper to speed up view rendering by caching the `find_template` result.
124 changes: 124 additions & 0 deletions CUSTOMIZATION.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,124 @@
# Customization

This engine allows us to do further development in Rails way from the following sections.

First of all, let, if you have a model call `Product` and it has the following columns:

- sku:string
- name:string
- category_id:integer
- description:text
- stock:integer
- price:float
- featured:boolean
- available_to_date:date
- available_to_time:time
- published_at:datetime

And it has model declaration as below:

```ruby
class Product < ActiveRecord::Base
has_one :product_detail
has_one :picture, as: :imageable
has_many :order_items, class_name: Order::Item.name
has_many :orders, through: :order_items
belongs_to :category
has_and_belongs_to_many :tags

validates_presence_of :name, :sku
end
```

## Configuration

This engine by default uses ActiveRecord adaptor, you could change this to other adaptor (e.g. Mongo / HER adaptor) as below:

```ruby
# config/initializers/wallaby.rb
Wallaby.config do |config|
config.adaptor = Wallaby::SomeOtherAdaptor
end
```

By default, there is no authentication, and you need to do the following config if you need one:

```ruby
# config/initializers/wallaby.rb
Wallaby.config do |config|
config.security.authenticate do
# you could use any controller methods here
authenticate_or_request_with_http_basic do |username, password|
username == 'too_simple' && password == 'too_naive'
end
end

config.security.current_user do
# you could use any controller methods here
Class.new do
def email
'user@example.com'
end
end.new
end
end
```

You could hide some models using configuration as below:

```ruby
# config/initializers/wallaby.rb
Wallaby.config do |config|
config.models.exclude ProductDetail, Order, Order::Item
end
```

## Controller

You could modify the logics for Post model by defining a controller as below:

```ruby
class PostsController < Wallaby::ResourceController
def create
# do something else
super
end
end

# OR any controller name you want, but specifying the `model_class`
class Admin::CustomPostsController < Wallaby::ResourceController
def self.model_class
Post
end

def create
# do something else
super
end
end
```

## Decorator

Similar to the controller above, you could use two ways to define a decorator.
Having a decorator, you could then modify what fields to use for views index/show/form

```ruby
class PostDecorator < ResourceDecorator
index_field_names.delete 'body'
show_fields['body'][:type] = 'markdown'
form_fields['body'][:label] = 'Content'
end
```

## View

You could easily define any field view for any custom type (e.g. markdown) for Post by defining a partial under `app/views/posts/index/_markdown`

```erb
<%# The local variables in the partial are `value` %>
<%= markdown.render value %>
```

If you want to make it available for other models, you could move it to `app/views/resources/index/_markdown`

2 changes: 1 addition & 1 deletion Gemfile.lock
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
PATH
remote: .
specs:
wallaby (0.0.3)
wallaby (0.0.4)
bootstrap-sass
devise
jquery-rails
Expand Down
115 changes: 36 additions & 79 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,18 +4,29 @@

Wallaby is a Rails engine to manage your data. You could have a play with the [demo here](https://wallaby-demo.herokuapp.com/admin/)

## Requirements
Rails 4.0 and above
## What's new

## Support
ActiveRecord
### v0.0.4

1. Basic search for collection
2. Kaminari pagination for collection.
3. Basic flash message.
4. Authentication. It can be configured.
5. Basic form errors

For more, see [Changlog](CHANGELOG.md)

## Yet another Rails admin engine? Why?
Because this engine is built in Rails way! You could customize things like what you normally do developing Rails app. (see the section [Customization](#customization) below).

# Installation
Because this engine is built in Rails way! You could do further development like what you normally do for a Rails app (see [Customization](CUSTOMIZATION.md)).

## Support

Rails 4.*, ActiveRecord, Devise

1. Add to `Gemfile`:
## Installation

1. Add the following lines to `Gemfile`:

```ruby
gem 'bootstrap-sass'
Expand All @@ -24,28 +35,35 @@ Because this engine is built in Rails way! You could customize things like what
gem 'wallaby'
```

2. Add engine to `routes.rb`:
2. Add engine routes to `routes.rb`:

```ruby
mount Wallaby::Engine => "/the_path_you_like"
Rails.application.routes.draw do
mount Wallaby::Engine => "/the_path_you_like"
# ... other routes
end
```

# Customization
Then you are all set to visit wallaby on your local machine at `/the_path_you_like`, unless you need to do the following configuration.

## Configuration

> Assume that you have an active model `Post(id: integer, title: string, body: text, publish_time: datetime, creator_id: integer, updator_id: integer, created_at: datetime, updated_at: datetime)`
### Authentication

1. Configuration
You could set up authentication via:

This engine by default uses ActiveRecord adaptor, you could change this to other adaptor (e.g. Mongo / HER adaptor) as below:
1. Easily tell wallaby which controller to inherit from:

```ruby
# config/initializers/wallaby.rb
Wallaby.config do |config|
config.adaptor = Wallaby::SomeOtherAdaptor
config.base_controller = OurSecurityController
end
```

By default, there is no authentication, and you need to do the following config if you need one:
Once this is set, wallaby will immediately be able to use `authenticate_user!` and `current_user` methods to do authentication (which is compatible with Devise), not to mention all functionalities including helper, before_action and etc (which will be benefitial for further development upon wallaby, see [Customization](CUSTOMIZATION.md)).

2. You could still use custom authentication by configuring the `authenticate` and `current_user` options as below:

```ruby
# config/initializers/wallaby.rb
Expand All @@ -60,6 +78,7 @@ Because this engine is built in Rails way! You could customize things like what
config.security.current_user do
# you could use any controller methods here
Class.new do
# email here is for gravator profile image
def email
'user@example.com'
end
Expand All @@ -68,69 +87,7 @@ Because this engine is built in Rails way! You could customize things like what
end
```

You could hide some models using configuration as below:

```ruby
# config/initializers/wallaby.rb
Wallaby.config do |config|
config.models.exclude ProductDetail, Order, Order::Item
end
```

2. Controller

You could modify the logics for Post model by defining a controller as below:

```ruby
class PostsController < Wallaby::ResourceController
def create
# do something else
super
end
end

# OR any controller name you want, but specifying the `model_class`
class Admin::CustomPostsController < Wallaby::ResourceController
def self.model_class
Post
end

def create
# do something else
super
end
end
```

3. Decorator

Similar to the controller above, you could use two ways to define a decorator.
Having a decorator, you could then modify what fields to use for views index/show/form

```ruby
class PostDecorator < ResourceDecorator
index_field_names.delete 'body'
show_fields['body'][:type] = 'markdown'
form_fields['body'][:label] = 'Content'
end
```

4. View

You could easily define any field view for any custom type (e.g. markdown) for Post by defining a partial under `app/views/posts/index/_markdown`

```erb
<%# The local variables in the partial are `value` %>
<%= markdown.render value %>
```

If you want to make it available for other models, you could move it to `app/views/resources/index/_markdown`

# How to test

```
bundle exec rake spec
```
For more configurations and how to do further development upon wallaby, see [Customization](CUSTOMIZATION.md).

# License
## License
This project rocks and uses MIT-LICENSE.
2 changes: 1 addition & 1 deletion lib/wallaby/version.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
module Wallaby
VERSION = '0.0.3'
VERSION = '0.0.4'
end

0 comments on commit 6b51f7e

Please sign in to comment.