AdminSpace 0.0.1
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.
- data/Gemfile +4 -0
- data/LICENSE.txt +22 -0
- data/README.md +62 -0
- data/Rakefile +1 -0
- data/app/controllers/admin_space/base.rb +83 -0
- data/app/controllers/admin_space/base_controller.rb +4 -0
- data/app/views/admin_space/base/_form.html.erb +9 -0
- data/app/views/admin_space/base/edit.html.erb +1 -0
- data/app/views/admin_space/base/index.html.erb +20 -0
- data/app/views/admin_space/base/new.html.erb +3 -0
- data/app/views/admin_space/base/show.html.erb +0 -0
- data/app/views/layouts/admin_space.html.erb +17 -0
- data/lib/admin_space.rb +12 -0
- data/lib/admin_space/route.rb +23 -0
- data/lib/admin_space/version.rb +3 -0
- metadata +60 -0
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
Copyright (c) 2012 Thomas Lauro
|
2
|
+
|
3
|
+
MIT License
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
6
|
+
a copy of this software and associated documentation files (the
|
7
|
+
"Software"), to deal in the Software without restriction, including
|
8
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
9
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
10
|
+
permit persons to whom the Software is furnished to do so, subject to
|
11
|
+
the following conditions:
|
12
|
+
|
13
|
+
The above copyright notice and this permission notice shall be
|
14
|
+
included in all copies or substantial portions of the Software.
|
15
|
+
|
16
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
17
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
18
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
19
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
20
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
21
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
22
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,62 @@
|
|
1
|
+
# AdminSpace
|
2
|
+
|
3
|
+
AdminSpace handle admin namespace, controllers, views in your application
|
4
|
+
|
5
|
+
## Installation
|
6
|
+
|
7
|
+
Using bundler:
|
8
|
+
In your Gemfile
|
9
|
+
```
|
10
|
+
gem 'admin_space'
|
11
|
+
```
|
12
|
+
|
13
|
+
Or manually :
|
14
|
+
```
|
15
|
+
gem install admin_space
|
16
|
+
```
|
17
|
+
|
18
|
+
## Usage
|
19
|
+
|
20
|
+
In routes.rb
|
21
|
+
```
|
22
|
+
admin_space do
|
23
|
+
root to: 'base#index', type: 'your_first_model'
|
24
|
+
end
|
25
|
+
```
|
26
|
+
|
27
|
+
In your models define attr_accessible:
|
28
|
+
```
|
29
|
+
class User < ActiveRecord::Base
|
30
|
+
attr_accessible :email, :password, :firstname, :lastname
|
31
|
+
end
|
32
|
+
```
|
33
|
+
|
34
|
+
You can now access your admin space.
|
35
|
+
|
36
|
+
AdminSpace handle admin controller, you do not need to generate yours.
|
37
|
+
But if you want fancy controller, you can still define some :
|
38
|
+
```
|
39
|
+
rails g controller admin_space::webblogs
|
40
|
+
```
|
41
|
+
|
42
|
+
In routes.rb
|
43
|
+
```
|
44
|
+
admin_space do
|
45
|
+
root to: 'base#index', type: 'your_first_model'
|
46
|
+
resources :webblogs
|
47
|
+
end
|
48
|
+
```
|
49
|
+
|
50
|
+
## Contributing
|
51
|
+
|
52
|
+
1. Fork it
|
53
|
+
2. Create your feature branch (`git checkout -b my-new-feature`)
|
54
|
+
3. Commit your changes (`git commit -am 'Added some feature'`)
|
55
|
+
4. Push to the branch (`git push origin my-new-feature`)
|
56
|
+
5. Create new Pull Request
|
57
|
+
|
58
|
+
## License
|
59
|
+
|
60
|
+
AdminSpace is released under the MIT license:
|
61
|
+
|
62
|
+
* http://www.opensource.org/licenses/MIT
|
data/Rakefile
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
require "bundler/gem_tasks"
|
@@ -0,0 +1,83 @@
|
|
1
|
+
module AdminSpace
|
2
|
+
class Base < ::ApplicationController
|
3
|
+
def self.managed_by_admin_space(base)
|
4
|
+
before_filter :load_resource, only: [:show, :edit, :update, :destroy]
|
5
|
+
include InstanceMethods
|
6
|
+
|
7
|
+
layout 'admin_space'
|
8
|
+
end
|
9
|
+
|
10
|
+
module InstanceMethods
|
11
|
+
def index
|
12
|
+
@resources = resource_class.all
|
13
|
+
end
|
14
|
+
|
15
|
+
def show
|
16
|
+
end
|
17
|
+
|
18
|
+
def edit
|
19
|
+
end
|
20
|
+
|
21
|
+
def update
|
22
|
+
@resource.update_attributes params[@model]
|
23
|
+
redirect_to [:admin, @resource]
|
24
|
+
end
|
25
|
+
|
26
|
+
def new
|
27
|
+
@resource = resource_class.new
|
28
|
+
end
|
29
|
+
|
30
|
+
def create
|
31
|
+
@resource = resource_class.new params[resource_name]
|
32
|
+
if @resource.save
|
33
|
+
redirect_to [:admin, @resource]
|
34
|
+
else
|
35
|
+
render action: :new
|
36
|
+
end
|
37
|
+
end
|
38
|
+
|
39
|
+
def destroy
|
40
|
+
@resource.destroy
|
41
|
+
redirect_to [:admin, resource_class.to_s]
|
42
|
+
end
|
43
|
+
|
44
|
+
protected
|
45
|
+
|
46
|
+
def resource_name
|
47
|
+
@resource_name ||= resource_name_from_path
|
48
|
+
end
|
49
|
+
|
50
|
+
def resource_name_from_path
|
51
|
+
params.include?(:type) ? params[:type].singularize : request.fullpath.underscore.split('/')[2].singularize
|
52
|
+
end
|
53
|
+
|
54
|
+
def resource_class
|
55
|
+
@resource_class ||= resource_name.to_s.classify.constantize
|
56
|
+
end
|
57
|
+
|
58
|
+
# Resources
|
59
|
+
|
60
|
+
def resource_collection
|
61
|
+
instance_variable_get("@#{resource_name.to_s.pluralize}") || []
|
62
|
+
end
|
63
|
+
|
64
|
+
def resource
|
65
|
+
instance_variable_get "@#{resource_name.to_s}"
|
66
|
+
end
|
67
|
+
|
68
|
+
def check_model
|
69
|
+
@model = params.include?('type') ? params[:type].classify.constantize : controller_name
|
70
|
+
end
|
71
|
+
|
72
|
+
def get_model
|
73
|
+
params[:type]
|
74
|
+
end
|
75
|
+
|
76
|
+
def load_resource
|
77
|
+
@resource = resource_class.find(params[:id])
|
78
|
+
end
|
79
|
+
end
|
80
|
+
|
81
|
+
managed_by_admin_space(self)
|
82
|
+
end
|
83
|
+
end
|
@@ -0,0 +1,9 @@
|
|
1
|
+
<dl style="clear: both; overflow: hidden;">
|
2
|
+
<% (@resource_class.accessible_attributes - [""]).each do |attr| %>
|
3
|
+
<dt style="clear: both; float: left; width: 100px;"><label><%= attr %></label></dt>
|
4
|
+
<dd style="float: left">
|
5
|
+
<%= f.text_field attr %>
|
6
|
+
</dd>
|
7
|
+
<% end %>
|
8
|
+
</dl>
|
9
|
+
<input type="submit" value="Add"/>
|
@@ -0,0 +1 @@
|
|
1
|
+
<%= render partial: :form %>
|
@@ -0,0 +1,20 @@
|
|
1
|
+
<h1><%= @resource_name.camelize %></h1>
|
2
|
+
<table>
|
3
|
+
<thead>
|
4
|
+
<tr>
|
5
|
+
<% (@resource_class.accessible_attributes - [""]).each do |attr| %>
|
6
|
+
<th><%= attr %></th>
|
7
|
+
<% end %>
|
8
|
+
</tr>
|
9
|
+
</thead>
|
10
|
+
<tbody>
|
11
|
+
<% @resources.each do |resource| %>
|
12
|
+
<tr>
|
13
|
+
<% (@resource_class.accessible_attributes - [""]).each do |attr| %>
|
14
|
+
<td><%= link_to resource.send(attr), [:admin, resource] %></td>
|
15
|
+
<% end %>
|
16
|
+
</tr>
|
17
|
+
<% end %>
|
18
|
+
</tbody>
|
19
|
+
</table>
|
20
|
+
<a href="<%= new_admin_user_path %>">New</a>
|
File without changes
|
@@ -0,0 +1,17 @@
|
|
1
|
+
<html>
|
2
|
+
<head>
|
3
|
+
</head>
|
4
|
+
<body>
|
5
|
+
<div id="menu">
|
6
|
+
<ul>
|
7
|
+
<% Dir.glob( 'app/models/*' ).each do |model| %>
|
8
|
+
<% model_name = File.basename(model).gsub( /^(.+).rb/, '\1').pluralize %>
|
9
|
+
<li><%= link_to model_name, [:admin, model_name] %></li>
|
10
|
+
<% end %>
|
11
|
+
</ul>
|
12
|
+
</div>
|
13
|
+
<div class="container">
|
14
|
+
<%= yield %>
|
15
|
+
</div>
|
16
|
+
</body>
|
17
|
+
</html>
|
data/lib/admin_space.rb
ADDED
@@ -0,0 +1,23 @@
|
|
1
|
+
module ActionDispatch::Routing
|
2
|
+
class Mapper
|
3
|
+
def admin_space *args
|
4
|
+
namespace :admin, module: :admin_space do
|
5
|
+
with_options controller: :base do |admin|
|
6
|
+
yield admin
|
7
|
+
end
|
8
|
+
# match ':type/:id', controller: :base, action: :show, constraints: { :id => /\d/ }
|
9
|
+
# match ':type/(:action/(:id(.:format)))', controller: :base
|
10
|
+
|
11
|
+
# List all model and build routes
|
12
|
+
models = []
|
13
|
+
Dir.glob( 'app/models/*' ).each do |f|
|
14
|
+
models << File.basename( f ).gsub( /^(.+).rb/, '\1')
|
15
|
+
end
|
16
|
+
|
17
|
+
models.each do |model|
|
18
|
+
eval("resources :#{model.pluralize}, controller: :base")
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
metadata
ADDED
@@ -0,0 +1,60 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: AdminSpace
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
prerelease:
|
6
|
+
platform: ruby
|
7
|
+
authors:
|
8
|
+
- Thomas Lauro
|
9
|
+
autorequire:
|
10
|
+
bindir: bin
|
11
|
+
cert_chain: []
|
12
|
+
date: 2012-11-19 00:00:00.000000000 Z
|
13
|
+
dependencies: []
|
14
|
+
description: AdminSpace handle admin namespace for you
|
15
|
+
email:
|
16
|
+
- thomas@lauro.fr
|
17
|
+
executables: []
|
18
|
+
extensions: []
|
19
|
+
extra_rdoc_files: []
|
20
|
+
files:
|
21
|
+
- app/controllers/admin_space/base.rb
|
22
|
+
- app/controllers/admin_space/base_controller.rb
|
23
|
+
- app/views/admin_space/base/_form.html.erb
|
24
|
+
- app/views/admin_space/base/edit.html.erb
|
25
|
+
- app/views/admin_space/base/index.html.erb
|
26
|
+
- app/views/admin_space/base/new.html.erb
|
27
|
+
- app/views/admin_space/base/show.html.erb
|
28
|
+
- app/views/layouts/admin_space.html.erb
|
29
|
+
- lib/admin_space/route.rb
|
30
|
+
- lib/admin_space/version.rb
|
31
|
+
- lib/admin_space.rb
|
32
|
+
- Gemfile
|
33
|
+
- LICENSE.txt
|
34
|
+
- README.md
|
35
|
+
- Rakefile
|
36
|
+
homepage: http://github.com/frozon/admin_space
|
37
|
+
licenses: []
|
38
|
+
post_install_message:
|
39
|
+
rdoc_options: []
|
40
|
+
require_paths:
|
41
|
+
- lib
|
42
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
43
|
+
none: false
|
44
|
+
requirements:
|
45
|
+
- - ! '>='
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '0'
|
48
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
49
|
+
none: false
|
50
|
+
requirements:
|
51
|
+
- - ! '>='
|
52
|
+
- !ruby/object:Gem::Version
|
53
|
+
version: '0'
|
54
|
+
requirements: []
|
55
|
+
rubyforge_project:
|
56
|
+
rubygems_version: 1.8.24
|
57
|
+
signing_key:
|
58
|
+
specification_version: 3
|
59
|
+
summary: AdminSpace handle admin namespace for you
|
60
|
+
test_files: []
|