material_admin 0.0.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/MIT-LICENSE +20 -0
- data/README.rdoc +3 -0
- data/Rakefile +34 -0
- data/lib/generators/admin/scaffold_controller/USAGE +15 -0
- data/lib/generators/admin/scaffold_controller/scaffold_controller_generator.rb +202 -0
- data/lib/generators/admin/scaffold_controller/templates/controllers/jbuilder/controller.rb.erb +85 -0
- data/lib/generators/admin/scaffold_controller/templates/controllers/railties/controller.rb.erb +68 -0
- data/lib/generators/admin/scaffold_controller/templates/layout/layout.html.erb +51 -0
- data/lib/generators/admin/scaffold_controller/templates/tests/test_unit/functional_test.rb.erb +51 -0
- data/lib/generators/admin/scaffold_controller/templates/views/erb/_form.html.erb.erb +32 -0
- data/lib/generators/admin/scaffold_controller/templates/views/erb/edit.html.erb.erb +4 -0
- data/lib/generators/admin/scaffold_controller/templates/views/erb/index.html.erb.erb +53 -0
- data/lib/generators/admin/scaffold_controller/templates/views/erb/new.html.erb.erb +5 -0
- data/lib/generators/admin/scaffold_controller/templates/views/erb/show.html.erb.erb +11 -0
- data/lib/generators/admin/scaffold_controller/templates/views/jbuilder/index.json.jbuilder.erb +4 -0
- data/lib/generators/admin/scaffold_controller/templates/views/jbuilder/show.json.jbuilder.erb +1 -0
- data/lib/material_admin/version.rb +3 -0
- data/lib/material_admin.rb +9 -0
- data/lib/tasks/material_admin_tasks.rake +4 -0
- data/test/dummy/README.rdoc +28 -0
- data/test/dummy/Rakefile +6 -0
- data/test/dummy/app/assets/javascripts/application.js +13 -0
- data/test/dummy/app/assets/stylesheets/application.css +15 -0
- data/test/dummy/app/controllers/application_controller.rb +5 -0
- data/test/dummy/app/helpers/application_helper.rb +2 -0
- data/test/dummy/app/views/layouts/application.html.erb +14 -0
- data/test/dummy/bin/bundle +3 -0
- data/test/dummy/bin/rails +4 -0
- data/test/dummy/bin/rake +4 -0
- data/test/dummy/bin/setup +29 -0
- data/test/dummy/config/application.rb +26 -0
- data/test/dummy/config/boot.rb +5 -0
- data/test/dummy/config/database.yml +25 -0
- data/test/dummy/config/environment.rb +5 -0
- data/test/dummy/config/environments/development.rb +41 -0
- data/test/dummy/config/environments/production.rb +79 -0
- data/test/dummy/config/environments/test.rb +42 -0
- data/test/dummy/config/initializers/assets.rb +11 -0
- data/test/dummy/config/initializers/backtrace_silencers.rb +7 -0
- data/test/dummy/config/initializers/cookies_serializer.rb +3 -0
- data/test/dummy/config/initializers/filter_parameter_logging.rb +4 -0
- data/test/dummy/config/initializers/inflections.rb +16 -0
- data/test/dummy/config/initializers/mime_types.rb +4 -0
- data/test/dummy/config/initializers/session_store.rb +3 -0
- data/test/dummy/config/initializers/wrap_parameters.rb +14 -0
- data/test/dummy/config/locales/en.yml +23 -0
- data/test/dummy/config/routes.rb +56 -0
- data/test/dummy/config/secrets.yml +22 -0
- data/test/dummy/config.ru +4 -0
- data/test/dummy/public/404.html +67 -0
- data/test/dummy/public/422.html +67 -0
- data/test/dummy/public/500.html +66 -0
- data/test/dummy/public/favicon.ico +0 -0
- data/test/material_admin_test.rb +7 -0
- data/test/test_helper.rb +20 -0
- metadata +233 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: d4bbc5eb990cc8e600d0d9cf7990411ab78d71a3
|
4
|
+
data.tar.gz: 4d9f577a642ba23b602e683f55707f6aeadd4f7b
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 2fec6619573c309a3e8adde17de480826f62f99bb76b6161a63c1a3f6fc86f1ade5127e4db82061a87d613a7e8e7efa7b95f257db35e36ca19279986ba55fd1c
|
7
|
+
data.tar.gz: 960bc4102e22a657d8b3073abfc482152e24a7880905b91927070fd4f44b4980a3793538cb5118db1ade20f6c8d109283c0cdeb53b2cf2330f2818408f895e5c
|
data/MIT-LICENSE
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
Copyright 2016
|
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.rdoc
ADDED
data/Rakefile
ADDED
@@ -0,0 +1,34 @@
|
|
1
|
+
begin
|
2
|
+
require 'bundler/setup'
|
3
|
+
rescue LoadError
|
4
|
+
puts 'You must `gem install bundler` and `bundle install` to run rake tasks'
|
5
|
+
end
|
6
|
+
|
7
|
+
require 'rdoc/task'
|
8
|
+
|
9
|
+
RDoc::Task.new(:rdoc) do |rdoc|
|
10
|
+
rdoc.rdoc_dir = 'rdoc'
|
11
|
+
rdoc.title = 'MaterialAdmin'
|
12
|
+
rdoc.options << '--line-numbers'
|
13
|
+
rdoc.rdoc_files.include('README.rdoc')
|
14
|
+
rdoc.rdoc_files.include('lib/**/*.rb')
|
15
|
+
end
|
16
|
+
|
17
|
+
|
18
|
+
|
19
|
+
|
20
|
+
|
21
|
+
|
22
|
+
Bundler::GemHelper.install_tasks
|
23
|
+
|
24
|
+
require 'rake/testtask'
|
25
|
+
|
26
|
+
Rake::TestTask.new(:test) do |t|
|
27
|
+
t.libs << 'lib'
|
28
|
+
t.libs << 'test'
|
29
|
+
t.pattern = 'test/**/*_test.rb'
|
30
|
+
t.verbose = false
|
31
|
+
end
|
32
|
+
|
33
|
+
|
34
|
+
task default: :test
|
@@ -0,0 +1,15 @@
|
|
1
|
+
Description:
|
2
|
+
Stubs out a scaffolded controller, its seven RESTful actions and related
|
3
|
+
views. Pass the model name, either CamelCased or under_scored. The
|
4
|
+
controller name is retrieved as a pluralized version of the model name
|
5
|
+
namespaces within Admin namespaced.
|
6
|
+
|
7
|
+
This generates a controller class in app/controllers/admin and invokes helper,
|
8
|
+
template engine and test framework generators.
|
9
|
+
It uses non-namespaced model in app/models
|
10
|
+
|
11
|
+
If you want change the prefix name 'admin' to something else you can pass --prefix_name option
|
12
|
+
|
13
|
+
Example:
|
14
|
+
`bin/rails generate admin:scaffold_controller Post`
|
15
|
+
`bin/rails g admin:scaffold_controller Post title:string content:text published:boolean --prefix_name=manager`
|
@@ -0,0 +1,202 @@
|
|
1
|
+
require 'rubygems/specification'
|
2
|
+
require 'rails/generators/named_base'
|
3
|
+
require 'rails/generators/resource_helpers'
|
4
|
+
|
5
|
+
module Admin
|
6
|
+
module Generators
|
7
|
+
class ScaffoldControllerGenerator < Rails::Generators::NamedBase
|
8
|
+
include Rails::Generators::ResourceHelpers
|
9
|
+
|
10
|
+
source_root File.expand_path('../templates', __FILE__)
|
11
|
+
|
12
|
+
class_option :template_engine, desc: 'Template engine to be invoked (erb or haml).'
|
13
|
+
|
14
|
+
check_class_collision suffix: "Controller"
|
15
|
+
|
16
|
+
check_class_collision suffix: "ControllerTest"
|
17
|
+
|
18
|
+
check_class_collision suffix: "Helper"
|
19
|
+
|
20
|
+
class_option :orm, banner: "NAME", type: :string, required: true,
|
21
|
+
desc: "ORM to generate the controller for"
|
22
|
+
|
23
|
+
class_option :html, type: :boolean, default: true,
|
24
|
+
desc: "Generate a scaffold with HTML output"
|
25
|
+
|
26
|
+
class_option :prefix_name, banner: "admin", type: :string, default: "admin",
|
27
|
+
desc: "Define the prefix of controller"
|
28
|
+
|
29
|
+
class_option :parent_controller, banner: "admin", type: :string, default: "admin",
|
30
|
+
desc: "Define the parent controller"
|
31
|
+
|
32
|
+
argument :attributes, type: :array, default: [], banner: "field:type field:type"
|
33
|
+
|
34
|
+
def initialize(args, *options) #:nodoc:
|
35
|
+
if args.length == 1
|
36
|
+
blacklist = %w(created_at updated_at id)
|
37
|
+
args[0].camelize.constantize.columns_hash.each do |k,v|
|
38
|
+
unless blacklist.include?(k)
|
39
|
+
string = "#{k}:#{v.type}"
|
40
|
+
args << string
|
41
|
+
end
|
42
|
+
end
|
43
|
+
end
|
44
|
+
super
|
45
|
+
end
|
46
|
+
|
47
|
+
hook_for :resource_route, in: :rails do |resource_route|
|
48
|
+
invoke resource_route, [prefixed_class_name]
|
49
|
+
end
|
50
|
+
|
51
|
+
def create_controller_files
|
52
|
+
# I think there should be a better way to detect if jbuilder is in use
|
53
|
+
# If you know it, please let me know
|
54
|
+
if Gem::Specification.find_all_by_name('jbuilder').length >= 1
|
55
|
+
template "controllers/jbuilder/controller.rb.erb", File.join('app/controllers', prefix, class_path, "#{controller_file_name}_controller.rb")
|
56
|
+
else
|
57
|
+
template "controllers/railties/controller.rb.erb", File.join('app/controllers', prefix, class_path, "#{controller_file_name}_controller.rb")
|
58
|
+
end
|
59
|
+
end
|
60
|
+
|
61
|
+
def create_layout
|
62
|
+
copy_file "admin.css", "app/assets/stylesheet/#{prefix}/#{prefix}.css"
|
63
|
+
copy_file "admin.js", "app/assets/javascript/#{prefix}/#{prefix}.js"
|
64
|
+
template "layout.html.erb", "app/views/layouts/#{prefix}.html.erb"
|
65
|
+
end
|
66
|
+
|
67
|
+
def create_test_files
|
68
|
+
template "tests/test_unit/functional_test.rb.erb", File.join("test/controllers", prefix, controller_class_path, "#{controller_file_name}_controller_test.rb")
|
69
|
+
end
|
70
|
+
|
71
|
+
hook_for :helper, in: :rails do |helper|
|
72
|
+
invoke helper, [prefixed_controller_class_name]
|
73
|
+
end
|
74
|
+
|
75
|
+
def create_root_folder
|
76
|
+
empty_directory File.join("app/views", prefix, controller_file_path)
|
77
|
+
end
|
78
|
+
|
79
|
+
def copy_view_files
|
80
|
+
available_views.each do |view|
|
81
|
+
filename = filename_with_extensions(view)
|
82
|
+
if bootstrap
|
83
|
+
template_path = "views/#{handler}_bootstrap/#{filename}.erb"
|
84
|
+
else
|
85
|
+
template_path = "views/#{handler}/#{filename}.erb"
|
86
|
+
end
|
87
|
+
template template_path, File.join("app/views", prefix, controller_file_path, filename)
|
88
|
+
end
|
89
|
+
|
90
|
+
# I think there should be a better way to detect if jbuilder is in use
|
91
|
+
if Gem::Specification.find_all_by_name('jbuilder').length >= 1
|
92
|
+
%w(index show).each do |view|
|
93
|
+
template "views/jbuilder/#{view}.json.jbuilder.erb", File.join("app/views", prefix, controller_file_path, "#{view}.json.jbuilder")
|
94
|
+
end
|
95
|
+
end
|
96
|
+
end
|
97
|
+
|
98
|
+
hook_for :assets, in: :rails do |assets|
|
99
|
+
invoke assets, [prefixed_class_name]
|
100
|
+
end
|
101
|
+
|
102
|
+
protected
|
103
|
+
|
104
|
+
def bootstrap
|
105
|
+
options[:bootstrap]
|
106
|
+
end
|
107
|
+
|
108
|
+
def prefix
|
109
|
+
options[:prefix_name]
|
110
|
+
end
|
111
|
+
|
112
|
+
def prefixed_class_name
|
113
|
+
"#{prefix.capitalize}::#{class_name}"
|
114
|
+
end
|
115
|
+
|
116
|
+
def prefixed_controller_class_name
|
117
|
+
"#{prefix.capitalize}::#{controller_class_name}"
|
118
|
+
end
|
119
|
+
|
120
|
+
def parent_controller_class_name
|
121
|
+
options[:parent_controller].capitalize
|
122
|
+
end
|
123
|
+
|
124
|
+
def prefixed_route_url
|
125
|
+
"/#{prefix}#{route_url}"
|
126
|
+
end
|
127
|
+
|
128
|
+
def prefixed_plain_model_url
|
129
|
+
"#{prefix}_#{singular_table_name}"
|
130
|
+
end
|
131
|
+
|
132
|
+
def prefixed_index_helper
|
133
|
+
"#{prefix}_#{index_helper}"
|
134
|
+
end
|
135
|
+
|
136
|
+
def available_views
|
137
|
+
%w(index edit show new _form)
|
138
|
+
end
|
139
|
+
|
140
|
+
def format
|
141
|
+
:html
|
142
|
+
end
|
143
|
+
|
144
|
+
def handler
|
145
|
+
options[:template_engine]
|
146
|
+
end
|
147
|
+
|
148
|
+
def filename_with_extensions(name)
|
149
|
+
[name, format, handler].compact.join(".")
|
150
|
+
end
|
151
|
+
|
152
|
+
# Add a class collisions name to be checked on class initialization. You
|
153
|
+
# can supply a hash with a :prefix or :suffix to be tested.
|
154
|
+
#
|
155
|
+
# ==== Examples
|
156
|
+
#
|
157
|
+
# check_class_collision suffix: "Decorator"
|
158
|
+
#
|
159
|
+
# If the generator is invoked with class name Admin, it will check for
|
160
|
+
# the presence of "AdminDecorator".
|
161
|
+
#
|
162
|
+
def self.check_class_collision(options={})
|
163
|
+
define_method :check_class_collision do
|
164
|
+
name = if self.respond_to?(:prefixed_controller_class_name) # for ScaffoldBase
|
165
|
+
prefixed_controller_class_name
|
166
|
+
elsif self.respond_to?(:prefixed_controller_class_name) # for ScaffoldBase
|
167
|
+
controller_class_name
|
168
|
+
else
|
169
|
+
class_name
|
170
|
+
end
|
171
|
+
|
172
|
+
class_collisions "#{options[:prefix]}#{name}#{options[:suffix]}"
|
173
|
+
end
|
174
|
+
end
|
175
|
+
|
176
|
+
def attributes_hash
|
177
|
+
return if attributes_names.empty?
|
178
|
+
|
179
|
+
attributes_names.map do |name|
|
180
|
+
if %w(password password_confirmation).include?(name) && attributes.any?(&:password_digest?)
|
181
|
+
"#{name}: 'secret'"
|
182
|
+
else
|
183
|
+
"#{name}: @#{singular_table_name}.#{name}"
|
184
|
+
end
|
185
|
+
end.sort.join(', ')
|
186
|
+
end
|
187
|
+
|
188
|
+
def attributes_list_with_timestamps
|
189
|
+
attributes_list(attributes_names + %w(created_at updated_at))
|
190
|
+
end
|
191
|
+
|
192
|
+
def attributes_list(attributes = attributes_names)
|
193
|
+
if self.attributes.any? {|attr| attr.name == 'password' && attr.type == :digest}
|
194
|
+
attributes = attributes.reject {|name| %w(password password_confirmation).include? name}
|
195
|
+
end
|
196
|
+
|
197
|
+
attributes.map { |a| ":#{a}"} * ', '
|
198
|
+
end
|
199
|
+
|
200
|
+
end
|
201
|
+
end
|
202
|
+
end
|
data/lib/generators/admin/scaffold_controller/templates/controllers/jbuilder/controller.rb.erb
ADDED
@@ -0,0 +1,85 @@
|
|
1
|
+
<% if namespaced? -%>
|
2
|
+
require_dependency "<%= namespaced_file_path %>/application_controller"
|
3
|
+
|
4
|
+
<% end -%>
|
5
|
+
<% module_namespacing do -%>
|
6
|
+
class <%= prefixed_controller_class_name %>Controller < <%= parent_controller_class_name %>Controller
|
7
|
+
before_action :set_<%= singular_table_name %>, only: [:show, :edit, :update, :destroy]
|
8
|
+
|
9
|
+
# GET <%= prefixed_route_url %>
|
10
|
+
# GET <%= prefixed_route_url %>.json
|
11
|
+
def index
|
12
|
+
@q = <%= orm_class.all(class_name) %>.ransack(params[:q])
|
13
|
+
@<%= plural_table_name %> = @q.result(distinct: true).page(params[:page])
|
14
|
+
end
|
15
|
+
|
16
|
+
# GET <%= prefixed_route_url %>/1
|
17
|
+
# GET <%= prefixed_route_url %>/1.json
|
18
|
+
def show
|
19
|
+
end
|
20
|
+
|
21
|
+
# GET <%= prefixed_route_url %>/new
|
22
|
+
def new
|
23
|
+
@<%= singular_table_name %> = <%= orm_class.build(class_name) %>
|
24
|
+
end
|
25
|
+
|
26
|
+
# GET <%= prefixed_route_url %>/1/edit
|
27
|
+
def edit
|
28
|
+
end
|
29
|
+
|
30
|
+
# POST <%= prefixed_route_url %>
|
31
|
+
# POST <%= prefixed_route_url %>.json
|
32
|
+
def create
|
33
|
+
@<%= singular_table_name %> = <%= orm_class.build(class_name, "#{singular_table_name}_params") %>
|
34
|
+
|
35
|
+
respond_to do |format|
|
36
|
+
if @<%= orm_instance.save %>
|
37
|
+
format.html { redirect_to <%= "[:#{prefix}, @#{singular_table_name}]" %>, notice: <%= "'#{human_name} was successfully created.'" %> }
|
38
|
+
format.json { render action: 'show', status: :created, location: <%= "@#{singular_table_name}" %> }
|
39
|
+
else
|
40
|
+
format.html { render action: 'new' }
|
41
|
+
format.json { render json: <%= "@#{orm_instance.errors}" %>, status: :unprocessable_entity }
|
42
|
+
end
|
43
|
+
end
|
44
|
+
end
|
45
|
+
|
46
|
+
# PATCH/PUT <%= prefixed_route_url %>/1
|
47
|
+
# PATCH/PUT <%= prefixed_route_url %>/1.json
|
48
|
+
def update
|
49
|
+
respond_to do |format|
|
50
|
+
if @<%= orm_instance.update("#{singular_table_name}_params") %>
|
51
|
+
format.html { redirect_to <%= "[:#{prefix}, @#{singular_table_name}]" %>, notice: <%= "'#{human_name} was successfully updated.'" %> }
|
52
|
+
format.json { head :no_content }
|
53
|
+
else
|
54
|
+
format.html { render action: 'edit' }
|
55
|
+
format.json { render json: <%= "@#{orm_instance.errors}" %>, status: :unprocessable_entity }
|
56
|
+
end
|
57
|
+
end
|
58
|
+
end
|
59
|
+
|
60
|
+
# DELETE <%= prefixed_route_url %>/1
|
61
|
+
# DELETE <%= prefixed_route_url %>/1.json
|
62
|
+
def destroy
|
63
|
+
@<%= orm_instance.destroy %>
|
64
|
+
respond_to do |format|
|
65
|
+
format.html { redirect_to <%= prefixed_index_helper %>_url, notice: <%= "'#{human_name} was successfully destroyed.'" %> }
|
66
|
+
format.json { head :no_content }
|
67
|
+
end
|
68
|
+
end
|
69
|
+
|
70
|
+
private
|
71
|
+
# Use callbacks to share common setup or constraints between actions.
|
72
|
+
def set_<%= singular_table_name %>
|
73
|
+
@<%= singular_table_name %> = <%= orm_class.find(class_name, "params[:id]") %>
|
74
|
+
end
|
75
|
+
|
76
|
+
# Never trust parameters from the scary internet, only allow the white list through.
|
77
|
+
def <%= "#{singular_table_name}_params" %>
|
78
|
+
<%- if attributes_names.empty? -%>
|
79
|
+
params[<%= ":#{singular_table_name}" %>]
|
80
|
+
<%- else -%>
|
81
|
+
params.require(<%= ":#{singular_table_name}" %>).permit(<%= attributes_names.map { |name| ":#{name}" }.join(', ') %>)
|
82
|
+
<%- end -%>
|
83
|
+
end
|
84
|
+
end
|
85
|
+
<% end -%>
|
data/lib/generators/admin/scaffold_controller/templates/controllers/railties/controller.rb.erb
ADDED
@@ -0,0 +1,68 @@
|
|
1
|
+
<% if namespaced? -%>
|
2
|
+
require_dependency "<%= namespaced_file_path %>/application_controller"
|
3
|
+
|
4
|
+
<% end -%>
|
5
|
+
<% module_namespacing do -%>
|
6
|
+
class <%= prefixed_controller_class_name %>Controller < <%= parent_controller_class_name %>Controller
|
7
|
+
before_action :set_<%= singular_table_name %>, only: [:show, :edit, :update, :destroy]
|
8
|
+
|
9
|
+
# GET <%= prefixed_route_url %>
|
10
|
+
def index
|
11
|
+
@<%= plural_table_name %> = <%= orm_class.all(class_name) %>
|
12
|
+
end
|
13
|
+
|
14
|
+
# GET <%= prefixed_route_url %>/1
|
15
|
+
def show
|
16
|
+
end
|
17
|
+
|
18
|
+
# GET <%= prefixed_route_url %>/new
|
19
|
+
def new
|
20
|
+
@<%= singular_table_name %> = <%= orm_class.build(class_name) %>
|
21
|
+
end
|
22
|
+
|
23
|
+
# GET <%= prefixed_route_url %>/1/edit
|
24
|
+
def edit
|
25
|
+
end
|
26
|
+
|
27
|
+
# POST <%= prefixed_route_url %>
|
28
|
+
def create
|
29
|
+
@<%= singular_table_name %> = <%= orm_class.build(class_name, "#{singular_table_name}_params") %>
|
30
|
+
|
31
|
+
if @<%= orm_instance.save %>
|
32
|
+
redirect_to <%= "[:#{prefix}, @#{singular_table_name}]" %>, notice: <%= "'#{human_name} was successfully created.'" %>
|
33
|
+
else
|
34
|
+
render action: 'new'
|
35
|
+
end
|
36
|
+
end
|
37
|
+
|
38
|
+
# PATCH/PUT <%= prefixed_route_url %>/1
|
39
|
+
def update
|
40
|
+
if @<%= orm_instance.update("#{singular_table_name}_params") %>
|
41
|
+
redirect_to <%= "[:#{prefix}, @#{singular_table_name}]" %>, notice: <%= "'#{human_name} was successfully updated.'" %>
|
42
|
+
else
|
43
|
+
render action: 'edit'
|
44
|
+
end
|
45
|
+
end
|
46
|
+
|
47
|
+
# DELETE <%= prefixed_route_url %>/1
|
48
|
+
def destroy
|
49
|
+
@<%= orm_instance.destroy %>
|
50
|
+
redirect_to <%= prefixed_index_helper %>_url, notice: <%= "'#{human_name} was successfully destroyed.'" %>
|
51
|
+
end
|
52
|
+
|
53
|
+
private
|
54
|
+
# Use callbacks to share common setup or constraints between actions.
|
55
|
+
def set_<%= singular_table_name %>
|
56
|
+
@<%= singular_table_name %> = <%= orm_class.find(class_name, "params[:id]") %>
|
57
|
+
end
|
58
|
+
|
59
|
+
# Only allow a trusted parameter "white list" through.
|
60
|
+
def <%= "#{singular_table_name}_params" %>
|
61
|
+
<%- if attributes_names.empty? -%>
|
62
|
+
params[<%= ":#{singular_table_name}" %>]
|
63
|
+
<%- else -%>
|
64
|
+
params.require(<%= ":#{singular_table_name}" %>).permit(<%= attributes_names.map { |name| ":#{name}" }.join(', ') %>)
|
65
|
+
<%- end -%>
|
66
|
+
end
|
67
|
+
end
|
68
|
+
<% end -%>
|
@@ -0,0 +1,51 @@
|
|
1
|
+
<!DOCTYPE html>
|
2
|
+
<html>
|
3
|
+
<head>
|
4
|
+
<title><%= File.basename(Rails.root.to_s)%></title>
|
5
|
+
<link href='https://fonts.googleapis.com/css?family=Roboto+Mono:400,100,100italic,300,300italic,500,400italic,700,500italic,700italic' rel='stylesheet' type='text/css'> <link href='https://fonts.googleapis.com/css?family=Cousine:400,400italic,700,700italic' rel='stylesheet' type='text/css'>
|
6
|
+
<link href="http://fonts.googleapis.com/icon?family=Material+Icons" rel="stylesheet">
|
7
|
+
<%%= stylesheet_link_tag '<%= file_name %>', media: 'all', 'data-turbolinks-track' => true %>
|
8
|
+
<%%= csrf_meta_tags %>
|
9
|
+
<meta name="viewport" content="width=device-width, initial-scale=1.0"/>
|
10
|
+
</head>
|
11
|
+
|
12
|
+
<body>
|
13
|
+
|
14
|
+
<nav>
|
15
|
+
<div class="container">
|
16
|
+
<ul id="slide-out" class="side-nav">
|
17
|
+
<%% Dir[Rails.root.join('app/controllers/#{file_name}/*_controller.rb')].map { |path| (path.match(/(\w+)_controller.rb/); $1) }.each do |a|%>
|
18
|
+
<li><a href="/#{file_name}/<%%= a %>"><%%= a.gsub("_"," ") %></a></li>
|
19
|
+
<%% end %>
|
20
|
+
</ul>
|
21
|
+
<a href="#" data-activates="slide-out" class="button-collapse show-on-large"><i class="mdi-navigation-menu"></i></a>
|
22
|
+
</div>
|
23
|
+
|
24
|
+
</nav>
|
25
|
+
|
26
|
+
<main>
|
27
|
+
<div id="admin_content" class="container">
|
28
|
+
|
29
|
+
<%%= yield %>
|
30
|
+
</div>
|
31
|
+
</main>
|
32
|
+
<footer class="page-footer">
|
33
|
+
<div class="container">
|
34
|
+
<div class="row">
|
35
|
+
<div class="col l6 s12">
|
36
|
+
<h5 class="white-text">Belligerent Eyes Admin</h5>
|
37
|
+
<p class="grey-text text-lighten-4">Hail to the censor!</p>
|
38
|
+
</div>
|
39
|
+
</div>
|
40
|
+
</div>
|
41
|
+
<div class="footer-copyright">
|
42
|
+
<div class="container">
|
43
|
+
© 2016 Crafted by display.xxx
|
44
|
+
<a class="grey-text text-lighten-4 right" href="#!">FYA</a>
|
45
|
+
</div>
|
46
|
+
</div>
|
47
|
+
</footer>
|
48
|
+
|
49
|
+
</body>
|
50
|
+
<%%= javascript_include_tag 'admin' %>
|
51
|
+
</html>
|
data/lib/generators/admin/scaffold_controller/templates/tests/test_unit/functional_test.rb.erb
ADDED
@@ -0,0 +1,51 @@
|
|
1
|
+
require 'test_helper'
|
2
|
+
|
3
|
+
<% module_namespacing do -%>
|
4
|
+
class <%= prefixed_controller_class_name %>ControllerTest < ActionController::TestCase
|
5
|
+
setup do
|
6
|
+
@<%= singular_table_name %> = <%= table_name %>(:one)
|
7
|
+
end
|
8
|
+
|
9
|
+
test "should get index" do
|
10
|
+
get :index
|
11
|
+
assert_response :success
|
12
|
+
assert_not_nil assigns(:<%= table_name %>)
|
13
|
+
end
|
14
|
+
|
15
|
+
test "should get new" do
|
16
|
+
get :new
|
17
|
+
assert_response :success
|
18
|
+
end
|
19
|
+
|
20
|
+
test "should create <%= singular_table_name %>" do
|
21
|
+
assert_difference('<%= class_name %>.count') do
|
22
|
+
post :create, <%= "#{singular_table_name}: { #{attributes_hash} }" %>
|
23
|
+
end
|
24
|
+
|
25
|
+
assert_redirected_to <%= prefixed_plain_model_url %>_path(assigns(:<%= singular_table_name %>))
|
26
|
+
end
|
27
|
+
|
28
|
+
test "should show <%= singular_table_name %>" do
|
29
|
+
get :show, id: <%= "@#{singular_table_name}" %>
|
30
|
+
assert_response :success
|
31
|
+
end
|
32
|
+
|
33
|
+
test "should get edit" do
|
34
|
+
get :edit, id: <%= "@#{singular_table_name}" %>
|
35
|
+
assert_response :success
|
36
|
+
end
|
37
|
+
|
38
|
+
test "should update <%= singular_table_name %>" do
|
39
|
+
patch :update, id: <%= "@#{singular_table_name}" %>, <%= "#{singular_table_name}: { #{attributes_hash} }" %>
|
40
|
+
assert_redirected_to <%= prefixed_plain_model_url %>_path(assigns(:<%= singular_table_name %>))
|
41
|
+
end
|
42
|
+
|
43
|
+
test "should destroy <%= singular_table_name %>" do
|
44
|
+
assert_difference('<%= class_name %>.count', -1) do
|
45
|
+
delete :destroy, id: <%= "@#{singular_table_name}" %>
|
46
|
+
end
|
47
|
+
|
48
|
+
assert_redirected_to <%= prefixed_index_helper %>_path
|
49
|
+
end
|
50
|
+
end
|
51
|
+
<% end -%>
|
@@ -0,0 +1,32 @@
|
|
1
|
+
<%%= simple_form_for(<%= "[:#{prefix}, @#{singular_table_name}]" %>) do |f| %>
|
2
|
+
<% attributes.each do |attribute| -%>
|
3
|
+
<div class="row">
|
4
|
+
<div class="col s12">
|
5
|
+
<%= if attribute.field_type == 'date' %>
|
6
|
+
<%%= f.input :<%= attribute.name %>, as: :string, input_html: { class: 'datepicker' } %>
|
7
|
+
<%= elsif attribute.else_if == 'text' %>
|
8
|
+
<%%= f.input :<%= attribute.name %>, as: :string, input_html: { class: 'materialize-textarea' } %>
|
9
|
+
<%= elsif singular_table_name.camelize.contantize.uploaders.keys.include?(attribute.name.to_sym) %>
|
10
|
+
<div class="image_preview">
|
11
|
+
<%%= image_tag @<%=singular_table_name%>.<%=attribute%>.url, class: 'admin--thumb' %>
|
12
|
+
<%%= f.input :remove_image, as: :boolean %>
|
13
|
+
</div>
|
14
|
+
<div class="file-field input-field">
|
15
|
+
<div class="btn">
|
16
|
+
<span>Image</span>
|
17
|
+
<%%= f.input :<%= attribute.name %>, label: false, wrapper: false %>
|
18
|
+
</div>
|
19
|
+
<div class="file-path-wrapper">
|
20
|
+
<input class="file-path validate" type="text" placeholder="Upload a file">
|
21
|
+
</div>
|
22
|
+
</div>
|
23
|
+
<% else %>
|
24
|
+
<%%= f.input :<%= attribute.name %> %>
|
25
|
+
|
26
|
+
<% end %>
|
27
|
+
</div>
|
28
|
+
</div>
|
29
|
+
<div class="actions">
|
30
|
+
<%%= f.button :submit %>
|
31
|
+
</div>
|
32
|
+
<%% end %>
|
@@ -0,0 +1,53 @@
|
|
1
|
+
<a class="btn-floating btn-large waves-effect waves-light red" href="<%%= new_admin_<%=singular_table_name%>_path %>" style="float:right;"><i class="material-icons">add</i></a>
|
2
|
+
|
3
|
+
<h2><%= plural_table_name.titleize %></h2>
|
4
|
+
|
5
|
+
<!-- filtering section - to be created customizing index -->
|
6
|
+
<%%= search_form_for @q, url: admin_<%=plural_table_name%>_path do |f| %>
|
7
|
+
<div class="row">
|
8
|
+
<div class="col s3 input-field">
|
9
|
+
<%%= f.label <%= ":id_cont" %> %>
|
10
|
+
<%%= f.search_field <%= ":id_cont" %> %>
|
11
|
+
</div>
|
12
|
+
</div>
|
13
|
+
<div class="row">
|
14
|
+
<div class="col">
|
15
|
+
<%%= f.submit class: 'btn waves-effect waves-light' %>
|
16
|
+
<%% if params[:q].present? %>
|
17
|
+
<a href="<%%= admin_<%=plural_table_name %>_path %>" class="btn waves-effect waves-light purple darken-4">RESET</a>
|
18
|
+
<%% end %>
|
19
|
+
</div>
|
20
|
+
</div>
|
21
|
+
<%% end %>
|
22
|
+
|
23
|
+
|
24
|
+
|
25
|
+
<table>
|
26
|
+
<thead>
|
27
|
+
<tr>
|
28
|
+
<% attributes.each do |attribute| -%>
|
29
|
+
<th><%= attribute.human_name %></th>
|
30
|
+
<% end -%>
|
31
|
+
<th></th>
|
32
|
+
<th></th>
|
33
|
+
<th></th>
|
34
|
+
</tr>
|
35
|
+
</thead>
|
36
|
+
|
37
|
+
<tbody>
|
38
|
+
<%% @<%= plural_table_name %>.each do |<%= singular_table_name %>| %>
|
39
|
+
<tr>
|
40
|
+
<% attributes.each do |attribute| -%>
|
41
|
+
<td><%%= <%= singular_table_name %>.<%= attribute.name %> %></td>
|
42
|
+
<% end -%>
|
43
|
+
<td><%%= link_to 'Show', <%= "[:#{prefix}, #{singular_table_name}]" %> %></td>
|
44
|
+
<td><%%= link_to 'Edit', edit_<%= prefixed_plain_model_url %>_path(<%= singular_table_name %>) %></td>
|
45
|
+
<td><%%= link_to 'Destroy', <%= "[:#{prefix}, #{singular_table_name}]" %>, method: :delete, data: { confirm: 'Are you sure?' } %></td>
|
46
|
+
</tr>
|
47
|
+
<%% end %>
|
48
|
+
</tbody>
|
49
|
+
</table>
|
50
|
+
|
51
|
+
<br>
|
52
|
+
|
53
|
+
<%%= link_to 'New <%= human_name %>', new_<%= prefixed_plain_model_url %>_path %>
|
@@ -0,0 +1,11 @@
|
|
1
|
+
<p id="notice"><%%= notice %></p>
|
2
|
+
|
3
|
+
<% attributes.reject(&:password_digest?).each do |attribute| -%>
|
4
|
+
<p>
|
5
|
+
<strong><%= attribute.human_name %>:</strong>
|
6
|
+
<%%= @<%= singular_table_name %>.<%= attribute.name %> %>
|
7
|
+
</p>
|
8
|
+
|
9
|
+
<% end -%>
|
10
|
+
<%%= link_to 'Edit', edit_<%= prefixed_plain_model_url %>_path(@<%= singular_table_name %>) %> |
|
11
|
+
<%%= link_to 'Back', <%= prefixed_index_helper %>_path %>
|
@@ -0,0 +1 @@
|
|
1
|
+
json.extract! @<%= singular_table_name %>, <%= attributes_list_with_timestamps %>
|