admin_view 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- data/.gitignore +7 -0
- data/Gemfile +4 -0
- data/MIT-LICENSE +20 -0
- data/README.md +31 -0
- data/Rakefile +11 -0
- data/admin_view.gemspec +26 -0
- data/lib/admin_view/version.rb +3 -0
- data/lib/generators/USAGE +5 -0
- data/lib/generators/admin_view_generator.rb +65 -0
- data/lib/generators/templates/base_controller.rb +18 -0
- data/lib/generators/templates/base_controller_spec.rb +41 -0
- data/lib/generators/templates/controller.rb +67 -0
- data/lib/generators/templates/controller_spec.rb +130 -0
- data/lib/generators/templates/views/_form.html.erb +12 -0
- data/lib/generators/templates/views/edit.html.erb +5 -0
- data/lib/generators/templates/views/index.html.erb +43 -0
- data/lib/generators/templates/views/new.html.erb +5 -0
- data/lib/generators/templates/views/show.html.erb +11 -0
- data/test/admin_view_generator_test.rb +19 -0
- data/test/test_helper.rb +8 -0
- metadata +110 -0
data/.gitignore
ADDED
data/Gemfile
ADDED
data/MIT-LICENSE
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
Copyright 2011 Rendered Text: Darko Fabijan, Marko Anastasov
|
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,31 @@
|
|
1
|
+
# admin_view
|
2
|
+
|
3
|
+
Rails 3 generator of CRUD admin controllers, views and specs for existing models.
|
4
|
+
|
5
|
+
It uses [meta_search](https://github.com/ernie/meta_search) for search and [kaminari](https://github.com/amatsuda/kaminari) for pagination.
|
6
|
+
|
7
|
+
Screenshot:
|
8
|
+
|
9
|
+
![admin_view example screenshot](http://renderedtext.com/images/blog/admin_view.png)
|
10
|
+
|
11
|
+
## Usage
|
12
|
+
|
13
|
+
Include it in your Gemfile:
|
14
|
+
|
15
|
+
gem "admin_view"
|
16
|
+
|
17
|
+
Run the generator:
|
18
|
+
|
19
|
+
$ bundle exec admin_view User --search_by name_or_email
|
20
|
+
|
21
|
+
The `--search_by` option is not required - if you don't pass it, the form template will come out commented out. However, it's useful most of the time, and you can use any meta_search-compatible expression to search in string or text fields.
|
22
|
+
|
23
|
+
## Contributing
|
24
|
+
|
25
|
+
Yes! Feel free to fork the repo, make your changes in a topic branch and send us a pull request.
|
26
|
+
|
27
|
+
If you're having a problem or found a bug, please open an issue in the GitHub [issue tracker](https://github.com/renderedtext/admin_view/issues).
|
28
|
+
|
29
|
+
## License
|
30
|
+
|
31
|
+
Copyright © 2011 [Rendered Text](http://renderedtext.com). admin_view is free software, and may be redistributed under the terms specified in the MIT-LICENSE file.
|
data/Rakefile
ADDED
data/admin_view.gemspec
ADDED
@@ -0,0 +1,26 @@
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
2
|
+
$:.push File.expand_path("../lib", __FILE__)
|
3
|
+
require "admin_view/version"
|
4
|
+
|
5
|
+
Gem::Specification.new do |s|
|
6
|
+
s.name = "admin_view"
|
7
|
+
s.version = AdminView::VERSION
|
8
|
+
s.platform = Gem::Platform::RUBY
|
9
|
+
s.authors = ["Marko Anastasov", "Darko Fabijan"]
|
10
|
+
s.email = ["devs@renderedtext.com"]
|
11
|
+
s.homepage = "http://github.com/renderedtext/admin_view"
|
12
|
+
s.summary = %q{Rails 3 generator of admin views and controllers for existing models.}
|
13
|
+
s.description = %q{Rails 3 generator of admin views and controllers for existing models.}
|
14
|
+
|
15
|
+
s.rubyforge_project = "admin_view"
|
16
|
+
|
17
|
+
s.files = `git ls-files`.split("\n")
|
18
|
+
s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
|
19
|
+
s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
|
20
|
+
s.require_paths = ["lib"]
|
21
|
+
|
22
|
+
s.add_dependency("rails", ">= 3.0")
|
23
|
+
s.add_dependency("rspec-rails", ">= 2.4.0")
|
24
|
+
s.add_dependency("meta_search")
|
25
|
+
s.add_dependency("kaminari")
|
26
|
+
end
|
@@ -0,0 +1,65 @@
|
|
1
|
+
require 'rails/generators/resource_helpers'
|
2
|
+
require 'rails/generators/named_base'
|
3
|
+
|
4
|
+
class AdminViewGenerator < Rails::Generators::NamedBase
|
5
|
+
|
6
|
+
include Rails::Generators::ResourceHelpers
|
7
|
+
|
8
|
+
source_root File.expand_path('../templates', __FILE__)
|
9
|
+
|
10
|
+
class_option :search_by, :type => :string, :desc => "The field or criteria to meta_search by (not required, but without a doubt recommended)"
|
11
|
+
|
12
|
+
def create_base_controller
|
13
|
+
empty_directory "app/controllers/admin"
|
14
|
+
path = File.join("app/controllers/admin", "base_controller.rb")
|
15
|
+
template("base_controller.rb", path) unless File.exists?(path)
|
16
|
+
end
|
17
|
+
|
18
|
+
def create_base_controller_spec
|
19
|
+
empty_directory "spec/controllers/admin"
|
20
|
+
path = File.join("spec/controllers/admin", "base_controller_spec.rb")
|
21
|
+
template("base_controller_spec.rb", path) unless File.exists?(path)
|
22
|
+
end
|
23
|
+
|
24
|
+
def create_controller
|
25
|
+
template "controller.rb", File.join("app/controllers/admin", "#{controller_file_name}_controller.rb")
|
26
|
+
end
|
27
|
+
|
28
|
+
def create_controller_rspec
|
29
|
+
template "controller_spec.rb", File.join("spec/controllers/admin", "#{controller_file_name}_controller_spec.rb")
|
30
|
+
end
|
31
|
+
|
32
|
+
def create_views
|
33
|
+
empty_directory "app/views/admin/#{controller_file_name}"
|
34
|
+
if model_exists?(class_name)
|
35
|
+
@attributes = class_name.constantize.send(:columns)
|
36
|
+
available_views.each do |view|
|
37
|
+
template "views/#{view}.html.erb", File.join("app/views/admin", controller_file_name, "#{view}.html.erb")
|
38
|
+
end
|
39
|
+
end
|
40
|
+
end
|
41
|
+
|
42
|
+
def add_resource_route
|
43
|
+
return if not File.exists?("config/routes.rb")
|
44
|
+
route_config = "namespace :admin do "
|
45
|
+
route_config << "resources :#{file_name.pluralize}"
|
46
|
+
route_config << " end"
|
47
|
+
route route_config
|
48
|
+
end
|
49
|
+
|
50
|
+
protected
|
51
|
+
|
52
|
+
def available_views
|
53
|
+
["index", "new", "show", "edit", "_form"]
|
54
|
+
end
|
55
|
+
|
56
|
+
def model_exists?(klass_name)
|
57
|
+
begin
|
58
|
+
klass = Module.const_get(klass_name)
|
59
|
+
return klass.superclass == ActiveRecord::Base
|
60
|
+
rescue NameError
|
61
|
+
return false
|
62
|
+
end
|
63
|
+
end
|
64
|
+
|
65
|
+
end
|
@@ -0,0 +1,18 @@
|
|
1
|
+
class Admin::BaseController < ApplicationController
|
2
|
+
|
3
|
+
before_filter :require_admin
|
4
|
+
|
5
|
+
protected
|
6
|
+
|
7
|
+
def require_admin
|
8
|
+
unless current_user.try(:admin?)
|
9
|
+
render404 and return false
|
10
|
+
end
|
11
|
+
end
|
12
|
+
|
13
|
+
def render404
|
14
|
+
render :file => File.join(Rails.root, 'public', '404.html'), :status => 404
|
15
|
+
return true
|
16
|
+
end
|
17
|
+
|
18
|
+
end
|
@@ -0,0 +1,41 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe Admin::BaseController do
|
4
|
+
|
5
|
+
describe "GET 'index'" do
|
6
|
+
|
7
|
+
context "logged in as admin" do
|
8
|
+
|
9
|
+
it "renders index page" do
|
10
|
+
controller.stub_chain(:current_user, :admin?).and_return(true)
|
11
|
+
get :index
|
12
|
+
response.should render_template('index')
|
13
|
+
end
|
14
|
+
|
15
|
+
end
|
16
|
+
|
17
|
+
context "logged in as user" do
|
18
|
+
|
19
|
+
it "renders 404" do
|
20
|
+
controller.stub_chain(:current_user, :admin?).and_return(false)
|
21
|
+
get :index
|
22
|
+
response.should render_template('404.html')
|
23
|
+
response.response_code.should eql(404)
|
24
|
+
end
|
25
|
+
|
26
|
+
end
|
27
|
+
|
28
|
+
context "not logged in" do
|
29
|
+
|
30
|
+
it "renders 404" do
|
31
|
+
controller.stub(:current_user).and_return(nil)
|
32
|
+
get :index
|
33
|
+
response.should render_template('404.html')
|
34
|
+
response.response_code.should eql(404)
|
35
|
+
end
|
36
|
+
|
37
|
+
end
|
38
|
+
|
39
|
+
end
|
40
|
+
|
41
|
+
end
|
@@ -0,0 +1,67 @@
|
|
1
|
+
class Admin::<%= controller_class_name %>Controller < Admin::BaseController
|
2
|
+
|
3
|
+
helper_method :sort_column, :sort_direction, :search_params
|
4
|
+
|
5
|
+
before_filter :find_<%= singular_table_name %>, :only => [:edit, :update, :show, :destroy]
|
6
|
+
|
7
|
+
def index
|
8
|
+
@search = <%= class_name %>.search(params[:search])
|
9
|
+
@<%= plural_table_name %> = find_<%= plural_table_name %>
|
10
|
+
end
|
11
|
+
|
12
|
+
def new
|
13
|
+
@<%= singular_table_name %> = <%= class_name %>.new
|
14
|
+
end
|
15
|
+
|
16
|
+
def create
|
17
|
+
@<%= singular_table_name %> = <%= class_name %>.new(params[:<%= singular_table_name %>])
|
18
|
+
if @<%= singular_table_name %>.save
|
19
|
+
redirect_to admin_<%= plural_table_name %>_path, :notice => "Successfully created <%= human_name.downcase %>."
|
20
|
+
else
|
21
|
+
render :new
|
22
|
+
end
|
23
|
+
end
|
24
|
+
|
25
|
+
def show
|
26
|
+
end
|
27
|
+
|
28
|
+
def edit
|
29
|
+
end
|
30
|
+
|
31
|
+
def update
|
32
|
+
if @<%= singular_table_name %>.update_attributes(params[:<%= singular_table_name %>])
|
33
|
+
redirect_to admin_<%= plural_table_name %>_path, :notice => "Successfully updated <%= human_name.downcase %>."
|
34
|
+
else
|
35
|
+
render :edit
|
36
|
+
end
|
37
|
+
end
|
38
|
+
|
39
|
+
def destroy
|
40
|
+
@<%= singular_table_name %>.destroy
|
41
|
+
redirect_to admin_<%= plural_table_name %>_path, :notice => "<%= human_name %> has been deleted."
|
42
|
+
end
|
43
|
+
|
44
|
+
protected
|
45
|
+
|
46
|
+
def find_<%= singular_table_name %>
|
47
|
+
@<%= singular_table_name %> = <%= class_name %>.find(params[:id])
|
48
|
+
end
|
49
|
+
|
50
|
+
def find_<%= plural_table_name %>
|
51
|
+
search_relation = @search.relation
|
52
|
+
search_relation.order(sort_column + " " + sort_direction).page params[:page]
|
53
|
+
end
|
54
|
+
|
55
|
+
def sort_column
|
56
|
+
<%= class_name %>.column_names.include?(params[:sort]) ? params[:sort] : "created_at"
|
57
|
+
end
|
58
|
+
|
59
|
+
def sort_direction
|
60
|
+
%w[asc desc].include?(params[:direction]) ? params[:direction] : "desc"
|
61
|
+
end
|
62
|
+
|
63
|
+
def search_params
|
64
|
+
{:search => params[:search]}
|
65
|
+
end
|
66
|
+
|
67
|
+
end
|
@@ -0,0 +1,130 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe Admin::<%= controller_class_name %>Controller do
|
4
|
+
|
5
|
+
def mock_<%= singular_table_name %>(stubs={})
|
6
|
+
(@mock_<%= singular_table_name %> ||= mock_model(<%= class_name %>).as_null_object).tap do |<%= singular_table_name %>|
|
7
|
+
<%= singular_table_name %>.stub(stubs) unless stubs.empty?
|
8
|
+
end
|
9
|
+
end
|
10
|
+
|
11
|
+
before { controller.stub(:require_admin) }
|
12
|
+
|
13
|
+
describe "GET index" do
|
14
|
+
it "assigns all <%= plural_table_name %> as @<%= plural_table_name %>" do
|
15
|
+
controller.stub(:find_<%= plural_table_name %>).and_return([mock_<%= singular_table_name %>])
|
16
|
+
get :index
|
17
|
+
assigns(:<%= plural_table_name %>).should eq([mock_<%= singular_table_name %>])
|
18
|
+
end
|
19
|
+
end
|
20
|
+
|
21
|
+
describe "GET show" do
|
22
|
+
it "assigns the requested <%= singular_table_name %> as @<%=singular_table_name %>" do
|
23
|
+
<%= class_name %>.stub(:find).with("37") { mock_<%= singular_table_name %> }
|
24
|
+
get :show, :id => "37"
|
25
|
+
assigns(:<%= singular_table_name %>).should be(mock_<%= singular_table_name %>)
|
26
|
+
end
|
27
|
+
end
|
28
|
+
|
29
|
+
describe "GET new" do
|
30
|
+
it "assigns a new <%= singular_table_name %> as @<%= singular_table_name %>" do
|
31
|
+
<%= class_name %>.stub(:new) { mock_<%= singular_table_name %> }
|
32
|
+
get :new
|
33
|
+
assigns(:<%= singular_table_name %>).should be(mock_<%= singular_table_name %>)
|
34
|
+
end
|
35
|
+
end
|
36
|
+
|
37
|
+
describe "GET edit" do
|
38
|
+
it "assigns the requested <%= singular_table_name %> as @<%= singular_table_name %>" do
|
39
|
+
<%= class_name %>.stub(:find).with("37") { mock_<%= singular_table_name %> }
|
40
|
+
get :edit, :id => "37"
|
41
|
+
assigns(:<%= singular_table_name %>).should be(mock_<%= singular_table_name %>)
|
42
|
+
end
|
43
|
+
end
|
44
|
+
|
45
|
+
describe "POST create" do
|
46
|
+
|
47
|
+
describe "with valid params" do
|
48
|
+
it "assigns a newly created <%= singular_table_name %> as @<%= singular_table_name %>" do
|
49
|
+
<%= class_name %>.stub(:new).with({'these' => 'params'}) { mock_<%= singular_table_name %>(:save => true) }
|
50
|
+
post :create, :<%= singular_table_name %> => {'these' => 'params'}
|
51
|
+
assigns(:<%= singular_table_name %>).should be(mock_<%= singular_table_name %>)
|
52
|
+
end
|
53
|
+
|
54
|
+
it "redirects to the created <%= singular_table_name %>" do
|
55
|
+
<%= class_name %>.stub(:new) { mock_<%= singular_table_name %>(:save => true) }
|
56
|
+
post :create, :<%= singular_table_name %> => {}
|
57
|
+
response.should redirect_to(admin_<%= plural_table_name %>_url)
|
58
|
+
end
|
59
|
+
end
|
60
|
+
|
61
|
+
describe "with invalid params" do
|
62
|
+
it "assigns a newly created but unsaved <%= singular_table_name %> as @<%= singular_table_name %>" do
|
63
|
+
<%= class_name %>.stub(:new).with({'these' => 'params'}) { mock_<%= singular_table_name %>(:save => false) }
|
64
|
+
post :create, :<%= singular_table_name %> => {'these' => 'params'}
|
65
|
+
assigns(:<%= singular_table_name %>).should be(mock_<%= singular_table_name %>)
|
66
|
+
end
|
67
|
+
|
68
|
+
it "re-renders the 'new' template" do
|
69
|
+
<%= class_name %>.stub(:new) { mock_<%= singular_table_name %>(:save => false) }
|
70
|
+
post :create, :<%= singular_table_name %> => {}
|
71
|
+
response.should render_template("new")
|
72
|
+
end
|
73
|
+
end
|
74
|
+
|
75
|
+
end
|
76
|
+
|
77
|
+
describe "PUT update" do
|
78
|
+
|
79
|
+
describe "with valid params" do
|
80
|
+
it "updates the requested <%= singular_table_name %>" do
|
81
|
+
<%= class_name %>.should_receive(:find).with("37") { mock_<%= singular_table_name %> }
|
82
|
+
mock_<%= singular_table_name %>.should_receive(:update_attributes).with({'these' => 'params'})
|
83
|
+
put :update, :id => "37", :<%= singular_table_name %> => {'these' => 'params'}
|
84
|
+
end
|
85
|
+
|
86
|
+
it "assigns the requested <%= singular_table_name %> as @<%= singular_table_name %>" do
|
87
|
+
<%= class_name %>.stub(:find) { mock_<%= singular_table_name %>(:update_attributes => true) }
|
88
|
+
put :update, :id => "1"
|
89
|
+
assigns(:<%= singular_table_name %>).should be(mock_<%= singular_table_name %>)
|
90
|
+
end
|
91
|
+
|
92
|
+
it "redirects to the <%= singular_table_name %>" do
|
93
|
+
<%= class_name %>.stub(:find) { mock_<%= singular_table_name %>(:update_attributes => true) }
|
94
|
+
put :update, :id => "1"
|
95
|
+
response.should redirect_to(admin_<%= plural_table_name %>_url)
|
96
|
+
end
|
97
|
+
end
|
98
|
+
|
99
|
+
describe "with invalid params" do
|
100
|
+
it "assigns the <%= singular_table_name %> as @<%= singular_table_name %>" do
|
101
|
+
<%= class_name %>.stub(:find) { mock_<%= singular_table_name %>(:update_attributes => false) }
|
102
|
+
put :update, :id => "1"
|
103
|
+
assigns(:<%= singular_table_name %>).should be(mock_<%= singular_table_name %>)
|
104
|
+
end
|
105
|
+
|
106
|
+
it "re-renders the 'edit' template" do
|
107
|
+
<%= class_name %>.stub(:find) { mock_<%= singular_table_name %>(:update_attributes => false) }
|
108
|
+
put :update, :id => "1"
|
109
|
+
response.should render_template("edit")
|
110
|
+
end
|
111
|
+
end
|
112
|
+
|
113
|
+
end
|
114
|
+
|
115
|
+
describe "DELETE destroy" do
|
116
|
+
it "destroys the requested <%= singular_table_name %>" do
|
117
|
+
<%= class_name %>.should_receive(:find).with("37") { mock_<%= singular_table_name %> }
|
118
|
+
mock_<%= singular_table_name %>.should_receive(:destroy)
|
119
|
+
delete :destroy, :id => "37"
|
120
|
+
end
|
121
|
+
|
122
|
+
it "redirects to the <%= plural_table_name %> list" do
|
123
|
+
<%= class_name %>.stub(:find) { mock_<%= singular_table_name %> }
|
124
|
+
delete :destroy, :id => "1"
|
125
|
+
response.should redirect_to(admin_<%= plural_table_name %>_url)
|
126
|
+
end
|
127
|
+
end
|
128
|
+
|
129
|
+
end
|
130
|
+
|
@@ -0,0 +1,12 @@
|
|
1
|
+
<%%= f.error_messages %>
|
2
|
+
|
3
|
+
<% @attributes.each do |attribute| -%>
|
4
|
+
<% next if ["id", "created_at", "updated_at"].include?(attribute.name) -%>
|
5
|
+
<p>
|
6
|
+
<%%= f.label :<%= attribute.name %> %><br />
|
7
|
+
<%%= f.text_field :<%= attribute.name %> %>
|
8
|
+
</p>
|
9
|
+
<% end -%>
|
10
|
+
|
11
|
+
<%% label = @<%= singular_table_name %>.new_record? ? "Create" : "Update" -%>
|
12
|
+
<%%= f.submit label %>
|
@@ -0,0 +1,43 @@
|
|
1
|
+
<h2><%= human_name.pluralize %></h2>
|
2
|
+
|
3
|
+
<%%= form_for @search, :url => admin_<%= plural_table_name %>_path, :html => {:method => :get} do |f| %>
|
4
|
+
<% if options[:search_by].blank? -%>
|
5
|
+
<!--
|
6
|
+
<% end %>
|
7
|
+
<!-- feel free to add further search options, eg foo_or_bar_contains -->
|
8
|
+
<%%= f.label :<%= options[:search_by] %>_contains, "Search by <%= options[:search_by] %>" %>
|
9
|
+
<%%= f.text_field :<%= options[:search_by] %>_contains %>
|
10
|
+
<%%= f.submit %>
|
11
|
+
<% if options[:search_by].blank? -%>
|
12
|
+
--><p>Set up your search form or delete.</p>
|
13
|
+
<% end %>
|
14
|
+
<%% end %>
|
15
|
+
|
16
|
+
<p><%%= link_to("Create a new <%= human_name %>", new_admin_<%= singular_table_name %>_path) %></p>
|
17
|
+
|
18
|
+
<table class="sortable">
|
19
|
+
<thead>
|
20
|
+
<tr>
|
21
|
+
<% @attributes.each do |attribute| -%>
|
22
|
+
<th><%%= sortable "<%= attribute.name %>" %></th>
|
23
|
+
<% end -%>
|
24
|
+
<th>Edit</th>
|
25
|
+
<th>Delete</th>
|
26
|
+
</tr>
|
27
|
+
</thead>
|
28
|
+
<tbody>
|
29
|
+
<%% @<%= plural_table_name %>.each do |<%= singular_table_name %>| %>
|
30
|
+
<tr>
|
31
|
+
<td><%%= link_to(<%= singular_table_name %>.id, admin_<%= singular_table_name %>_path(<%= singular_table_name %>)) %></td>
|
32
|
+
<% @attributes.each do |attribute| -%>
|
33
|
+
<% next if attribute.name == "id" -%>
|
34
|
+
<td><%%= <%= singular_table_name %>.<%= attribute.name %> %></td>
|
35
|
+
<% end -%>
|
36
|
+
<td><%%= link_to('Edit', edit_admin_<%= singular_table_name %>_path(<%= singular_table_name %>)) %></td>
|
37
|
+
<td><%%= link_to('Delete', admin_<%= singular_table_name %>_path(<%= singular_table_name %>), :confirm => "Are you sure?", :method => :delete) %></td>
|
38
|
+
</tr>
|
39
|
+
<%% end %>
|
40
|
+
</tbody>
|
41
|
+
</table>
|
42
|
+
|
43
|
+
<%%= paginate @<%= plural_table_name %> %>
|
@@ -0,0 +1,11 @@
|
|
1
|
+
<h1><%= human_name.capitalize %> <%%= @<%= singular_table_name %>.id %></h1>
|
2
|
+
|
3
|
+
<% @attributes.each do |attribute| -%>
|
4
|
+
<p>
|
5
|
+
<strong><%= attribute.human_name %>:</strong>
|
6
|
+
<%%= @<%= singular_table_name %>.<%= attribute.name %> %>
|
7
|
+
</p>
|
8
|
+
<% end -%>
|
9
|
+
|
10
|
+
<%%= link_to "Edit", edit_admin_<%= singular_table_name %>_path(@<%= singular_table_name %>) %> |
|
11
|
+
<%%= link_to "Back", admin_<%= plural_table_name %>_path %>
|
@@ -0,0 +1,19 @@
|
|
1
|
+
require File.join(File.dirname(__FILE__), 'test_helper')
|
2
|
+
|
3
|
+
require 'generators/admin_view_generator'
|
4
|
+
|
5
|
+
class AdminViewGeneratorTest < Rails::Generators::TestCase
|
6
|
+
|
7
|
+
destination File.expand_path("../tmp", File.dirname(__FILE__))
|
8
|
+
setup :prepare_destination
|
9
|
+
tests AdminViewGenerator
|
10
|
+
|
11
|
+
test "create the controllers and specs" do
|
12
|
+
run_generator %w(User --search_by email)
|
13
|
+
|
14
|
+
assert_file "app/controllers/admin/base_controller.rb", /class Admin::BaseController < ApplicationController/
|
15
|
+
assert_file "app/controllers/admin/users_controller.rb", /class Admin::UsersController < Admin::BaseController/
|
16
|
+
assert_file "spec/controllers/admin/base_controller_spec.rb", /describe Admin::BaseController do/
|
17
|
+
assert_file "spec/controllers/admin/users_controller_spec.rb", /describe Admin::UsersController do/
|
18
|
+
end
|
19
|
+
end
|
data/test/test_helper.rb
ADDED
metadata
ADDED
@@ -0,0 +1,110 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: admin_view
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
prerelease:
|
6
|
+
platform: ruby
|
7
|
+
authors:
|
8
|
+
- Marko Anastasov
|
9
|
+
- Darko Fabijan
|
10
|
+
autorequire:
|
11
|
+
bindir: bin
|
12
|
+
cert_chain: []
|
13
|
+
date: 2011-09-19 00:00:00.000000000Z
|
14
|
+
dependencies:
|
15
|
+
- !ruby/object:Gem::Dependency
|
16
|
+
name: rails
|
17
|
+
requirement: &17270240 !ruby/object:Gem::Requirement
|
18
|
+
none: false
|
19
|
+
requirements:
|
20
|
+
- - ! '>='
|
21
|
+
- !ruby/object:Gem::Version
|
22
|
+
version: '3.0'
|
23
|
+
type: :runtime
|
24
|
+
prerelease: false
|
25
|
+
version_requirements: *17270240
|
26
|
+
- !ruby/object:Gem::Dependency
|
27
|
+
name: rspec-rails
|
28
|
+
requirement: &17269740 !ruby/object:Gem::Requirement
|
29
|
+
none: false
|
30
|
+
requirements:
|
31
|
+
- - ! '>='
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: 2.4.0
|
34
|
+
type: :runtime
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: *17269740
|
37
|
+
- !ruby/object:Gem::Dependency
|
38
|
+
name: meta_search
|
39
|
+
requirement: &17269360 !ruby/object:Gem::Requirement
|
40
|
+
none: false
|
41
|
+
requirements:
|
42
|
+
- - ! '>='
|
43
|
+
- !ruby/object:Gem::Version
|
44
|
+
version: '0'
|
45
|
+
type: :runtime
|
46
|
+
prerelease: false
|
47
|
+
version_requirements: *17269360
|
48
|
+
- !ruby/object:Gem::Dependency
|
49
|
+
name: kaminari
|
50
|
+
requirement: &17268900 !ruby/object:Gem::Requirement
|
51
|
+
none: false
|
52
|
+
requirements:
|
53
|
+
- - ! '>='
|
54
|
+
- !ruby/object:Gem::Version
|
55
|
+
version: '0'
|
56
|
+
type: :runtime
|
57
|
+
prerelease: false
|
58
|
+
version_requirements: *17268900
|
59
|
+
description: Rails 3 generator of admin views and controllers for existing models.
|
60
|
+
email:
|
61
|
+
- devs@renderedtext.com
|
62
|
+
executables: []
|
63
|
+
extensions: []
|
64
|
+
extra_rdoc_files: []
|
65
|
+
files:
|
66
|
+
- .gitignore
|
67
|
+
- Gemfile
|
68
|
+
- MIT-LICENSE
|
69
|
+
- README.md
|
70
|
+
- Rakefile
|
71
|
+
- admin_view.gemspec
|
72
|
+
- lib/admin_view/version.rb
|
73
|
+
- lib/generators/USAGE
|
74
|
+
- lib/generators/admin_view_generator.rb
|
75
|
+
- lib/generators/templates/base_controller.rb
|
76
|
+
- lib/generators/templates/base_controller_spec.rb
|
77
|
+
- lib/generators/templates/controller.rb
|
78
|
+
- lib/generators/templates/controller_spec.rb
|
79
|
+
- lib/generators/templates/views/_form.html.erb
|
80
|
+
- lib/generators/templates/views/edit.html.erb
|
81
|
+
- lib/generators/templates/views/index.html.erb
|
82
|
+
- lib/generators/templates/views/new.html.erb
|
83
|
+
- lib/generators/templates/views/show.html.erb
|
84
|
+
- test/admin_view_generator_test.rb
|
85
|
+
- test/test_helper.rb
|
86
|
+
homepage: http://github.com/renderedtext/admin_view
|
87
|
+
licenses: []
|
88
|
+
post_install_message:
|
89
|
+
rdoc_options: []
|
90
|
+
require_paths:
|
91
|
+
- lib
|
92
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
93
|
+
none: false
|
94
|
+
requirements:
|
95
|
+
- - ! '>='
|
96
|
+
- !ruby/object:Gem::Version
|
97
|
+
version: '0'
|
98
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
99
|
+
none: false
|
100
|
+
requirements:
|
101
|
+
- - ! '>='
|
102
|
+
- !ruby/object:Gem::Version
|
103
|
+
version: '0'
|
104
|
+
requirements: []
|
105
|
+
rubyforge_project: admin_view
|
106
|
+
rubygems_version: 1.8.8
|
107
|
+
signing_key:
|
108
|
+
specification_version: 3
|
109
|
+
summary: Rails 3 generator of admin views and controllers for existing models.
|
110
|
+
test_files: []
|