-
Notifications
You must be signed in to change notification settings - Fork 12
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
5 changed files
with
189 additions
and
90 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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` | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |