admini 0.1.1 → 0.1.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +330 -7
- data/app/assets/stylesheets/admini/default.css +4 -0
- data/app/views/admini/layouts/_header.html.erb +3 -3
- data/app/views/admini/shared/links/_delete.html.erb +1 -1
- data/app/views/admini/shared/links/_edit.html.erb +1 -1
- data/app/views/admini/shared/links/_index.html.erb +1 -1
- data/app/views/admini/shared/links/_new.html.erb +1 -1
- data/app/views/admini/shared/links/_show.html.erb +1 -1
- data/config/locales/admini.en.yml +6 -7
- data/config/locales/admini.ja.yml +6 -7
- data/lib/admini/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: b1ca246591999312d4fb645e07db0908545a3d0d
|
4
|
+
data.tar.gz: fea1ddd7562e51df56f487d21b5773df2bfca5e7
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 6a0353dcbf993d93d98caac46c09d17313d1008093fe01a25a5416c548e0c4bc12b5d9d32a5ee2fa591a3956971307339780ff5bd044a61d1a4d1d602ebb0696
|
7
|
+
data.tar.gz: e06b9a436f94a80b041adeabbfaa1cd873f96aca71988111b9623224731b5f17c3634c567342188ad3294d3c41c9b6a3f6c95aa98ada4ae60f960db21b157704
|
data/README.md
CHANGED
@@ -1,10 +1,48 @@
|
|
1
1
|
# Admini
|
2
|
-
Short description and motivation.
|
3
2
|
|
4
|
-
|
5
|
-
|
3
|
+
[![Gem Version](https://badge.fury.io/rb/admini.svg)](https://badge.fury.io/rb/admini)
|
4
|
+
|
5
|
+
Admini is a minimal administration framework for Ruby on Rails application.
|
6
|
+
|
7
|
+
The core feature is just provides CRUD actions as Active Support's Concern module.
|
8
|
+
So you can implement administration page as usual.
|
9
|
+
|
10
|
+
Admini solves the same problem as [ActiveAdmin](https://github.com/activeadmin/activeadmin), [RailsAdmin](https://github.com/sferik/rails_admin) and [Administrate](https://github.com/thoughtbot/administrate).
|
11
|
+
Admini is the simplest framework, so you can create administration page according to the Rails way.
|
12
|
+
|
13
|
+
**Note**: Admini is still under development, and there may be breaking changes to the API.
|
14
|
+
|
15
|
+
## Table of contents
|
16
|
+
|
17
|
+
- [Demo](#demo)
|
18
|
+
- [Installation](#installation)
|
19
|
+
- [Basic usage](#basic-usage)
|
20
|
+
- [Customization](#customization)
|
21
|
+
- [Customize attributes](#customize-attributes)
|
22
|
+
- [Customize rendering text](#customize-rendering-text)
|
23
|
+
- [Search items](#search-items)
|
24
|
+
- [Enum as select tag](#enum-as-select-tag)
|
25
|
+
- [Override CRUD actions](#override-crud-actions)
|
26
|
+
- [Authorize user](#authorize-user)
|
27
|
+
- [Use default theme](#use-default-theme)
|
28
|
+
- [Edit header menu](#edit-header-menu)
|
29
|
+
- [Override specify view](#override-specify-view)
|
30
|
+
- [Change namespace of form object](#change-namespace-of-form-object)
|
31
|
+
- [Change paginates per](#change-paginates-per)
|
32
|
+
- [ToDo](#todo)
|
33
|
+
- [Need help?](#need-help?)
|
34
|
+
- [Contributing](#contributing)
|
35
|
+
- [License](#license)
|
36
|
+
|
37
|
+
## Demo
|
38
|
+
|
39
|
+
You can try an administration page built with Admini at following link.
|
40
|
+
The code of the demo can be found [here]().
|
41
|
+
|
42
|
+
- http://example.com
|
6
43
|
|
7
44
|
## Installation
|
45
|
+
|
8
46
|
Add this line to your application's Gemfile:
|
9
47
|
|
10
48
|
```ruby
|
@@ -12,17 +50,302 @@ gem 'admini'
|
|
12
50
|
```
|
13
51
|
|
14
52
|
And then execute:
|
53
|
+
|
15
54
|
```bash
|
16
55
|
$ bundle
|
17
56
|
```
|
18
57
|
|
19
|
-
|
20
|
-
|
21
|
-
|
58
|
+
## Basic usage
|
59
|
+
|
60
|
+
If the namespace of your administration page is `:admin`, you probably create `Admin::ApplicationController` like this:
|
61
|
+
|
62
|
+
```ruby
|
63
|
+
class Admin::ApplicationController < ActionController::Base
|
64
|
+
protect_from_forgery with: :exception
|
65
|
+
|
66
|
+
# If you use Devise:
|
67
|
+
# before_action :authenticate_user!
|
68
|
+
end
|
69
|
+
```
|
70
|
+
|
71
|
+
There's no code related to Admini.
|
72
|
+
You can implement as you like, such as an authentication.
|
73
|
+
|
74
|
+
Now everything is ready to create administration page.
|
75
|
+
For example, to create the page manages Post model, you have to do the following steps:
|
76
|
+
|
77
|
+
1. Create `Admin::PostsController` and include `Admini::Resources`
|
78
|
+
2. Add routing
|
79
|
+
|
80
|
+
The example codes is below:
|
81
|
+
|
82
|
+
```ruby
|
83
|
+
class Admin::PostsController < Admin::ApplicationController
|
84
|
+
include Admini::Resources
|
85
|
+
end
|
86
|
+
```
|
87
|
+
|
88
|
+
```ruby
|
89
|
+
namespace :admin do
|
90
|
+
resources :posts
|
91
|
+
end
|
92
|
+
```
|
93
|
+
|
94
|
+
That's it, and now you can take action `index`, `new`, `create`, `show`, `edit`, `update`, `destroy` the posts at `/admin/posts`.
|
95
|
+
|
96
|
+
## Customization
|
97
|
+
|
98
|
+
### Customize attributes
|
99
|
+
|
100
|
+
The items rendering on `index`, `new`, `show` and `edit` can customize using `#xxx_attributes`.
|
101
|
+
If you define following methods to controller, the items have changed:
|
102
|
+
|
103
|
+
- `#index_attributes`
|
104
|
+
- `#show_attributes` (default: `#index_attributes`)
|
105
|
+
- `#new_attributes`
|
106
|
+
- `#edit_attributes` (default: `#new_attributes`)
|
107
|
+
|
108
|
+
Examples:
|
109
|
+
|
110
|
+
```ruby
|
111
|
+
class Admin::PostsController < Admin::ApplicationController
|
112
|
+
include Admini::Resources
|
113
|
+
|
114
|
+
private
|
115
|
+
|
116
|
+
def index_attributes
|
117
|
+
%i(id title status created_at)
|
118
|
+
end
|
119
|
+
|
120
|
+
def show_attributes
|
121
|
+
%i(id title status created_at content)
|
122
|
+
end
|
123
|
+
|
124
|
+
def new_attributes
|
125
|
+
%i(title status content)
|
126
|
+
end
|
127
|
+
end
|
128
|
+
```
|
129
|
+
|
130
|
+
### Customize rendering text
|
131
|
+
|
132
|
+
The items rendering text on `index` and `show` are also customizable as you like.
|
133
|
+
If you define `#render_xxx` on your controller, Admini renders text according to the method.
|
134
|
+
|
135
|
+
Here is an example that renders a title with link to post instead of just title.
|
136
|
+
|
137
|
+
```ruby
|
138
|
+
class Admin::PostsController < Admin::ApplicationController
|
139
|
+
include Admini::Resources
|
140
|
+
include ActionView::Helpers::UrlHelper
|
141
|
+
|
142
|
+
private
|
143
|
+
|
144
|
+
def render_title(resource)
|
145
|
+
path = case resource.status
|
146
|
+
when 'draft'
|
147
|
+
preview_post_path(resource, token: resource.preview_token)
|
148
|
+
else
|
149
|
+
post_path(resource)
|
150
|
+
end
|
151
|
+
link_to resource.title, path
|
152
|
+
end
|
153
|
+
end
|
154
|
+
```
|
155
|
+
|
156
|
+
In the same way, a method name to customize the `content` is `#render_content`, or `created_at` is `#render_created_at`.
|
157
|
+
|
158
|
+
### Search items
|
159
|
+
|
160
|
+
If you want to enable the search form, you should just define `#search_attributes` on your controller.
|
161
|
+
|
162
|
+
Following examples enable the search form searched by `title` and `content`.
|
163
|
+
|
164
|
+
```ruby
|
165
|
+
class Admin::PostsController < Admin::ApplicationController
|
166
|
+
include Admini::Resources
|
167
|
+
|
168
|
+
private
|
169
|
+
|
170
|
+
def search_attributes
|
171
|
+
%i(title content)
|
172
|
+
end
|
173
|
+
end
|
174
|
+
```
|
175
|
+
|
176
|
+
### Enum as select tag
|
177
|
+
|
178
|
+
Enum is treated as Integer by database, so enum form has created as text field by default.
|
179
|
+
If you want to show the form as select box, you should define `#enum_attributes`.
|
180
|
+
|
181
|
+
```ruby
|
182
|
+
class Admin::PostsController < Admin::ApplicationController
|
183
|
+
include Admini::Resources
|
184
|
+
|
185
|
+
private
|
186
|
+
|
187
|
+
def enum_attributes
|
188
|
+
%i(status)
|
189
|
+
end
|
190
|
+
end
|
191
|
+
```
|
192
|
+
|
193
|
+
### Override CRUD actions
|
194
|
+
|
195
|
+
Often we want to override CRUD actions, especially `create` and `update`.
|
196
|
+
|
197
|
+
To do this, just define `#create` or `#update` on your controller.
|
198
|
+
If you want to delegate to `super` defined by Admini, you should call `#super` on the action.
|
199
|
+
|
200
|
+
```ruby
|
201
|
+
class Admin::PostsController < Admin::ApplicationController
|
202
|
+
include Admini::Resources
|
203
|
+
|
204
|
+
def create
|
205
|
+
@resource.user = current_user
|
206
|
+
super
|
207
|
+
end
|
208
|
+
end
|
22
209
|
```
|
23
210
|
|
211
|
+
### Authorize user
|
212
|
+
|
213
|
+
You can simply authorize user using [CanCanCan](https://github.com/CanCanCommunity/cancancan), [Pundit](https://github.com/elabs/pundit) or your own code.
|
214
|
+
|
215
|
+
When you define the following methods on your controller, Admini authorizes user with it, and raise `Admini::AuthorizationError` if user has not authorized.
|
216
|
+
|
217
|
+
- `#can_create?`
|
218
|
+
- `#can_read?`
|
219
|
+
- `#can_update?`
|
220
|
+
- `#can_delete?`
|
221
|
+
|
222
|
+
Examples using CanCanCan:
|
223
|
+
|
224
|
+
```ruby
|
225
|
+
class Admin::PostsController < Admin::ApplicationController
|
226
|
+
include Admini::Resources
|
227
|
+
|
228
|
+
private
|
229
|
+
|
230
|
+
def can_create?
|
231
|
+
can? :create, Post
|
232
|
+
end
|
233
|
+
end
|
234
|
+
```
|
235
|
+
|
236
|
+
Also you can define custom error handler.
|
237
|
+
This is realized by to define `#authorization_error` on your `Admin::ApplicationController`.
|
238
|
+
|
239
|
+
```ruby
|
240
|
+
class Admin::ApplicationController < ActionController::Base
|
241
|
+
private
|
242
|
+
|
243
|
+
def authorization_error
|
244
|
+
puts 'Authorization error'
|
245
|
+
end
|
246
|
+
end
|
247
|
+
```
|
248
|
+
|
249
|
+
### Use default theme
|
250
|
+
|
251
|
+
Admini doesn't apply any styles to administration pages by default.
|
252
|
+
Because Admini should be minimal.
|
253
|
+
If you want to apply basic style created by Admini, you should require the stylesheet.
|
254
|
+
|
255
|
+
`app/assets/stylesheets/admini/application.css`:
|
256
|
+
|
257
|
+
```css
|
258
|
+
/*
|
259
|
+
*= require admini/default
|
260
|
+
*/
|
261
|
+
```
|
262
|
+
|
263
|
+
Needless to say, you can write your own styles here as you like.
|
264
|
+
|
265
|
+
### Edit header menu
|
266
|
+
|
267
|
+
Admini is minimal, so the links to pages will **not** added automatically.
|
268
|
+
The default view generated by Admini doesn't have any links [like this](https://github.com/kami-zh/admini/blob/master/app/views/admini/layouts/_header.html.erb).
|
269
|
+
|
270
|
+
However, you can override header menu by editing `app/views/admini/layouts/_header.html.erb`.
|
271
|
+
|
272
|
+
Examples:
|
273
|
+
|
274
|
+
```html
|
275
|
+
<div class="header">
|
276
|
+
<div class="container">
|
277
|
+
<%= link_to 'Admin', admin_root_path, class: 'header-title' %>
|
278
|
+
<%= link_to 'Posts', admin_posts_path %>
|
279
|
+
<%= link_to 'Users', admin_users_path %>
|
280
|
+
<div class="right">
|
281
|
+
<%= link_to 'Logout', destroy_user_session_path, method: :delete %>
|
282
|
+
</div>
|
283
|
+
</div>
|
284
|
+
</div>
|
285
|
+
```
|
286
|
+
|
287
|
+
### Override specify view
|
288
|
+
|
289
|
+
The view has rendered with a [common views](https://github.com/kami-zh/admini/tree/master/app/views/admini).
|
290
|
+
If you want to implement original views, you should place your own views according to Rails convention.
|
291
|
+
|
292
|
+
For example, to customize the view of `admin/posts#show`, you should create `app/views/admin/posts/show.html.erb`.
|
293
|
+
|
294
|
+
```html
|
295
|
+
<h1>admin/posts#show</h1>
|
296
|
+
```
|
297
|
+
|
298
|
+
In the same way, you can override all views, including `application.html.erb`, `_header.html.erb`, `_nav.html.erb`.
|
299
|
+
|
300
|
+
### Change namespace of form object
|
301
|
+
|
302
|
+
Admini sets `[:admin, @resource]` as the namespace of form object by default.
|
303
|
+
This is because generally we adopt `:admin` as administration page's namespace.
|
304
|
+
|
305
|
+
If your administration page has a different namespace like `:editor`, you should define `#resource_object` on your `Editor::ApplicationController`.
|
306
|
+
|
307
|
+
```ruby
|
308
|
+
class Editor::ApplicationController < ActionController::Base
|
309
|
+
private
|
310
|
+
|
311
|
+
def resource_object
|
312
|
+
[:editor, @resource]
|
313
|
+
end
|
314
|
+
end
|
315
|
+
```
|
316
|
+
|
317
|
+
### Change paginates per
|
318
|
+
|
319
|
+
Admini depends on [Kaminari](https://github.com/amatsuda/kaminari) as paginater, and it paginates per `25` items.
|
320
|
+
You can override this number by `#paginates_per` method.
|
321
|
+
|
322
|
+
```ruby
|
323
|
+
class Admin::ApplicationController < ActionController::Base
|
324
|
+
private
|
325
|
+
|
326
|
+
def paginates_per
|
327
|
+
10
|
328
|
+
end
|
329
|
+
end
|
330
|
+
```
|
331
|
+
|
332
|
+
## ToDo
|
333
|
+
|
334
|
+
- [ ] Add spec
|
335
|
+
- [ ] Improve README (Because I'm not good at English :no_good:)
|
336
|
+
|
337
|
+
## Need help?
|
338
|
+
|
339
|
+
Feel free to ask me in [Issues](https://github.com/kami-zh/admini/issues) or [author's twitter](https://twitter.com/kami_zh).
|
340
|
+
|
24
341
|
## Contributing
|
25
|
-
|
342
|
+
|
343
|
+
1. Fork it ( https://github.com/kami-zh/admini/fork )
|
344
|
+
2. Create your feature branch (git checkout -b my-new-feature)
|
345
|
+
3. Commit your changes (git commit -am 'Add some feature')
|
346
|
+
4. Push to the branch (git push origin my-new-feature)
|
347
|
+
5. Create a new Pull Request
|
26
348
|
|
27
349
|
## License
|
350
|
+
|
28
351
|
The gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).
|
@@ -1,9 +1,9 @@
|
|
1
1
|
<div class="header">
|
2
2
|
<div class="container">
|
3
|
-
<%= link_to t('admini.
|
4
|
-
<%= link_to t('admini.
|
3
|
+
<%= link_to t('admini.title'), '#', class: 'header-title' %>
|
4
|
+
<%= link_to t('admini.menu'), '#' %>
|
5
5
|
<div class="right">
|
6
|
-
<%= link_to t('admini.
|
6
|
+
<%= link_to t('admini.logout'), '#' %>
|
7
7
|
</div>
|
8
8
|
</div>
|
9
9
|
</div>
|
@@ -1 +1 @@
|
|
1
|
-
<% if enable_action?(:destroy) && can_delete? %><%= link_to t('admini.
|
1
|
+
<% if enable_action?(:destroy) && can_delete? %><%= link_to t('admini.action.delete'), { action: :destroy, id: resource.id }, method: :delete, data: { confirm: t('admini.confirm') } %><% end %>
|
@@ -1 +1 @@
|
|
1
|
-
<% if enable_action?(:update) && can_update? %><%= link_to t('admini.
|
1
|
+
<% if enable_action?(:update) && can_update? %><%= link_to t('admini.action.edit'), { action: :edit, id: resource.id } %><% end %>
|
@@ -1 +1 @@
|
|
1
|
-
<% if enable_action?(:index) && can_read? %><%= link_to t('admini.
|
1
|
+
<% if enable_action?(:index) && can_read? %><%= link_to t('admini.action.index'), action: :index %><% end %>
|
@@ -1 +1 @@
|
|
1
|
-
<% if enable_action?(:new) && can_create? %><%= link_to t('admini.
|
1
|
+
<% if enable_action?(:new) && can_create? %><%= link_to t('admini.action.new'), action: :new %><% end %>
|
@@ -1 +1 @@
|
|
1
|
-
<% if enable_action?(:show) %><%= link_to t('admini.
|
1
|
+
<% if enable_action?(:show) %><%= link_to t('admini.action.show'), { action: :show, id: resource.id } %><% end %>
|
@@ -1,14 +1,13 @@
|
|
1
1
|
en:
|
2
2
|
admini:
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
3
|
+
confirm: Are you sure?
|
4
|
+
logout: Logout
|
5
|
+
menu: Menu
|
6
|
+
search: Search
|
7
|
+
title: Admin
|
8
|
+
action:
|
8
9
|
index: Index
|
9
10
|
new: New
|
10
11
|
edit: Edit
|
11
12
|
show: Show
|
12
13
|
delete: Delete
|
13
|
-
confirm: Are you sure?
|
14
|
-
search: Search
|
@@ -1,14 +1,13 @@
|
|
1
1
|
ja:
|
2
2
|
admini:
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
3
|
+
confirm: 本当によろしいですか?
|
4
|
+
logout: ログアウト
|
5
|
+
menu: メニュー
|
6
|
+
search: 検索する
|
7
|
+
title: 管理画面
|
8
|
+
action:
|
8
9
|
index: 一覧
|
9
10
|
new: 作成
|
10
11
|
edit: 編集
|
11
12
|
show: 表示
|
12
13
|
delete: 削除
|
13
|
-
confirm: 本当によろしいですか?
|
14
|
-
search: 検索する
|
data/lib/admini/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: admini
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- kami
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2016-
|
11
|
+
date: 2016-10-01 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: actionpack
|