ghart_admin_scaffold 0.3.0
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/lib/generators/ghart_admin_scaffold/USAGE +10 -0
- data/lib/generators/ghart_admin_scaffold/ghart_admin_scaffold_generator.rb +51 -0
- data/lib/generators/ghart_admin_scaffold/templates/_form.html.erb +16 -0
- data/lib/generators/ghart_admin_scaffold/templates/controller.rb +47 -0
- data/lib/generators/ghart_admin_scaffold/templates/edit.html.erb +3 -0
- data/lib/generators/ghart_admin_scaffold/templates/index.html.erb +18 -0
- data/lib/generators/ghart_admin_scaffold/templates/layout.html.erb +17 -0
- data/lib/generators/ghart_admin_scaffold/templates/new.html.erb +3 -0
- data/lib/generators/ghart_admin_scaffold/templates/show.html.erb +9 -0
- metadata +84 -0
@@ -0,0 +1,10 @@
|
|
1
|
+
Description:
|
2
|
+
Scaffolds an entire admin-namespaced resource, from model and migration to controller and
|
3
|
+
views, along with a full test suite.
|
4
|
+
|
5
|
+
Pass the name of the model (in singular form), either CamelCased or
|
6
|
+
under_scored, as the first argument, and an optional list of attribute
|
7
|
+
pairs.
|
8
|
+
|
9
|
+
Example:
|
10
|
+
`rails generate ghart_admin_scaffold post title:string body:text published:boolean`
|
@@ -0,0 +1,51 @@
|
|
1
|
+
require 'rails/generators'
|
2
|
+
require 'rails/generators/erb'
|
3
|
+
require 'rails/generators/rails/scaffold/scaffold_generator'
|
4
|
+
|
5
|
+
module Erb
|
6
|
+
module Generators
|
7
|
+
class ScaffoldGenerator < Base
|
8
|
+
def self.source_root
|
9
|
+
@source_root ||= File.expand_path('../templates', __FILE__)
|
10
|
+
end
|
11
|
+
protected
|
12
|
+
def assign_names!(name)
|
13
|
+
@class_path = name.include?('/') ? name.split('/') : name.split('::')
|
14
|
+
@class_path = ["admin"] + @class_path
|
15
|
+
@class_path.map! { |m| m.underscore }
|
16
|
+
@file_name = @class_path.pop
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
21
|
+
|
22
|
+
module Rails
|
23
|
+
module Generators
|
24
|
+
class ScaffoldControllerGenerator < NamedBase
|
25
|
+
def self.source_root
|
26
|
+
@source_root ||= File.expand_path('../templates', __FILE__)
|
27
|
+
end
|
28
|
+
protected
|
29
|
+
def assign_names!(name)
|
30
|
+
@class_path = name.include?('/') ? name.split('/') : name.split('::')
|
31
|
+
@class_path = ["admin"] + @class_path
|
32
|
+
@class_path.map! { |m| m.underscore }
|
33
|
+
@file_name = @class_path.pop
|
34
|
+
end
|
35
|
+
end
|
36
|
+
end
|
37
|
+
end
|
38
|
+
|
39
|
+
module Rails
|
40
|
+
module Generators
|
41
|
+
class GhartAdminScaffoldGenerator < ScaffoldGenerator
|
42
|
+
def self.source_root
|
43
|
+
@source_root ||= File.expand_path('../templates', __FILE__)
|
44
|
+
end
|
45
|
+
def add_resource_route
|
46
|
+
return if options[:actions].present?
|
47
|
+
route "namespace :admin do\n resource#{:s unless options[:singleton]} :#{pluralize?(file_name)}\n end"
|
48
|
+
end
|
49
|
+
end
|
50
|
+
end
|
51
|
+
end
|
@@ -0,0 +1,16 @@
|
|
1
|
+
<%%= form_for([:admin, @<%= singular_name %>]) do |f| %>
|
2
|
+
<% for attribute in attributes -%>
|
3
|
+
<div class="field">
|
4
|
+
<%%= f.label :<%= attribute.name %> %><br />
|
5
|
+
<% if attribute.name == "status" -%>
|
6
|
+
<%%= f.select :status, [["Draft"],["Inactive"],["Active"]], {:include_blank => true} %>
|
7
|
+
<% else -%>
|
8
|
+
<%%= f.<%= attribute.field_type %> :<%= attribute.name %> %>
|
9
|
+
<% end -%>
|
10
|
+
</div>
|
11
|
+
<% end -%>
|
12
|
+
<br />
|
13
|
+
<div class="actions">
|
14
|
+
<%%= f.submit "Submit" %> or <%%= link_to 'Cancel', admin_<%= plural_name %>_path %>
|
15
|
+
</div>
|
16
|
+
<%% end %>
|
@@ -0,0 +1,47 @@
|
|
1
|
+
class <%= controller_class_name %>Controller < ApplicationController
|
2
|
+
|
3
|
+
respond_to :html #, :xml, :json
|
4
|
+
|
5
|
+
<% unless options[:singleton] -%>
|
6
|
+
def index
|
7
|
+
respond_with(@<%= file_name.pluralize %> = <%= orm_class.all(file_name.camelize) %>)
|
8
|
+
end
|
9
|
+
<% end -%>
|
10
|
+
|
11
|
+
def show
|
12
|
+
respond_with(@<%= file_name %> = <%= orm_class.find(file_name.camelize, "params[:id]") %>)
|
13
|
+
end
|
14
|
+
|
15
|
+
def new
|
16
|
+
respond_with(@<%= file_name %> = <%= orm_class.build(file_name.camelize) %>)
|
17
|
+
end
|
18
|
+
|
19
|
+
def edit
|
20
|
+
@<%= file_name %> = <%= orm_class.find(file_name.camelize, "params[:id]") %>
|
21
|
+
end
|
22
|
+
|
23
|
+
def create
|
24
|
+
@<%= file_name %> = <%= orm_class.build(file_name.camelize, "params[:#{file_name}]") %>
|
25
|
+
if @<%= orm_instance.save %>
|
26
|
+
respond_with(@<%= file_name %>, :location => <%= table_name %>_url)
|
27
|
+
else
|
28
|
+
respond_with(@<%= file_name %>)
|
29
|
+
end
|
30
|
+
end
|
31
|
+
|
32
|
+
def update
|
33
|
+
@<%= file_name %> = <%= orm_class.find(file_name.camelize, "params[:id]") %>
|
34
|
+
if @<%= orm_instance.update_attributes("params[:#{file_name}]") %>
|
35
|
+
respond_with(@<%= file_name %>, :location => <%= table_name %>_url)
|
36
|
+
else
|
37
|
+
respond_with(@<%= file_name %>)
|
38
|
+
end
|
39
|
+
end
|
40
|
+
|
41
|
+
def destroy
|
42
|
+
@<%= file_name %> = <%= orm_class.find(file_name.camelize, "params[:id]") %>
|
43
|
+
@<%= orm_instance.destroy %>
|
44
|
+
respond_with(@<%= file_name %>, :location => <%= table_name %>_url)
|
45
|
+
end
|
46
|
+
|
47
|
+
end
|
@@ -0,0 +1,18 @@
|
|
1
|
+
<h1><%= plural_name.capitalize %></h1>
|
2
|
+
|
3
|
+
<table>
|
4
|
+
<%% @<%= plural_name %>.each do |<%= singular_name %>| %>
|
5
|
+
<tr>
|
6
|
+
<% for attribute in attributes -%>
|
7
|
+
<td><%%= <%= singular_name %>.<%= attribute.name %> %></td>
|
8
|
+
<% end -%>
|
9
|
+
<td width="20"></td>
|
10
|
+
<td><%%= link_to 'Edit', edit_admin_<%= singular_name %>_path(<%= singular_name %>) %></td>
|
11
|
+
<td><%%= link_to 'Delete', [:admin, <%= singular_name %>], :confirm => 'Are you sure?', :method => :delete %></td>
|
12
|
+
</tr>
|
13
|
+
<%% end %>
|
14
|
+
</table>
|
15
|
+
|
16
|
+
<br />
|
17
|
+
|
18
|
+
<%%= link_to 'Add <%= human_name %>', new_admin_<%= singular_name %>_path %>
|
@@ -0,0 +1,17 @@
|
|
1
|
+
<!DOCTYPE html>
|
2
|
+
<html>
|
3
|
+
<head>
|
4
|
+
<title><%= controller_class_name %>: <%%= controller.action_name %></title>
|
5
|
+
<%%= stylesheet_link_tag 'scaffold' %>
|
6
|
+
<%%= javascript_include_tag :defaults %>
|
7
|
+
<%%= csrf_meta_tag %>
|
8
|
+
</head>
|
9
|
+
<body>
|
10
|
+
|
11
|
+
<p class="notice"><%%= notice %></p>
|
12
|
+
<p class="alert"><%%= alert %></p>
|
13
|
+
|
14
|
+
<%%= yield %>
|
15
|
+
|
16
|
+
</body>
|
17
|
+
</html>
|
metadata
ADDED
@@ -0,0 +1,84 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: ghart_admin_scaffold
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
prerelease: false
|
5
|
+
segments:
|
6
|
+
- 0
|
7
|
+
- 3
|
8
|
+
- 0
|
9
|
+
version: 0.3.0
|
10
|
+
platform: ruby
|
11
|
+
authors: []
|
12
|
+
|
13
|
+
autorequire:
|
14
|
+
bindir: bin
|
15
|
+
cert_chain: []
|
16
|
+
|
17
|
+
date: 2010-05-09 00:00:00 -06:00
|
18
|
+
default_executable:
|
19
|
+
dependencies:
|
20
|
+
- !ruby/object:Gem::Dependency
|
21
|
+
name: rails
|
22
|
+
prerelease: false
|
23
|
+
requirement: &id001 !ruby/object:Gem::Requirement
|
24
|
+
requirements:
|
25
|
+
- - "="
|
26
|
+
- !ruby/object:Gem::Version
|
27
|
+
segments:
|
28
|
+
- 3
|
29
|
+
- 0
|
30
|
+
- 0
|
31
|
+
- beta3
|
32
|
+
version: 3.0.0.beta3
|
33
|
+
type: :runtime
|
34
|
+
version_requirements: *id001
|
35
|
+
description:
|
36
|
+
email:
|
37
|
+
executables: []
|
38
|
+
|
39
|
+
extensions: []
|
40
|
+
|
41
|
+
extra_rdoc_files: []
|
42
|
+
|
43
|
+
files:
|
44
|
+
- lib/generators/ghart_admin_scaffold/ghart_admin_scaffold_generator.rb
|
45
|
+
- lib/generators/ghart_admin_scaffold/templates/_form.html.erb
|
46
|
+
- lib/generators/ghart_admin_scaffold/templates/controller.rb
|
47
|
+
- lib/generators/ghart_admin_scaffold/templates/edit.html.erb
|
48
|
+
- lib/generators/ghart_admin_scaffold/templates/index.html.erb
|
49
|
+
- lib/generators/ghart_admin_scaffold/templates/layout.html.erb
|
50
|
+
- lib/generators/ghart_admin_scaffold/templates/new.html.erb
|
51
|
+
- lib/generators/ghart_admin_scaffold/templates/show.html.erb
|
52
|
+
- lib/generators/ghart_admin_scaffold/USAGE
|
53
|
+
has_rdoc: true
|
54
|
+
homepage:
|
55
|
+
licenses: []
|
56
|
+
|
57
|
+
post_install_message:
|
58
|
+
rdoc_options: []
|
59
|
+
|
60
|
+
require_paths:
|
61
|
+
- lib
|
62
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
63
|
+
requirements:
|
64
|
+
- - ">="
|
65
|
+
- !ruby/object:Gem::Version
|
66
|
+
segments:
|
67
|
+
- 0
|
68
|
+
version: "0"
|
69
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
70
|
+
requirements:
|
71
|
+
- - ">="
|
72
|
+
- !ruby/object:Gem::Version
|
73
|
+
segments:
|
74
|
+
- 0
|
75
|
+
version: "0"
|
76
|
+
requirements: []
|
77
|
+
|
78
|
+
rubyforge_project:
|
79
|
+
rubygems_version: 1.3.6
|
80
|
+
signing_key:
|
81
|
+
specification_version: 3
|
82
|
+
summary: Admin-namespaced scaffold generator
|
83
|
+
test_files: []
|
84
|
+
|