zscaffold_admin 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/MIT-LICENSE +20 -0
- data/README.rdoc +18 -0
- data/Rakefile +31 -0
- data/lib/generators/scaffold_admin/USAGE +8 -0
- data/lib/generators/scaffold_admin/install_generator.rb +50 -0
- data/lib/generators/scaffold_admin/scaffold_admin_generator.rb +109 -0
- data/lib/generators/scaffold_admin/templates/controller.rb +65 -0
- data/lib/generators/scaffold_admin/templates/helper.rb +9 -0
- data/lib/generators/scaffold_admin/templates/images/breadcrumb_divider.png +0 -0
- data/lib/generators/scaffold_admin/templates/images/btn_submit.png +0 -0
- data/lib/generators/scaffold_admin/templates/images/btn_submit_2.png +0 -0
- data/lib/generators/scaffold_admin/templates/images/btn_view_site.png +0 -0
- data/lib/generators/scaffold_admin/templates/images/header_bg.png +0 -0
- data/lib/generators/scaffold_admin/templates/images/header_shadow.png +0 -0
- data/lib/generators/scaffold_admin/templates/images/icn_add_user.png +0 -0
- data/lib/generators/scaffold_admin/templates/images/icn_alert_error.png +0 -0
- data/lib/generators/scaffold_admin/templates/images/icn_alert_info.png +0 -0
- data/lib/generators/scaffold_admin/templates/images/icn_alert_success.png +0 -0
- data/lib/generators/scaffold_admin/templates/images/icn_alert_warning.png +0 -0
- data/lib/generators/scaffold_admin/templates/images/icn_audio.png +0 -0
- data/lib/generators/scaffold_admin/templates/images/icn_categories.png +0 -0
- data/lib/generators/scaffold_admin/templates/images/icn_edit.png +0 -0
- data/lib/generators/scaffold_admin/templates/images/icn_edit_article.png +0 -0
- data/lib/generators/scaffold_admin/templates/images/icn_folder.png +0 -0
- data/lib/generators/scaffold_admin/templates/images/icn_jump_back.png +0 -0
- data/lib/generators/scaffold_admin/templates/images/icn_logout.png +0 -0
- data/lib/generators/scaffold_admin/templates/images/icn_new_article.png +0 -0
- data/lib/generators/scaffold_admin/templates/images/icn_photo.png +0 -0
- data/lib/generators/scaffold_admin/templates/images/icn_profile.png +0 -0
- data/lib/generators/scaffold_admin/templates/images/icn_search.png +0 -0
- data/lib/generators/scaffold_admin/templates/images/icn_security.png +0 -0
- data/lib/generators/scaffold_admin/templates/images/icn_settings.png +0 -0
- data/lib/generators/scaffold_admin/templates/images/icn_tags.png +0 -0
- data/lib/generators/scaffold_admin/templates/images/icn_trash.png +0 -0
- data/lib/generators/scaffold_admin/templates/images/icn_user.png +0 -0
- data/lib/generators/scaffold_admin/templates/images/icn_video.png +0 -0
- data/lib/generators/scaffold_admin/templates/images/icn_view_users.png +0 -0
- data/lib/generators/scaffold_admin/templates/images/module_footer_bg.png +0 -0
- data/lib/generators/scaffold_admin/templates/images/post_message.png +0 -0
- data/lib/generators/scaffold_admin/templates/images/secondary_bar.png +0 -0
- data/lib/generators/scaffold_admin/templates/images/secondary_bar_shadow.png +0 -0
- data/lib/generators/scaffold_admin/templates/images/sidebar.png +0 -0
- data/lib/generators/scaffold_admin/templates/images/sidebar_divider.png +0 -0
- data/lib/generators/scaffold_admin/templates/images/sidebar_shadow.png +0 -0
- data/lib/generators/scaffold_admin/templates/images/table_sorter_header.png +0 -0
- data/lib/generators/scaffold_admin/templates/javascripts/hideshow.js +69 -0
- data/lib/generators/scaffold_admin/templates/javascripts/jquery-1.5.2.min.js +16 -0
- data/lib/generators/scaffold_admin/templates/javascripts/jquery.equalHeight.js +20 -0
- data/lib/generators/scaffold_admin/templates/javascripts/jquery.tablesorter.min.js +4 -0
- data/lib/generators/scaffold_admin/templates/layouts/admin.html.erb +65 -0
- data/lib/generators/scaffold_admin/templates/migration.rb +11 -0
- data/lib/generators/scaffold_admin/templates/model.rb +9 -0
- data/lib/generators/scaffold_admin/templates/shared/_menu.html.erb +26 -0
- data/lib/generators/scaffold_admin/templates/stylesheets/ie.css +43 -0
- data/lib/generators/scaffold_admin/templates/stylesheets/layout.css +883 -0
- data/lib/generators/scaffold_admin/templates/views/_form.html.erb +32 -0
- data/lib/generators/scaffold_admin/templates/views/edit.html.erb +6 -0
- data/lib/generators/scaffold_admin/templates/views/index.html.erb +40 -0
- data/lib/generators/scaffold_admin/templates/views/new.html.erb +6 -0
- data/lib/generators/scaffold_admin/templates/views/show.html.erb +22 -0
- data/lib/tasks/zscaffold_admin_tasks.rake +4 -0
- data/lib/zscaffold_admin/engine.rb +5 -0
- data/lib/zscaffold_admin.rb +4 -0
- metadata +126 -0
data/MIT-LICENSE
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
Copyright 2011 YOURNAME
|
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
@@ -0,0 +1,18 @@
|
|
1
|
+
= ZscaffoldAdmin
|
2
|
+
|
3
|
+
Use Rails 3.1.0.rc4(brach => 3-1-stable)
|
4
|
+
|
5
|
+
It is a scaffold with configurable layout. Can be used in applications and other Engines.
|
6
|
+
|
7
|
+
Install the gem in your Gemfile.
|
8
|
+
|
9
|
+
Install files for configuration.
|
10
|
+
rails g scaffold_admin:install
|
11
|
+
|
12
|
+
Then just generate the scaffold.
|
13
|
+
rails g scaffold_admin post name:string title:string enabled:boolean
|
14
|
+
|
15
|
+
Option with namespace.
|
16
|
+
rails g scaffold_admin blog/post name:string title:string enabled:boolean
|
17
|
+
|
18
|
+
This project rocks and uses MIT-LICENSE.
|
data/Rakefile
ADDED
@@ -0,0 +1,31 @@
|
|
1
|
+
#!/usr/bin/env rake
|
2
|
+
begin
|
3
|
+
require 'bundler/setup'
|
4
|
+
rescue LoadError
|
5
|
+
puts 'You must `gem install bundler` and `bundle install` to run rake tasks'
|
6
|
+
end
|
7
|
+
|
8
|
+
require 'rake/rdoctask'
|
9
|
+
|
10
|
+
Rake::RDocTask.new(:rdoc) do |rdoc|
|
11
|
+
rdoc.rdoc_dir = 'rdoc'
|
12
|
+
rdoc.title = 'ZscaffoldAdmin'
|
13
|
+
rdoc.options << '--line-numbers' << '--inline-source'
|
14
|
+
rdoc.rdoc_files.include('README.rdoc')
|
15
|
+
rdoc.rdoc_files.include('lib/**/*.rb')
|
16
|
+
end
|
17
|
+
|
18
|
+
APP_RAKEFILE = File.expand_path("../test/dummy/Rakefile", __FILE__)
|
19
|
+
load 'rails/tasks/engine.rake'
|
20
|
+
|
21
|
+
require 'rake/testtask'
|
22
|
+
|
23
|
+
Rake::TestTask.new(:test) do |t|
|
24
|
+
t.libs << 'lib'
|
25
|
+
t.libs << 'test'
|
26
|
+
t.pattern = 'test/**/*_test.rb'
|
27
|
+
t.verbose = false
|
28
|
+
end
|
29
|
+
|
30
|
+
|
31
|
+
task :default => :test
|
@@ -0,0 +1,50 @@
|
|
1
|
+
module ScaffoldAdmin
|
2
|
+
class InstallGenerator < Rails::Generators::Base
|
3
|
+
desc 'Copy files for configuration ZScaffold Admin'
|
4
|
+
|
5
|
+
def self.source_root
|
6
|
+
@_install_source_root ||= File.expand_path("../templates", __FILE__)
|
7
|
+
end
|
8
|
+
|
9
|
+
def copy_files
|
10
|
+
array_classes.each do |klass|
|
11
|
+
copy_file "#{klass}.rb", "lib/templates/#{klass}.rb"
|
12
|
+
end
|
13
|
+
|
14
|
+
array_views.each do |view|
|
15
|
+
copy_file "views/#{view}.html.erb", "lib/templates/views/#{view}.html.erb"
|
16
|
+
end
|
17
|
+
|
18
|
+
copy_file "shared/_menu.html.erb", "app/views/shared/_menu.html.erb"
|
19
|
+
copy_file "layouts/admin.html.erb", "app/views/layouts/admin.html.erb"
|
20
|
+
copy_file "stylesheets/ie.css", "app/assets/stylesheets/ie.css"
|
21
|
+
copy_file "stylesheets/layout.css", "app/assets/stylesheets/layout.css"
|
22
|
+
|
23
|
+
array_javascripts.each do |js|
|
24
|
+
copy_file "javascripts/#{js}.js", "app/assets/javascripts/#{js}.js"
|
25
|
+
end
|
26
|
+
|
27
|
+
array_images.each do |images|
|
28
|
+
copy_file "images/#{images}.png", "app/assets/images/#{images}.png"
|
29
|
+
end
|
30
|
+
|
31
|
+
end
|
32
|
+
|
33
|
+
def array_classes
|
34
|
+
%w[controller helper model migration]
|
35
|
+
end
|
36
|
+
|
37
|
+
def array_views
|
38
|
+
%w[edit _form index new show]
|
39
|
+
end
|
40
|
+
|
41
|
+
def array_javascripts
|
42
|
+
%w[hideshow jquery.equalHeight jquery.tablesorter.min jquery-1.5.2.min]
|
43
|
+
end
|
44
|
+
|
45
|
+
def array_images
|
46
|
+
%w[breadcrumb_divider btn_submit btn_submit_2 btn_view_site header_bg header_shadow icn_add_user icn_alert_error icn_alert_info icn_alert_success icn_alert_warning icn_audio icn_categories icn_edit icn_edit_article icn_folder icn_jump_back icn_logout icn_new_article icn_photo icn_profile icn_search icn_security icn_settings icn_tags icn_trash icn_user icn_video icn_view_users module_footer_bg post_message secondary_bar secondary_bar_shadow sidebar sidebar_divider sidebar_shadow table_sorter_header]
|
47
|
+
end
|
48
|
+
|
49
|
+
end
|
50
|
+
end
|
@@ -0,0 +1,109 @@
|
|
1
|
+
require 'rails/generators/migration'
|
2
|
+
require 'rails/generators/generated_attribute'
|
3
|
+
|
4
|
+
class ScaffoldAdminGenerator < Rails::Generators::Base
|
5
|
+
include Rails::Generators::Migration
|
6
|
+
source_root File.expand_path("#{Rails.root}/lib/templates", __FILE__)
|
7
|
+
|
8
|
+
no_tasks { attr_accessor :scaffold_name, :model_attributes }
|
9
|
+
|
10
|
+
argument :scaffold_name, :type => :string, :required => true, :banner => 'Namespace/ModelName'
|
11
|
+
argument :attributes, :type => :array, :default => [], :banner => 'field_name:type'
|
12
|
+
|
13
|
+
def create_templates
|
14
|
+
args_attributes
|
15
|
+
|
16
|
+
if namespace_name
|
17
|
+
template "model.rb", "app/models/#{namespace_underscore}/#{singular_name}.rb"
|
18
|
+
template "controller.rb", "app/controllers/#{namespace_underscore}/#{plural_name}_controller.rb"
|
19
|
+
template "helper.rb", "app/helpers/#{namespace_underscore}/#{plural_name}_helper.rb"
|
20
|
+
|
21
|
+
%w[index show edit new].each do |view|
|
22
|
+
template "views/#{view}.html.erb", "app/views/#{namespace_underscore}/#{plural_name}/#{view}.html.erb"
|
23
|
+
end
|
24
|
+
|
25
|
+
template "views/_form.html.erb", "app/views/#{namespace_underscore}/#{plural_name}/_form.html.erb"
|
26
|
+
|
27
|
+
else
|
28
|
+
template "model.rb", "app/models/#{singular_name}.rb"
|
29
|
+
template "controller.rb", "app/controllers/#{plural_name}_controller.rb"
|
30
|
+
template "helper.rb", "app/helpers/#{plural_name}_helper.rb"
|
31
|
+
|
32
|
+
%w[index show edit new].each do |view|
|
33
|
+
template "views/#{view}.html.erb", "app/views/#{plural_name}/#{view}.html.erb"
|
34
|
+
end
|
35
|
+
|
36
|
+
template "views/_form.html.erb", "app/views/#{namespace_underscore}/#{plural_name}/_form.html.erb"
|
37
|
+
|
38
|
+
end
|
39
|
+
|
40
|
+
route "resources :#{plural_name}"
|
41
|
+
end
|
42
|
+
|
43
|
+
def create_migration
|
44
|
+
migration_number = Time.now.strftime('%Y%m%d%H%M%S')
|
45
|
+
if namespace_name
|
46
|
+
template 'migration.rb', "db/migrate/#{migration_number}_create_#{namespace_underscore}_#{plural_name}.rb"
|
47
|
+
else
|
48
|
+
template 'migration.rb', "db/migrate/#{migration_number}_create_#{plural_name}.rb"
|
49
|
+
end
|
50
|
+
end
|
51
|
+
|
52
|
+
def split_scaffold_name
|
53
|
+
path = {}
|
54
|
+
namespace = scaffold_name.split('/')
|
55
|
+
path[:model_name] = namespace.pop
|
56
|
+
path[:namespace] = namespace.pop
|
57
|
+
path
|
58
|
+
end
|
59
|
+
|
60
|
+
def args_attributes
|
61
|
+
@model_attributes = []
|
62
|
+
|
63
|
+
attributes.each do |arg|
|
64
|
+
if arg.include?(':')
|
65
|
+
@model_attributes << Rails::Generators::GeneratedAttribute.new(*arg.split(':'))
|
66
|
+
end
|
67
|
+
end
|
68
|
+
|
69
|
+
@model_attributes.uniq!
|
70
|
+
|
71
|
+
end
|
72
|
+
|
73
|
+
def model_name
|
74
|
+
split_scaffold_name[:model_name]
|
75
|
+
end
|
76
|
+
|
77
|
+
def namespace_name
|
78
|
+
split_scaffold_name[:namespace]
|
79
|
+
end
|
80
|
+
|
81
|
+
def singular_name
|
82
|
+
model_name.underscore
|
83
|
+
end
|
84
|
+
|
85
|
+
def class_name
|
86
|
+
model_name.titlecase.gsub(/[\-\/" "]/, "")
|
87
|
+
end
|
88
|
+
|
89
|
+
def plural_name
|
90
|
+
model_name.underscore.pluralize
|
91
|
+
end
|
92
|
+
|
93
|
+
def plural_class
|
94
|
+
class_name.pluralize
|
95
|
+
end
|
96
|
+
|
97
|
+
def module_name
|
98
|
+
unless namespace_name.nil?
|
99
|
+
namespace_name.titlecase.gsub(/[\-\/" "]/, "")
|
100
|
+
end
|
101
|
+
end
|
102
|
+
|
103
|
+
def namespace_underscore
|
104
|
+
unless namespace_name.nil?
|
105
|
+
namespace_name.underscore
|
106
|
+
end
|
107
|
+
end
|
108
|
+
|
109
|
+
end
|
@@ -0,0 +1,65 @@
|
|
1
|
+
<%- if namespace_name -%>
|
2
|
+
module <%= module_name %>
|
3
|
+
<%- end -%>
|
4
|
+
class <%= plural_class %>Controller < ApplicationController
|
5
|
+
layout 'admin'
|
6
|
+
respond_to :html, :xml, :js
|
7
|
+
|
8
|
+
def index
|
9
|
+
@<%= plural_name %> = <%= class_name %>.order 'created_at DESC'
|
10
|
+
|
11
|
+
respond_with @<%= plural_name %>
|
12
|
+
end
|
13
|
+
|
14
|
+
def show
|
15
|
+
@<%= singular_name %> = <%= class_name %>.find params[:id]
|
16
|
+
|
17
|
+
respond_with @<%= singular_name %>
|
18
|
+
end
|
19
|
+
|
20
|
+
def new
|
21
|
+
@<%= singular_name %> = <%= class_name %>.new
|
22
|
+
|
23
|
+
respond_with @<%= singular_name %>
|
24
|
+
end
|
25
|
+
|
26
|
+
def edit
|
27
|
+
@<%= singular_name %> = <%= class_name %>.find params[:id]
|
28
|
+
respond_with @<%= singular_name %>
|
29
|
+
end
|
30
|
+
|
31
|
+
def create
|
32
|
+
@<%= singular_name %> = <%= class_name %>.new params[:post]
|
33
|
+
|
34
|
+
if @<%= singular_name %>.save
|
35
|
+
flash[:notice] = I18n.t :<%= singular_name %>_created
|
36
|
+
respond_with @<%= singular_name %>
|
37
|
+
else
|
38
|
+
flash[:alert] = I18n.t :<%= singular_name %>_not_created
|
39
|
+
render :action => :new
|
40
|
+
end
|
41
|
+
end
|
42
|
+
|
43
|
+
def update
|
44
|
+
@<%= singular_name %> = <%= class_name %>.find params[:id]
|
45
|
+
|
46
|
+
if @<%= singular_name %>.update_attributes params[:post]
|
47
|
+
flash[:notice] = I18n.t :<%= singular_name %>_updated
|
48
|
+
respond_with @<%= singular_name %>
|
49
|
+
else
|
50
|
+
flash[:alert] = I18n.t :<%= singular_name %>_not_updated
|
51
|
+
render :action => :edit
|
52
|
+
end
|
53
|
+
end
|
54
|
+
|
55
|
+
def destroy
|
56
|
+
@<%= singular_name %> = <%= class_name %>.find params[:id]
|
57
|
+
@<%= singular_name %>.destroy
|
58
|
+
|
59
|
+
respond_with @<%= singular_name %>
|
60
|
+
end
|
61
|
+
|
62
|
+
end
|
63
|
+
<%- if namespace_name -%>
|
64
|
+
end
|
65
|
+
<%- end -%>
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|
@@ -0,0 +1,69 @@
|
|
1
|
+
// Andy Langton's show/hide/mini-accordion @ http://andylangton.co.uk/jquery-show-hide
|
2
|
+
|
3
|
+
// this tells jquery to run the function below once the DOM is ready
|
4
|
+
$(document).ready(function() {
|
5
|
+
|
6
|
+
// choose text for the show/hide link - can contain HTML (e.g. an image)
|
7
|
+
var showText='Show';
|
8
|
+
var hideText='Hide';
|
9
|
+
|
10
|
+
// initialise the visibility check
|
11
|
+
var is_visible = false;
|
12
|
+
|
13
|
+
// append show/hide links to the element directly preceding the element with a class of "toggle"
|
14
|
+
$('.toggle').prev().append(' <a href="#" class="toggleLink">'+showText+'</a>');
|
15
|
+
// hide all of the elements with a class of 'toggle'
|
16
|
+
$('.toggle').hide();
|
17
|
+
|
18
|
+
// capture clicks on the toggle links
|
19
|
+
$('a.toggleLink').click(function() {
|
20
|
+
|
21
|
+
// switch visibility
|
22
|
+
is_visible = !is_visible;
|
23
|
+
|
24
|
+
// change the link text depending on whether the element is shown or hidden
|
25
|
+
if ($(this).text()==showText) {
|
26
|
+
$(this).text(hideText);
|
27
|
+
$(this).parent().next('.toggle').slideDown('slow');
|
28
|
+
}
|
29
|
+
else {
|
30
|
+
$(this).text(showText);
|
31
|
+
$(this).parent().next('.toggle').slideUp('slow');
|
32
|
+
}
|
33
|
+
|
34
|
+
// return false so any link destination is not followed
|
35
|
+
return false;
|
36
|
+
|
37
|
+
});
|
38
|
+
});
|
39
|
+
|
40
|
+
$(function(){
|
41
|
+
$('.column').equalHeight();
|
42
|
+
});
|
43
|
+
|
44
|
+
$(document).ready(function()
|
45
|
+
{
|
46
|
+
$(".tablesorter").tablesorter();
|
47
|
+
}
|
48
|
+
);
|
49
|
+
|
50
|
+
$(document).ready(function() {
|
51
|
+
|
52
|
+
//When page loads...
|
53
|
+
$(".tab_content").hide(); //Hide all content
|
54
|
+
$("ul.tabs li:first").addClass("active").show(); //Activate first tab
|
55
|
+
$(".tab_content:first").show(); //Show first tab content
|
56
|
+
|
57
|
+
//On Click Event
|
58
|
+
$("ul.tabs li").click(function() {
|
59
|
+
|
60
|
+
$("ul.tabs li").removeClass("active"); //Remove any "active" class
|
61
|
+
$(this).addClass("active"); //Add "active" class to selected tab
|
62
|
+
$(".tab_content").hide(); //Hide all tab content
|
63
|
+
|
64
|
+
var activeTab = $(this).find("a").attr("href"); //Find the href attribute value to identify the active tab + content
|
65
|
+
$(activeTab).fadeIn(); //Fade in the active ID content
|
66
|
+
return false;
|
67
|
+
});
|
68
|
+
|
69
|
+
});
|