admini 0.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: f106a63ce982fb23ce0995f971014c505943003d
4
+ data.tar.gz: 9be87bd739f34f6e6eda1e80914704ba3539a327
5
+ SHA512:
6
+ metadata.gz: 781731b8eb9442abf59b0d1f807924f6b2ba02550b202c34b184f150bf5136139775ce20c867ab0e5b962074025b06e4ebe4097be65b0eedb0103a92d9877bbd
7
+ data.tar.gz: 03ac9f74110c832abcf6aed47934a8e29a1c70aa7b67c272dd820d7e32f3497b69aabffa0879111c6a1f36f435fe94a33f81e14de216e813b787ef88dc9c1458
data/.gitignore ADDED
@@ -0,0 +1,4 @@
1
+ .bundle
2
+ log
3
+ pkg
4
+ Gemfile.lock
data/Gemfile ADDED
@@ -0,0 +1,3 @@
1
+ source 'https://rubygems.org'
2
+
3
+ gemspec
data/MIT-LICENSE ADDED
@@ -0,0 +1,20 @@
1
+ Copyright 2016 kami
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining
4
+ a copy of this software and associated documentation files (the
5
+ "Software"), to deal in the Software without restriction, including
6
+ without limitation the rights to use, copy, modify, merge, publish,
7
+ distribute, sublicense, and/or sell copies of the Software, and to
8
+ permit persons to whom the Software is furnished to do so, subject to
9
+ the following conditions:
10
+
11
+ The above copyright notice and this permission notice shall be
12
+ included in all copies or substantial portions of the Software.
13
+
14
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
18
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
19
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,28 @@
1
+ # Admini
2
+ Short description and motivation.
3
+
4
+ ## Usage
5
+ How to use my plugin.
6
+
7
+ ## Installation
8
+ Add this line to your application's Gemfile:
9
+
10
+ ```ruby
11
+ gem 'admini'
12
+ ```
13
+
14
+ And then execute:
15
+ ```bash
16
+ $ bundle
17
+ ```
18
+
19
+ Or install it yourself as:
20
+ ```bash
21
+ $ gem install admini
22
+ ```
23
+
24
+ ## Contributing
25
+ Contribution directions go here.
26
+
27
+ ## License
28
+ The gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).
data/Rakefile ADDED
@@ -0,0 +1,3 @@
1
+ require 'bundler'
2
+
3
+ Bundler::GemHelper.install_tasks
data/admini.gemspec ADDED
@@ -0,0 +1,22 @@
1
+ $:.push File.expand_path('../lib', __FILE__)
2
+
3
+ require 'admini/version'
4
+
5
+ Gem::Specification.new do |s|
6
+ s.name = 'admini'
7
+ s.version = Admini::VERSION
8
+ s.authors = 'kami'
9
+ s.email = 'hiroki.zenigami@gmail.com'
10
+ s.homepage = 'https://github.com/kami-zh/admini'
11
+ s.summary = 'A minimal administration framework for Ruby on Rails application.'
12
+ s.description = 'A minimal administration framework for Ruby on Rails application.'
13
+ s.license = 'MIT'
14
+
15
+ s.files = `git ls-files -z`.split("\x0")
16
+
17
+ s.add_dependency 'actionpack'
18
+ s.add_dependency 'activesupport'
19
+ s.add_dependency 'jquery-rails'
20
+ s.add_dependency 'simple_form'
21
+ s.add_dependency 'kaminari'
22
+ end
@@ -0,0 +1,2 @@
1
+ //= require jquery
2
+ //= require jquery_ujs
@@ -0,0 +1,81 @@
1
+ html {
2
+ font-size: 14px;
3
+ line-height: 1.5;
4
+ }
5
+
6
+ body {
7
+ margin: 0;
8
+ color: #333;
9
+ }
10
+
11
+ a {
12
+ color: #00c;
13
+ }
14
+
15
+ .container {
16
+ padding-right: 20px;
17
+ padding-left: 20px;
18
+ }
19
+
20
+ .right {
21
+ float: right;
22
+ }
23
+
24
+ .header {
25
+ margin-bottom: 20px;
26
+ padding-top: 20px;
27
+ padding-bottom: 20px;
28
+ border-bottom: 1px solid #eee;
29
+ }
30
+
31
+ .header-title {
32
+ color: #333;
33
+ text-decoration: none;
34
+ }
35
+
36
+ .nav {
37
+ margin-bottom: 8px;
38
+ }
39
+
40
+ table {
41
+ margin-bottom: 12px;
42
+ border-collapse: collapse;
43
+ font-size: .9rem;
44
+ text-align: left;
45
+ }
46
+
47
+ th,
48
+ td {
49
+ padding: 8px 12px;
50
+ border-bottom: 1px solid #eee;
51
+ }
52
+
53
+ th {
54
+ white-space: nowrap;
55
+ }
56
+
57
+ .input {
58
+ margin-bottom: 8px;
59
+ }
60
+
61
+ label {
62
+ display: block;
63
+ margin-bottom: 2px;
64
+ font-size: .9rem;
65
+ font-weight: bold;
66
+ }
67
+
68
+ input[type=text],
69
+ input[type=email],
70
+ input[type=password],
71
+ input[type=url],
72
+ textarea {
73
+ padding: 8px;
74
+ width: 50%;
75
+ min-width: 480px;
76
+ border: 1px solid #eee;
77
+ }
78
+
79
+ textarea {
80
+ height: 160px;
81
+ }
@@ -0,0 +1,199 @@
1
+ module Admini
2
+ class AuthorizationError < StandardError; end
3
+
4
+ module Resources
5
+ extend ActiveSupport::Concern
6
+
7
+ included do
8
+ before_action :load_resources, only: :index
9
+ before_action :load_resource, only: [:edit, :update, :show, :destroy]
10
+ before_action :build_resource, only: [:new, :create]
11
+ before_action :authorize
12
+
13
+ helper_method :resource_name,
14
+ :index_attributes,
15
+ :new_attributes,
16
+ :edit_attributes,
17
+ :show_attributes,
18
+ :enum_attributes,
19
+ :can_create?,
20
+ :can_read?,
21
+ :can_update?,
22
+ :can_delete?,
23
+ :enable_action?,
24
+ :render_attribute,
25
+ :resource_object
26
+
27
+ layout 'admini/layouts/application'
28
+ end
29
+
30
+ def index
31
+ end
32
+
33
+ def new
34
+ end
35
+
36
+ def create
37
+ if @resource.save
38
+ redirect_to action: :show, id: @resource.id
39
+ else
40
+ render :new
41
+ end
42
+ end
43
+
44
+ def show
45
+ end
46
+
47
+ def edit
48
+ end
49
+
50
+ def update
51
+ if @resource.update(resource_params)
52
+ redirect_to action: :show, id: @resource.id
53
+ else
54
+ render :edit
55
+ end
56
+ end
57
+
58
+ def destroy
59
+ @resource.destroy
60
+ redirect_to action: :index
61
+ end
62
+
63
+ private
64
+
65
+ def resource_class
66
+ @resource_class ||= controller_name.classify.constantize
67
+ end
68
+
69
+ def resource_name
70
+ @resource_name ||= resource_class.to_s.downcase
71
+ end
72
+
73
+ def resources
74
+ @resources ||= resource_class.order(id: :desc)
75
+ .page(params[:page])
76
+ .per(paginates_per)
77
+ end
78
+ alias_method :load_resources, :resources
79
+
80
+ def resource
81
+ @resource ||= resource_class.find(params[:id])
82
+ end
83
+ alias_method :load_resource, :resource
84
+
85
+ def build_resource
86
+ @resource = case action_name
87
+ when 'new'
88
+ resource_class.new
89
+ when 'create'
90
+ resource_class.new(resource_params)
91
+ end
92
+ end
93
+
94
+ def resource_params
95
+ attributes = case action_name
96
+ when 'create'
97
+ new_attributes
98
+ when 'update'
99
+ edit_attributes
100
+ end
101
+ params.require(resource_name).permit(attributes)
102
+ end
103
+
104
+ def index_attributes
105
+ %i(id created_at updated_at)
106
+ end
107
+
108
+ def show_attributes
109
+ index_attributes
110
+ end
111
+
112
+ def new_attributes
113
+ %i()
114
+ end
115
+
116
+ def edit_attributes
117
+ new_attributes
118
+ end
119
+
120
+ def enum_attributes
121
+ %i()
122
+ end
123
+
124
+ def authorize
125
+ unless send("can_#{crud_type}?")
126
+ authorization_error
127
+ end
128
+ end
129
+
130
+ def crud_type
131
+ case action_name
132
+ when 'new', 'create'
133
+ :create
134
+ when 'index', 'show'
135
+ :read
136
+ when 'edit', 'update'
137
+ :update
138
+ when 'destroy'
139
+ :delete
140
+ end
141
+ end
142
+
143
+ def can_create?
144
+ true
145
+ end
146
+
147
+ def can_read?
148
+ true
149
+ end
150
+
151
+ def can_update?
152
+ true
153
+ end
154
+
155
+ def can_delete?
156
+ true
157
+ end
158
+
159
+ def authorization_error
160
+ if defined?(super)
161
+ super
162
+ else
163
+ raise Admini::AuthorizationError
164
+ end
165
+ end
166
+
167
+ def enable_action?(action)
168
+ routes.include?(controller: controller_path, action: action.to_s)
169
+ end
170
+
171
+ def routes
172
+ @routes ||= Rails.application
173
+ .routes
174
+ .routes
175
+ .map(&:defaults)
176
+ .reject(&:blank?)
177
+ end
178
+
179
+ def resource_object
180
+ defined?(super) ? super : [:admin, @resource]
181
+ end
182
+
183
+ def render_attribute(resource, attribute)
184
+ if self.class.private_method_defined?("render_#{attribute}")
185
+ send("render_#{attribute}", resource)
186
+ else
187
+ resource.send(attribute)
188
+ end
189
+ end
190
+
191
+ def paginates_per
192
+ defined?(super) ? super : 25
193
+ end
194
+
195
+ def _prefixes
196
+ super << 'admini/resources'
197
+ end
198
+ end
199
+ end
@@ -0,0 +1,9 @@
1
+ <div class="header">
2
+ <div class="container">
3
+ <%= link_to t('admini.header.title'), '#', class: 'header-title' %>
4
+ <%= link_to t('admini.header.menu'), '#' %>
5
+ <div class="right">
6
+ <%= link_to t('admini.header.logout'), '#' %>
7
+ </div>
8
+ </div>
9
+ </div>
@@ -0,0 +1,11 @@
1
+ <div class="nav">
2
+ <div class="container">
3
+ <%= render 'admini/shared/links/index' %>
4
+ <%= render 'admini/shared/links/new' %>
5
+ <% if action_name.in?(%w(show edit update)) %>
6
+ <%= render partial: 'admini/shared/links/show', locals: { resource: @resource } %>
7
+ <%= render partial: 'admini/shared/links/edit', locals: { resource: @resource } %>
8
+ <%= render partial: 'admini/shared/links/delete', locals: { resource: @resource } %>
9
+ <% end %>
10
+ </div>
11
+ </div>
@@ -0,0 +1,14 @@
1
+ <!DOCTYPE html>
2
+ <html>
3
+ <head>
4
+ <title>Admini</title>
5
+ <%= stylesheet_link_tag 'admini/application' %>
6
+ <%= javascript_include_tag 'admini/application' %>
7
+ <%= csrf_meta_tags %>
8
+ </head>
9
+ <body>
10
+ <%= render 'admini/layouts/header' %>
11
+ <%= render 'admini/layouts/nav' %>
12
+ <%= yield %>
13
+ </body>
14
+ </html>
@@ -0,0 +1,13 @@
1
+ <div class="container">
2
+ <%= simple_form_for resource_object do |f| %>
3
+ <% send("#{action_name}_attributes").each do |attribute| %>
4
+ <% case %>
5
+ <% when attribute.in?(enum_attributes) %>
6
+ <%= f.input attribute, collection: @resource.class.send(attribute.to_s.pluralize).keys %>
7
+ <% else %>
8
+ <%= f.input attribute %>
9
+ <% end %>
10
+ <% end %>
11
+ <%= f.submit %>
12
+ <% end %>
13
+ </div>
@@ -0,0 +1 @@
1
+ <%= render 'form' %>
@@ -0,0 +1,23 @@
1
+ <div class="container">
2
+ <table>
3
+ <tr>
4
+ <% index_attributes.each do |attribute| %>
5
+ <th><%= t("activerecord.attributes.#{resource_name}.#{attribute}") %></th>
6
+ <% end %>
7
+ <th></th>
8
+ </tr>
9
+ <% @resources.each do |resource| %>
10
+ <tr>
11
+ <% index_attributes.each do |attribute| %>
12
+ <td><%= render_attribute(resource, attribute) %></td>
13
+ <% end %>
14
+ <td>
15
+ <%= render partial: 'admini/shared/links/show', locals: { resource: resource } %>
16
+ <%= render partial: 'admini/shared/links/edit', locals: { resource: resource } %>
17
+ <%= render partial: 'admini/shared/links/delete', locals: { resource: resource } %>
18
+ </td>
19
+ </tr>
20
+ <% end %>
21
+ </table>
22
+ <%= paginate(@resources) %>
23
+ </div>
@@ -0,0 +1 @@
1
+ <%= render 'form' %>
@@ -0,0 +1,10 @@
1
+ <div class="container">
2
+ <table>
3
+ <% show_attributes.each do |attribute| %>
4
+ <tr>
5
+ <th><%= t("activerecord.attributes.#{resource_name}.#{attribute}") %></th>
6
+ <td><%= render_attribute(@resource, attribute) %></td>
7
+ </tr>
8
+ <% end %>
9
+ </table>
10
+ </div>
@@ -0,0 +1 @@
1
+ <% if enable_action?(:destroy) && can_delete? %><%= link_to t('admini.link.delete'), { action: :destroy, id: resource.id }, method: :delete, data: { confirm: t('admini.confirm') } %><% end %>
@@ -0,0 +1 @@
1
+ <% if enable_action?(:update) && can_update? %><%= link_to t('admini.link.edit'), { action: :edit, id: resource.id } %><% end %>
@@ -0,0 +1 @@
1
+ <% if enable_action?(:index) && can_read? %><%= link_to t('admini.link.index'), action: :index %><% end %>
@@ -0,0 +1 @@
1
+ <% if enable_action?(:new) && can_create? %><%= link_to t('admini.link.new'), action: :new %><% end %>
@@ -0,0 +1 @@
1
+ <% if enable_action?(:show) %><%= link_to t('admini.link.show'), { action: :show, id: resource.id } %><% end %>
@@ -0,0 +1,13 @@
1
+ en:
2
+ admini:
3
+ header:
4
+ title: Admin
5
+ menu: Menu
6
+ logout: Logout
7
+ link:
8
+ index: Index
9
+ new: New
10
+ edit: Edit
11
+ show: Show
12
+ delete: Delete
13
+ confirm: Are you sure?
@@ -0,0 +1,13 @@
1
+ ja:
2
+ admini:
3
+ header:
4
+ title: 管理画面
5
+ menu: メニュー
6
+ logout: ログアウト
7
+ link:
8
+ index: 一覧
9
+ new: 作成
10
+ edit: 編集
11
+ show: 表示
12
+ delete: 削除
13
+ confirm: 本当によろしいですか?
data/lib/admini.rb ADDED
@@ -0,0 +1,3 @@
1
+ require 'kaminari'
2
+ require 'simple_form'
3
+ require 'admini/engine'
@@ -0,0 +1,4 @@
1
+ module Admini
2
+ class Engine < ::Rails::Engine
3
+ end
4
+ end
@@ -0,0 +1,3 @@
1
+ module Admini
2
+ VERSION = '0.1.0'
3
+ end
metadata ADDED
@@ -0,0 +1,140 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: admini
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - kami
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2016-09-29 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: actionpack
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ">="
18
+ - !ruby/object:Gem::Version
19
+ version: '0'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ">="
25
+ - !ruby/object:Gem::Version
26
+ version: '0'
27
+ - !ruby/object:Gem::Dependency
28
+ name: activesupport
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ">="
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ">="
39
+ - !ruby/object:Gem::Version
40
+ version: '0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: jquery-rails
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - ">="
46
+ - !ruby/object:Gem::Version
47
+ version: '0'
48
+ type: :runtime
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - ">="
53
+ - !ruby/object:Gem::Version
54
+ version: '0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: simple_form
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - ">="
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ type: :runtime
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - ">="
67
+ - !ruby/object:Gem::Version
68
+ version: '0'
69
+ - !ruby/object:Gem::Dependency
70
+ name: kaminari
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - ">="
74
+ - !ruby/object:Gem::Version
75
+ version: '0'
76
+ type: :runtime
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - ">="
81
+ - !ruby/object:Gem::Version
82
+ version: '0'
83
+ description: A minimal administration framework for Ruby on Rails application.
84
+ email: hiroki.zenigami@gmail.com
85
+ executables: []
86
+ extensions: []
87
+ extra_rdoc_files: []
88
+ files:
89
+ - ".gitignore"
90
+ - Gemfile
91
+ - MIT-LICENSE
92
+ - README.md
93
+ - Rakefile
94
+ - admini.gemspec
95
+ - app/assets/javascripts/admini/application.js
96
+ - app/assets/stylesheets/admini/default.css
97
+ - app/controllers/concerns/admini/resources.rb
98
+ - app/views/admini/layouts/_header.html.erb
99
+ - app/views/admini/layouts/_nav.html.erb
100
+ - app/views/admini/layouts/application.html.erb
101
+ - app/views/admini/resources/_form.html.erb
102
+ - app/views/admini/resources/edit.html.erb
103
+ - app/views/admini/resources/index.html.erb
104
+ - app/views/admini/resources/new.html.erb
105
+ - app/views/admini/resources/show.html.erb
106
+ - app/views/admini/shared/links/_delete.html.erb
107
+ - app/views/admini/shared/links/_edit.html.erb
108
+ - app/views/admini/shared/links/_index.html.erb
109
+ - app/views/admini/shared/links/_new.html.erb
110
+ - app/views/admini/shared/links/_show.html.erb
111
+ - config/locales/admini.en.yml
112
+ - config/locales/admini.ja.yml
113
+ - lib/admini.rb
114
+ - lib/admini/engine.rb
115
+ - lib/admini/version.rb
116
+ homepage: https://github.com/kami-zh/admini
117
+ licenses:
118
+ - MIT
119
+ metadata: {}
120
+ post_install_message:
121
+ rdoc_options: []
122
+ require_paths:
123
+ - lib
124
+ required_ruby_version: !ruby/object:Gem::Requirement
125
+ requirements:
126
+ - - ">="
127
+ - !ruby/object:Gem::Version
128
+ version: '0'
129
+ required_rubygems_version: !ruby/object:Gem::Requirement
130
+ requirements:
131
+ - - ">="
132
+ - !ruby/object:Gem::Version
133
+ version: '0'
134
+ requirements: []
135
+ rubyforge_project:
136
+ rubygems_version: 2.5.1
137
+ signing_key:
138
+ specification_version: 4
139
+ summary: A minimal administration framework for Ruby on Rails application.
140
+ test_files: []