zscaffold_admin 0.0.1 → 0.0.2
Sign up to get free protection for your applications and to get access to all the features.
- data/README.rdoc +11 -3
- data/lib/generators/scaffold_admin/install_generator.rb +15 -1
- data/lib/generators/scaffold_admin/scaffold_admin_generator.rb +9 -9
- data/lib/generators/scaffold_admin/templates/code_application_helper.rb +5 -0
- data/lib/generators/scaffold_admin/templates/controller.rb +6 -8
- data/lib/generators/scaffold_admin/templates/views/_form.html.erb +1 -1
- data/lib/generators/scaffold_admin/templates/views/index.html.erb +1 -1
- data/lib/generators/scaffold_admin/templates/views/show.html.erb +1 -0
- metadata +4 -3
data/README.rdoc
CHANGED
@@ -5,14 +5,22 @@ Use Rails 3.1.0.rc4(brach => 3-1-stable)
|
|
5
5
|
It is a scaffold with configurable layout. Can be used in applications and other Engines.
|
6
6
|
|
7
7
|
Install the gem in your Gemfile.
|
8
|
-
|
8
|
+
gem 'zscaffold_admin', :git => 'git://github.com/vagnerzampieri/zscaffold_admin.git'
|
9
|
+
|
9
10
|
Install files for configuration.
|
10
11
|
rails g scaffold_admin:install
|
11
12
|
|
12
13
|
Then just generate the scaffold.
|
13
14
|
rails g scaffold_admin post name:string title:string enabled:boolean
|
15
|
+
|
16
|
+
== Bugs:
|
17
|
+
currently has about Engines and namespace are being repaired.
|
18
|
+
|
19
|
+
== Soon it will be done:
|
20
|
+
|
21
|
+
Scaffold with option for Ajax.
|
22
|
+
|
23
|
+
Skips.
|
14
24
|
|
15
|
-
Option with namespace.
|
16
|
-
rails g scaffold_admin blog/post name:string title:string enabled:boolean
|
17
25
|
|
18
26
|
This project rocks and uses MIT-LICENSE.
|
@@ -27,9 +27,23 @@ module ScaffoldAdmin
|
|
27
27
|
array_images.each do |images|
|
28
28
|
copy_file "images/#{images}.png", "app/assets/images/#{images}.png"
|
29
29
|
end
|
30
|
+
end
|
30
31
|
|
32
|
+
def inject_code_helper
|
33
|
+
path = IO.readlines("#{Rails.root}/config/routes.rb")
|
34
|
+
content = File.open(File.expand_path("../templates/code_application_helper.rb", __FILE__), 'r') {|file| file.read}
|
35
|
+
sentinel = /module ApplicationHelper/
|
36
|
+
app = /::Application/
|
37
|
+
engine = /::Engine/
|
38
|
+
application = path.first.gsub(/::(.*)/, "").gsub("\n", "").underscore
|
39
|
+
|
40
|
+
if path.first =~ app
|
41
|
+
inject_into_file "#{Rails.root}/app/helpers/application_helper.rb", "\n#{content}\n", { :after => sentinel, :verbose => false }
|
42
|
+
elsif path.first =~ engine
|
43
|
+
inject_into_file "#{Rails.root}/app/helpers/#{application}/application_helper.rb", "\n#{content}\n", { :after => sentinel, :verbose => false }
|
44
|
+
end
|
31
45
|
end
|
32
|
-
|
46
|
+
|
33
47
|
def array_classes
|
34
48
|
%w[controller helper model migration]
|
35
49
|
end
|
@@ -8,7 +8,7 @@ class ScaffoldAdminGenerator < Rails::Generators::Base
|
|
8
8
|
no_tasks { attr_accessor :scaffold_name, :model_attributes }
|
9
9
|
|
10
10
|
argument :scaffold_name, :type => :string, :required => true, :banner => 'Namespace/ModelName'
|
11
|
-
argument :attributes, :type => :array, :default => [], :banner => 'field_name:type'
|
11
|
+
argument :attributes, :type => :array, :default => [], :banner => 'field_name:type'
|
12
12
|
|
13
13
|
def create_templates
|
14
14
|
args_attributes
|
@@ -18,23 +18,19 @@ class ScaffoldAdminGenerator < Rails::Generators::Base
|
|
18
18
|
template "controller.rb", "app/controllers/#{namespace_underscore}/#{plural_name}_controller.rb"
|
19
19
|
template "helper.rb", "app/helpers/#{namespace_underscore}/#{plural_name}_helper.rb"
|
20
20
|
|
21
|
-
|
21
|
+
array_views.each do |view|
|
22
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"
|
23
|
+
end
|
26
24
|
|
27
25
|
else
|
28
26
|
template "model.rb", "app/models/#{singular_name}.rb"
|
29
27
|
template "controller.rb", "app/controllers/#{plural_name}_controller.rb"
|
30
28
|
template "helper.rb", "app/helpers/#{plural_name}_helper.rb"
|
31
29
|
|
32
|
-
|
30
|
+
array_views.each do |view|
|
33
31
|
template "views/#{view}.html.erb", "app/views/#{plural_name}/#{view}.html.erb"
|
34
32
|
end
|
35
33
|
|
36
|
-
template "views/_form.html.erb", "app/views/#{namespace_underscore}/#{plural_name}/_form.html.erb"
|
37
|
-
|
38
34
|
end
|
39
35
|
|
40
36
|
route "resources :#{plural_name}"
|
@@ -45,9 +41,13 @@ class ScaffoldAdminGenerator < Rails::Generators::Base
|
|
45
41
|
if namespace_name
|
46
42
|
template 'migration.rb', "db/migrate/#{migration_number}_create_#{namespace_underscore}_#{plural_name}.rb"
|
47
43
|
else
|
48
|
-
template 'migration.rb', "db/migrate/#{migration_number}_create_#{plural_name}.rb"
|
44
|
+
template 'migration.rb', "db/migrate/#{migration_number}_create_#{plural_name}.rb"
|
49
45
|
end
|
50
46
|
end
|
47
|
+
|
48
|
+
def array_views
|
49
|
+
%w[edit _form index new show]
|
50
|
+
end
|
51
51
|
|
52
52
|
def split_scaffold_name
|
53
53
|
path = {}
|
@@ -12,7 +12,7 @@ class <%= plural_class %>Controller < ApplicationController
|
|
12
12
|
end
|
13
13
|
|
14
14
|
def show
|
15
|
-
@<%= singular_name %> = <%= class_name %>.
|
15
|
+
@<%= singular_name %> = <%= class_name %>.where(:id => params[:id]).first
|
16
16
|
|
17
17
|
respond_with @<%= singular_name %>
|
18
18
|
end
|
@@ -24,36 +24,34 @@ class <%= plural_class %>Controller < ApplicationController
|
|
24
24
|
end
|
25
25
|
|
26
26
|
def edit
|
27
|
-
@<%= singular_name %> = <%= class_name %>.
|
27
|
+
@<%= singular_name %> = <%= class_name %>.where(:id => params[:id]).first
|
28
28
|
respond_with @<%= singular_name %>
|
29
29
|
end
|
30
30
|
|
31
31
|
def create
|
32
|
-
@<%= singular_name %> = <%= class_name %>.new params[
|
32
|
+
@<%= singular_name %> = <%= class_name %>.new params[:<%= singular_name %>]
|
33
33
|
|
34
34
|
if @<%= singular_name %>.save
|
35
35
|
flash[:notice] = I18n.t :<%= singular_name %>_created
|
36
36
|
respond_with @<%= singular_name %>
|
37
37
|
else
|
38
|
-
flash[:alert] = I18n.t :<%= singular_name %>_not_created
|
39
38
|
render :action => :new
|
40
39
|
end
|
41
40
|
end
|
42
41
|
|
43
42
|
def update
|
44
|
-
@<%= singular_name %> = <%= class_name %>.
|
43
|
+
@<%= singular_name %> = <%= class_name %>.where(:id => params[:id]).first
|
45
44
|
|
46
|
-
if @<%= singular_name %>.update_attributes params[
|
45
|
+
if @<%= singular_name %>.update_attributes params[:<%= singular_name %>]
|
47
46
|
flash[:notice] = I18n.t :<%= singular_name %>_updated
|
48
47
|
respond_with @<%= singular_name %>
|
49
48
|
else
|
50
|
-
flash[:alert] = I18n.t :<%= singular_name %>_not_updated
|
51
49
|
render :action => :edit
|
52
50
|
end
|
53
51
|
end
|
54
52
|
|
55
53
|
def destroy
|
56
|
-
@<%= singular_name %> = <%= class_name %>.
|
54
|
+
@<%= singular_name %> = <%= class_name %>.where(:id => params[:id]).first
|
57
55
|
@<%= singular_name %>.destroy
|
58
56
|
|
59
57
|
respond_with @<%= singular_name %>
|
@@ -2,7 +2,7 @@
|
|
2
2
|
<div class="module_content">
|
3
3
|
<%% if @<%= singular_name %>.errors.any? %>
|
4
4
|
<div id="error_explanation">
|
5
|
-
<
|
5
|
+
<h4 class='alert_error'><%%= pluralize(@<%= singular_name %>.errors.count, "error") %> prohibited this category from being saved:</h4>
|
6
6
|
|
7
7
|
<ul>
|
8
8
|
<%% @<%= singular_name %>.errors.full_messages.each do |msg| %>
|
@@ -26,7 +26,7 @@
|
|
26
26
|
<%- end -%>
|
27
27
|
<td><%%= link_to image_tag("/assets/icn_folder.png", :alt => I18n.t(:show), :title => I18n.t(:show)), <%= singular_name %> %></td>
|
28
28
|
<td><%%= link_to image_tag("/assets/icn_edit_article.png", :alt => I18n.t(:edit), :title => I18n.t(:edit)), edit_<%= singular_name %>_path(<%= singular_name %>) %></td>
|
29
|
-
<td><%%=
|
29
|
+
<td><%%= button_to I18n.t(:delete), { :action => "destroy", :id => <%= singular_name %>.id }, :confirm => I18n.t(:are_you_sure), :method => :delete %></td>
|
30
30
|
</tr>
|
31
31
|
<%% end %>
|
32
32
|
</tbody>
|
metadata
CHANGED
@@ -5,8 +5,8 @@ version: !ruby/object:Gem::Version
|
|
5
5
|
segments:
|
6
6
|
- 0
|
7
7
|
- 0
|
8
|
-
-
|
9
|
-
version: 0.0.
|
8
|
+
- 2
|
9
|
+
version: 0.0.2
|
10
10
|
platform: ruby
|
11
11
|
authors:
|
12
12
|
- Vagner Zampieri
|
@@ -14,7 +14,7 @@ autorequire:
|
|
14
14
|
bindir: bin
|
15
15
|
cert_chain: []
|
16
16
|
|
17
|
-
date: 2011-
|
17
|
+
date: 2011-07-04 00:00:00 -03:00
|
18
18
|
default_executable:
|
19
19
|
dependencies: []
|
20
20
|
|
@@ -83,6 +83,7 @@ files:
|
|
83
83
|
- lib/generators/scaffold_admin/templates/layouts/admin.html.erb
|
84
84
|
- lib/generators/scaffold_admin/templates/stylesheets/ie.css
|
85
85
|
- lib/generators/scaffold_admin/templates/stylesheets/layout.css
|
86
|
+
- lib/generators/scaffold_admin/templates/code_application_helper.rb
|
86
87
|
- lib/generators/scaffold_admin/USAGE
|
87
88
|
- lib/zscaffold_admin.rb
|
88
89
|
- lib/zscaffold_admin/engine.rb
|