schofield 0.0.0 → 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/VERSION +1 -1
- data/generators/form/form_generator.rb +120 -0
- data/generators/form/templates/view__form.html.haml +11 -0
- data/generators/schofield_controller/schofield_controller_generator.rb +110 -0
- data/generators/schofield_controller/templates/controller_spec.rb +25 -0
- data/generators/schofield_controller/templates/helper_spec.rb +11 -0
- data/generators/schofield_controller/templates/nested/controller.rb +82 -0
- data/generators/schofield_controller/templates/nested/edit.rb +5 -0
- data/generators/schofield_controller/templates/nested/index.rb +21 -0
- data/generators/schofield_controller/templates/nested/new.rb +3 -0
- data/generators/schofield_controller/templates/nested/show.rb +7 -0
- data/generators/schofield_controller/templates/unnested/controller.rb +77 -0
- data/generators/schofield_controller/templates/unnested/edit.rb +5 -0
- data/generators/schofield_controller/templates/unnested/index.rb +21 -0
- data/generators/schofield_controller/templates/unnested/new.rb +3 -0
- data/generators/schofield_controller/templates/unnested/show.rb +3 -0
- data/generators/schofield_controller/templates/view_spec.rb +12 -0
- data/schofield.gemspec +75 -0
- data/tasks/schofield.rake +13 -0
- metadata +19 -1
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.0.
|
1
|
+
0.0.1
|
@@ -0,0 +1,120 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
# Get current OS - needed for clipboard functionality
|
3
|
+
case RUBY_PLATFORM
|
4
|
+
when /darwin/ then
|
5
|
+
CURRENT_OS = :osx
|
6
|
+
when /win32/
|
7
|
+
CURRENT_OS = :win
|
8
|
+
begin
|
9
|
+
require 'win32/clipboard'
|
10
|
+
rescue LoadError
|
11
|
+
# Do nothing
|
12
|
+
end
|
13
|
+
else
|
14
|
+
CURRENT_OS = :x
|
15
|
+
end
|
16
|
+
|
17
|
+
class FormGenerator < Rails::Generator::NamedBase
|
18
|
+
|
19
|
+
default_options :haml => false,
|
20
|
+
:partial => false
|
21
|
+
|
22
|
+
VIEWS_PATH = File.join('app', 'views').freeze
|
23
|
+
IGNORED_COLUMNS = [:updated_at, :created_at].freeze
|
24
|
+
|
25
|
+
attr_reader :controller_file_name,
|
26
|
+
:controller_class_path,
|
27
|
+
:controller_class_nesting,
|
28
|
+
:controller_class_nesting_depth,
|
29
|
+
:controller_class_name,
|
30
|
+
:template_type
|
31
|
+
|
32
|
+
def initialize(runtime_args, runtime_options = {})
|
33
|
+
super
|
34
|
+
base_name, @controller_class_path = extract_modules(@name.pluralize)
|
35
|
+
controller_class_name_without_nesting, @controller_file_name = inflect_names(base_name)
|
36
|
+
@template_type = options[:haml] ? :haml : :erb
|
37
|
+
end
|
38
|
+
|
39
|
+
def manifest
|
40
|
+
record do |m|
|
41
|
+
if options[:partial]
|
42
|
+
controller_and_view_path = options[:controller] || File.join(controller_class_path, controller_file_name)
|
43
|
+
# Ensure directory exists.
|
44
|
+
m.directory File.join(VIEWS_PATH, controller_and_view_path)
|
45
|
+
# Create a form partial for the model as "_form" in it's views path.
|
46
|
+
m.template "view__form.html.#{template_type}", File.join(VIEWS_PATH, controller_and_view_path, "_form.html.#{template_type}")
|
47
|
+
else
|
48
|
+
# Load template file, and render without saving to file
|
49
|
+
template = File.read(File.join(source_root, "view__form.html.#{template_type}"))
|
50
|
+
erb = ERB.new(template, nil, '-')
|
51
|
+
generated_code = erb.result(binding).strip rescue nil
|
52
|
+
|
53
|
+
# Print the result, and copy to clipboard
|
54
|
+
puts "# ---------------------------------------------------------"
|
55
|
+
puts "# GENERATED FORMTASTIC CODE"
|
56
|
+
puts "# ---------------------------------------------------------"
|
57
|
+
puts
|
58
|
+
puts generated_code || " Nothing could be generated - model exists?"
|
59
|
+
puts
|
60
|
+
puts "# ---------------------------------------------------------"
|
61
|
+
puts " Copied to clipboard - just paste it!" if save_to_clipboard(generated_code)
|
62
|
+
end
|
63
|
+
end
|
64
|
+
end
|
65
|
+
|
66
|
+
protected
|
67
|
+
|
68
|
+
# Save to lipboard with multiple OS support.
|
69
|
+
def save_to_clipboard(data)
|
70
|
+
return unless data
|
71
|
+
begin
|
72
|
+
case CURRENT_OS
|
73
|
+
when :osx
|
74
|
+
`echo "#{data}" | pbcopy`
|
75
|
+
when :win
|
76
|
+
::Win32::Clipboard.data = data
|
77
|
+
else # :linux/:unix
|
78
|
+
`echo "#{data}" | xsel --clipboard` || `echo "#{data}" | xclip`
|
79
|
+
end
|
80
|
+
rescue
|
81
|
+
false
|
82
|
+
else
|
83
|
+
true
|
84
|
+
end
|
85
|
+
end
|
86
|
+
|
87
|
+
# Add additional model attributes if specified in args - probably not that common scenario.
|
88
|
+
def attributes
|
89
|
+
# Get columns for the requested model.
|
90
|
+
existing_attributes = @class_name.constantize.content_columns.reject { |column| IGNORED_COLUMNS.include?(column.name.to_sym) }
|
91
|
+
@args = super + existing_attributes
|
92
|
+
end
|
93
|
+
|
94
|
+
def add_options!(opt)
|
95
|
+
opt.separator ''
|
96
|
+
opt.separator 'Options:'
|
97
|
+
|
98
|
+
# Allow option to generate HAML views instead of ERB.
|
99
|
+
opt.on('--haml',
|
100
|
+
"Generate HAML output instead of the default ERB.") do |v|
|
101
|
+
options[:haml] = v
|
102
|
+
end
|
103
|
+
|
104
|
+
# Allow option to generate to partial in model's views path, instead of printing out in terminal.
|
105
|
+
opt.on('--partial',
|
106
|
+
"Save generated output directly to a form partial (app/views/{resource}/_form.html.*).") do |v|
|
107
|
+
options[:partial] = v
|
108
|
+
end
|
109
|
+
|
110
|
+
opt.on('--controller CONTROLLER_PATH',
|
111
|
+
"Specify a non-standard controller for the specified model (e.g. admin/posts).") do |v|
|
112
|
+
options[:controller] = v if v.present?
|
113
|
+
end
|
114
|
+
end
|
115
|
+
|
116
|
+
def banner
|
117
|
+
"Usage: #{$0} form ExistingModelName [--haml] [--partial]"
|
118
|
+
end
|
119
|
+
|
120
|
+
end
|
@@ -0,0 +1,11 @@
|
|
1
|
+
= error_messages_for '<%= singular_name.singularize %>', :object => object
|
2
|
+
|
3
|
+
- semantic_form_for [:admin, @<%= singular_name.singularize %>], :html => { :multipart => true } do |f|
|
4
|
+
|
5
|
+
- f.inputs do
|
6
|
+
|
7
|
+
<% attributes.each do |attribute| -%>
|
8
|
+
= f.input :<%= attribute.name %>, :label => '<%= attribute.name.humanize %>'
|
9
|
+
<% end -%>
|
10
|
+
|
11
|
+
= f.buttons
|
@@ -0,0 +1,110 @@
|
|
1
|
+
class SchofieldControllerGenerator < Rails::Generator::NamedBase
|
2
|
+
|
3
|
+
def initialize(runtime_args, runtime_options = {})
|
4
|
+
super
|
5
|
+
usage if runtime_args.empty?
|
6
|
+
|
7
|
+
@args = runtime_args.dup
|
8
|
+
base_name = @args.shift
|
9
|
+
assign_names!(base_name)
|
10
|
+
end
|
11
|
+
|
12
|
+
|
13
|
+
def manifest
|
14
|
+
record do |m|
|
15
|
+
|
16
|
+
template_directory = options[:parent].nil? ? 'unnested' : 'nested'
|
17
|
+
|
18
|
+
sco_class = class_name.gsub('Admin::', '').singularize
|
19
|
+
sco_humanized_uc = sco_class.underscore.humanize
|
20
|
+
sco_underscored = @singular_name.singularize
|
21
|
+
sco_underscored_plural = sco_underscored.pluralize
|
22
|
+
sco_titleized_plural = sco_underscored.pluralize.titleize
|
23
|
+
sco_humanized = sco_humanized_uc.downcase
|
24
|
+
sco_parent_class = options[:parent] ? options[:parent].classify : ''
|
25
|
+
sco_parent_underscored = sco_parent_class.underscore.downcase
|
26
|
+
sco_parent_underscored_plural = sco_parent_underscored.pluralize
|
27
|
+
sco_parent_titleized_plural = sco_parent_underscored.titleize.pluralize
|
28
|
+
|
29
|
+
assigns = { :sco_underscored => sco_underscored,
|
30
|
+
:sco_underscored_plural => sco_underscored_plural,
|
31
|
+
:sco_class => sco_class,
|
32
|
+
:sco_humanized_uc => sco_humanized_uc,
|
33
|
+
:sco_parent_underscored => sco_parent_underscored,
|
34
|
+
:sco_parent_underscored_plural => sco_parent_underscored_plural,
|
35
|
+
:sco_parent_titleized_plural => sco_parent_titleized_plural,
|
36
|
+
:sco_parent_class => sco_parent_class,
|
37
|
+
:sco_titleized_plural => sco_titleized_plural,
|
38
|
+
:sco_humanized => sco_humanized,
|
39
|
+
:non_restful_actions => non_restful_actions }
|
40
|
+
|
41
|
+
|
42
|
+
# Check for class naming collisions.
|
43
|
+
m.class_collisions class_path, "#{class_name}Controller", "#{class_name}Helper"
|
44
|
+
|
45
|
+
# Controller, helper, views, and spec directories.
|
46
|
+
m.directory File.join('app/controllers', class_path)
|
47
|
+
m.directory File.join('app/helpers', class_path)
|
48
|
+
m.directory File.join('app/views', class_path, file_name)
|
49
|
+
m.directory File.join('spec/controllers', class_path)
|
50
|
+
m.directory File.join('spec/helpers', class_path)
|
51
|
+
m.directory File.join('spec/views', class_path, file_name)
|
52
|
+
|
53
|
+
# Controller spec, class, and helper.
|
54
|
+
m.template 'controller_spec.rb',
|
55
|
+
File.join('spec/controllers', class_path, "#{file_name}_controller_spec.rb")
|
56
|
+
|
57
|
+
m.template 'helper_spec.rb',
|
58
|
+
File.join('spec/helpers', class_path, "#{file_name}_helper_spec.rb")
|
59
|
+
|
60
|
+
m.template "#{template_directory}/controller.rb",
|
61
|
+
File.join('app/controllers', class_path, "#{file_name}_controller.rb"),
|
62
|
+
:assigns => assigns
|
63
|
+
|
64
|
+
m.template 'controller:helper.rb',
|
65
|
+
File.join('app/helpers', class_path, "#{file_name}_helper.rb")
|
66
|
+
|
67
|
+
# Spec and view template for each action.
|
68
|
+
actions.each do |action|
|
69
|
+
|
70
|
+
m.template 'view_spec.rb',
|
71
|
+
File.join('spec/views', class_path, file_name, "#{action}.haml_spec.rb"),
|
72
|
+
:assigns => { :action => action, :model => file_name }
|
73
|
+
|
74
|
+
m.template "#{template_directory}/#{action}.rb",
|
75
|
+
File.join('app/views', class_path, file_name, "#{action}.haml"),
|
76
|
+
:assigns => assigns if actions_with_view.include?(action)
|
77
|
+
|
78
|
+
end
|
79
|
+
end
|
80
|
+
end
|
81
|
+
|
82
|
+
|
83
|
+
|
84
|
+
|
85
|
+
def actions_with_view
|
86
|
+
non_restful_actions + %w( index show new edit )
|
87
|
+
end
|
88
|
+
|
89
|
+
def restful_actions
|
90
|
+
%w( index show new create edit update destroy sort )
|
91
|
+
end
|
92
|
+
|
93
|
+
def non_restful_actions
|
94
|
+
restful_actions - %w( index show new create edit update destroy sort )
|
95
|
+
end
|
96
|
+
|
97
|
+
|
98
|
+
protected
|
99
|
+
|
100
|
+
def add_options!(opt)
|
101
|
+
opt.separator ''
|
102
|
+
opt.separator 'Options:'
|
103
|
+
opt.on('--parent PARENT', 'Specify the parent model') { |v| options[:parent] = v if v.present? }
|
104
|
+
end
|
105
|
+
|
106
|
+
def banner
|
107
|
+
"Usage: #{$0} schofield_controller ControllerName [--parent PARENT]"
|
108
|
+
end
|
109
|
+
|
110
|
+
end
|
@@ -0,0 +1,25 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe <%= class_name %>Controller do
|
4
|
+
|
5
|
+
<% if actions.empty? -%>
|
6
|
+
#Delete this example and add some real ones
|
7
|
+
<% else -%>
|
8
|
+
#Delete these examples and add some real ones
|
9
|
+
<% end -%>
|
10
|
+
it "should use <%= class_name %>Controller" do
|
11
|
+
controller.should be_an_instance_of(<%= class_name %>Controller)
|
12
|
+
end
|
13
|
+
|
14
|
+
<% unless actions.empty? -%>
|
15
|
+
<% for action in actions -%>
|
16
|
+
|
17
|
+
describe "GET '<%= action %>'" do
|
18
|
+
it "should be successful" do
|
19
|
+
get '<%= action %>'
|
20
|
+
response.should be_success
|
21
|
+
end
|
22
|
+
end
|
23
|
+
<% end -%>
|
24
|
+
<% end -%>
|
25
|
+
end
|
@@ -0,0 +1,11 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe <%= class_name %>Helper do
|
4
|
+
|
5
|
+
#Delete this example and add some real ones or delete this file
|
6
|
+
it "should be included in the object returned by #helper" do
|
7
|
+
included_modules = (class << helper; self; end).send :included_modules
|
8
|
+
included_modules.should include(<%= class_name %>Helper)
|
9
|
+
end
|
10
|
+
|
11
|
+
end
|
@@ -0,0 +1,82 @@
|
|
1
|
+
class <%= class_name %>Controller < Admin::AdminController
|
2
|
+
|
3
|
+
before_filter :find_<%= sco_underscored %>, :only => [:show, :edit, :update, :destroy]
|
4
|
+
before_filter :find_<%= sco_parent_underscored %>, :only => [:index, :new, :create]
|
5
|
+
|
6
|
+
|
7
|
+
<% if actions.include?('index') -%>
|
8
|
+
|
9
|
+
def index
|
10
|
+
@<%= sco_underscored_plural %> = @<%= sco_parent_underscored %>.<%= sco_underscored_plural %>
|
11
|
+
end
|
12
|
+
|
13
|
+
<% end -%>
|
14
|
+
|
15
|
+
def show
|
16
|
+
end
|
17
|
+
|
18
|
+
|
19
|
+
def new
|
20
|
+
@<%= sco_underscored %> = @<%= sco_parent_underscored %>.<%= sco_underscored_plural %>.build
|
21
|
+
end
|
22
|
+
|
23
|
+
|
24
|
+
def edit
|
25
|
+
end
|
26
|
+
|
27
|
+
|
28
|
+
def create
|
29
|
+
@<%= sco_underscored %> = @<%= sco_parent_underscored %>.<%= sco_underscored_plural %>.build(params[:<%= sco_underscored %>])
|
30
|
+
if @<%= sco_underscored %>.save
|
31
|
+
flash[:notice] = '<%= sco_humanized_uc %> was successfully created.'
|
32
|
+
redirect_to_form_referer
|
33
|
+
else
|
34
|
+
render :action => 'new'
|
35
|
+
end
|
36
|
+
end
|
37
|
+
|
38
|
+
|
39
|
+
def update
|
40
|
+
if @<%= sco_underscored %>.update_attributes(params[:<%= sco_underscored %>])
|
41
|
+
flash[:notice] = '<%= sco_humanized_uc %> was successfully updated.'
|
42
|
+
redirect_to_form_referer
|
43
|
+
else
|
44
|
+
render :action => 'edit'
|
45
|
+
end
|
46
|
+
end
|
47
|
+
|
48
|
+
|
49
|
+
def destroy
|
50
|
+
@<%= sco_underscored %>.destroy
|
51
|
+
redirect_to :back
|
52
|
+
end
|
53
|
+
|
54
|
+
|
55
|
+
<% if actions.include?('sort') -%>
|
56
|
+
|
57
|
+
def sort
|
58
|
+
params[:<%= sco_underscored %>].each_with_index do |id, index|
|
59
|
+
<%= sco_class %>.update_all(['position=?', index+1], ['id=?', id])
|
60
|
+
end
|
61
|
+
render :nothing => true
|
62
|
+
end
|
63
|
+
|
64
|
+
<% end -%>
|
65
|
+
|
66
|
+
<% for action in non_restful_actions -%>
|
67
|
+
def <%= action %>
|
68
|
+
end
|
69
|
+
|
70
|
+
<% end -%>
|
71
|
+
|
72
|
+
private
|
73
|
+
|
74
|
+
def find_<%= sco_parent_underscored %>
|
75
|
+
@<%= sco_parent_underscored %> = <%= sco_parent_class %>.find(params[:<%= sco_parent_underscored %>_id])
|
76
|
+
end
|
77
|
+
|
78
|
+
def find_<%= sco_underscored %>
|
79
|
+
@<%= sco_underscored %> = <%= sco_class %>.find(params[:id])
|
80
|
+
end
|
81
|
+
|
82
|
+
end
|
@@ -0,0 +1,5 @@
|
|
1
|
+
- titles link_to('<%= sco_parent_titleized_plural %>', admin_<%= sco_parent_underscored_plural %>_path), link_to(@<%= sco_underscored %>.<%= sco_parent_underscored %>, admin_<%= sco_parent_underscored %>_path(@<%= sco_underscored %>.<%= sco_parent_underscored %>)), 'Edit <%= sco_humanized %>'
|
2
|
+
|
3
|
+
- toggle_show_edit 'Show', :admin, @<%= sco_underscored %>
|
4
|
+
|
5
|
+
= render :partial => 'form', :locals => { :object => @<%= sco_underscored %> }
|
@@ -0,0 +1,21 @@
|
|
1
|
+
- titles link_to('<%= sco_parent_titleized_plural %>', admin_<%= sco_parent_underscored_plural %>_path), '<%= sco_titleized_plural %>'
|
2
|
+
|
3
|
+
%p= link_to('Add new <%= sco_humanized %>', new_admin_<%= sco_parent_underscored %>_<%= sco_underscored %>_path)
|
4
|
+
|
5
|
+
- if @<%= sco_underscored_plural %>.any?
|
6
|
+
|
7
|
+
%table#<%= sco_underscored_plural %>
|
8
|
+
|
9
|
+
= render :partial => 'shared/admin/table_header', :locals => { :columns => %w( Title ), :buttons => 3 }
|
10
|
+
|
11
|
+
%tbody
|
12
|
+
|
13
|
+
- @<%= sco_underscored_plural %>.each do |<%= sco_underscored %>|
|
14
|
+
|
15
|
+
%tr
|
16
|
+
|
17
|
+
%td&= <%= sco_underscored %>
|
18
|
+
|
19
|
+
%td= link_to_button 'Show', admin_<%= sco_underscored %>_path(<%= sco_underscored %>)
|
20
|
+
%td= link_to_button 'Edit', edit_admin_<%= sco_underscored %>_path(<%= sco_underscored %>)
|
21
|
+
%td= link_to_button 'Delete', admin_<%= sco_underscored %>_path(<%= sco_underscored %>), :method => 'delete', :confirm => "Are you sure you want to delete the <%= sco_humanized %>: #{h(<%= sco_underscored %>)}?"
|
@@ -0,0 +1,3 @@
|
|
1
|
+
- titles link_to('<%= sco_parent_titleized_plural %>', admin_<%= sco_parent_underscored_plural %>_path), link_to(@<%= sco_parent_underscored %>, admin_<%= sco_parent_underscored %>_path(@<%= sco_parent_underscored %>)), 'New <%= sco_humanized %>'
|
2
|
+
|
3
|
+
= render :partial => 'form', :locals => { :object => @<%= sco_underscored %> }
|
@@ -0,0 +1,7 @@
|
|
1
|
+
- titles link_to('<%= sco_titleized_plural %>', admin_<%= sco_underscored_plural %>_path), @<%= sco_underscored %>
|
2
|
+
|
3
|
+
|
4
|
+
- titles link_to('<%= sco_parent_titleized_plural %>', admin_<%= sco_parent_underscored_plural %>_path), link_to('<%= sco_titleized_plural %>', admin_<%= sco_underscored_plural %>_path), @<%= sco_underscored %>
|
5
|
+
|
6
|
+
|
7
|
+
- toggle_show_edit 'Edit', :admin, @<%= sco_underscored %>
|
@@ -0,0 +1,77 @@
|
|
1
|
+
class <%= class_name %>Controller < Admin::AdminController
|
2
|
+
|
3
|
+
before_filter :find_<%= sco_underscored %>, :only => [:show, :edit, :update, :destroy]
|
4
|
+
|
5
|
+
|
6
|
+
<% if actions.include?('index') -%>
|
7
|
+
|
8
|
+
def index
|
9
|
+
@<%= sco_underscored_plural %> = <%= sco_class %>.all
|
10
|
+
end
|
11
|
+
|
12
|
+
<% end -%>
|
13
|
+
|
14
|
+
def show
|
15
|
+
end
|
16
|
+
|
17
|
+
|
18
|
+
def new
|
19
|
+
@<%= sco_underscored %> = <%= sco_class %>.new
|
20
|
+
end
|
21
|
+
|
22
|
+
|
23
|
+
def edit
|
24
|
+
end
|
25
|
+
|
26
|
+
|
27
|
+
def create
|
28
|
+
@<%= sco_underscored %> = <%= sco_class %>.new(params[:<%= sco_underscored %>])
|
29
|
+
if @<%= sco_underscored %>.save
|
30
|
+
flash[:notice] = '<%= sco_humanized_uc %> was successfully created.'
|
31
|
+
redirect_to_form_referer
|
32
|
+
else
|
33
|
+
render :action => 'new'
|
34
|
+
end
|
35
|
+
end
|
36
|
+
|
37
|
+
|
38
|
+
def update
|
39
|
+
if @<%= sco_underscored %>.update_attributes(params[:<%= sco_underscored %>])
|
40
|
+
flash[:notice] = '<%= sco_humanized_uc %> was successfully updated.'
|
41
|
+
redirect_to_form_referer
|
42
|
+
else
|
43
|
+
render :action => 'edit'
|
44
|
+
end
|
45
|
+
end
|
46
|
+
|
47
|
+
|
48
|
+
def destroy
|
49
|
+
@<%= sco_underscored %>.destroy
|
50
|
+
redirect_to :back
|
51
|
+
end
|
52
|
+
|
53
|
+
|
54
|
+
<% if actions.include?('sort') -%>
|
55
|
+
|
56
|
+
def sort
|
57
|
+
params[:<%= sco_underscored %>].each_with_index do |id, index|
|
58
|
+
<%= sco_class %>.update_all(['position=?', index+1], ['id=?', id])
|
59
|
+
end
|
60
|
+
render :nothing => true
|
61
|
+
end
|
62
|
+
|
63
|
+
<% end -%>
|
64
|
+
|
65
|
+
<% for action in non_restful_actions -%>
|
66
|
+
def <%= action %>
|
67
|
+
end
|
68
|
+
|
69
|
+
<% end -%>
|
70
|
+
|
71
|
+
private
|
72
|
+
|
73
|
+
def find_<%= sco_underscored %>
|
74
|
+
@<%= sco_underscored %> = <%= sco_class %>.find(params[:id])
|
75
|
+
end
|
76
|
+
|
77
|
+
end
|
@@ -0,0 +1,5 @@
|
|
1
|
+
- titles link_to('<%= sco_titleized_plural %>', admin_<%= sco_underscored_plural %>_path), link_to(@<%= sco_underscored %>, admin_<%= sco_underscored %>_path(@<%= sco_underscored %>)), 'Edit'
|
2
|
+
|
3
|
+
- toggle_show_edit 'Show', :admin, @<%= sco_underscored %>
|
4
|
+
|
5
|
+
= render :partial => 'form', :locals => { :object => @<%= sco_underscored %> }
|
@@ -0,0 +1,21 @@
|
|
1
|
+
- titles '<%= sco_titleized_plural %>'
|
2
|
+
|
3
|
+
%p= link_to('Add new <%= sco_humanized %>', new_admin_<%= sco_underscored %>_path)
|
4
|
+
|
5
|
+
- if @<%= sco_underscored_plural %>.any?
|
6
|
+
|
7
|
+
%table#<%= sco_underscored_plural %>
|
8
|
+
|
9
|
+
= render :partial => 'shared/admin/table_header', :locals => { :columns => %w( Title ), :buttons => 3 }
|
10
|
+
|
11
|
+
%tbody
|
12
|
+
|
13
|
+
- @<%= sco_underscored_plural %>.each do |<%= sco_underscored %>|
|
14
|
+
|
15
|
+
%tr
|
16
|
+
|
17
|
+
%td&= <%= sco_underscored %>
|
18
|
+
|
19
|
+
%td= link_to_button 'Show', admin_<%= sco_underscored %>_path(<%= sco_underscored %>)
|
20
|
+
%td= link_to_button 'Edit', edit_admin_<%= sco_underscored %>_path(<%= sco_underscored %>)
|
21
|
+
%td= link_to_button 'Delete', admin_<%= sco_underscored %>_path(<%= sco_underscored %>), :method => 'delete', :confirm => "Are you sure you want to delete the <%= sco_humanized %>: #{h(<%= sco_underscored %>)}?"
|
@@ -0,0 +1,12 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe "/<%= class_name.underscore %>/<%= action %>" do
|
4
|
+
before(:each) do
|
5
|
+
render '<%= class_name.underscore %>/<%= action %>'
|
6
|
+
end
|
7
|
+
|
8
|
+
#Delete this example and add some real ones or delete this file
|
9
|
+
it "should tell you where to find the file" do
|
10
|
+
response.should have_tag('p', %r[Find me in app/views/<%= class_name.underscore %>/<%= action %>])
|
11
|
+
end
|
12
|
+
end
|
data/schofield.gemspec
ADDED
@@ -0,0 +1,75 @@
|
|
1
|
+
# Generated by jeweler
|
2
|
+
# DO NOT EDIT THIS FILE DIRECTLY
|
3
|
+
# Instead, edit Jeweler::Tasks in Rakefile, and run the gemspec command
|
4
|
+
# -*- encoding: utf-8 -*-
|
5
|
+
|
6
|
+
Gem::Specification.new do |s|
|
7
|
+
s.name = %q{schofield}
|
8
|
+
s.version = "0.0.1"
|
9
|
+
|
10
|
+
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
11
|
+
s.authors = ["Marc Tauber"]
|
12
|
+
s.date = %q{2009-12-02}
|
13
|
+
s.description = %q{Create views and controllers from routes defined in admin namespace. Very, very basic and very specific to my needs.'}
|
14
|
+
s.email = %q{marc@marctauber.com}
|
15
|
+
s.extra_rdoc_files = [
|
16
|
+
"LICENSE",
|
17
|
+
"README.rdoc"
|
18
|
+
]
|
19
|
+
s.files = [
|
20
|
+
".document",
|
21
|
+
".gitignore",
|
22
|
+
"LICENSE",
|
23
|
+
"README.rdoc",
|
24
|
+
"Rakefile",
|
25
|
+
"VERSION",
|
26
|
+
"generators/form/form_generator.rb",
|
27
|
+
"generators/form/templates/view__form.html.haml",
|
28
|
+
"generators/schofield_controller/schofield_controller_generator.rb",
|
29
|
+
"generators/schofield_controller/templates/controller_spec.rb",
|
30
|
+
"generators/schofield_controller/templates/helper_spec.rb",
|
31
|
+
"generators/schofield_controller/templates/nested/controller.rb",
|
32
|
+
"generators/schofield_controller/templates/nested/edit.rb",
|
33
|
+
"generators/schofield_controller/templates/nested/index.rb",
|
34
|
+
"generators/schofield_controller/templates/nested/new.rb",
|
35
|
+
"generators/schofield_controller/templates/nested/show.rb",
|
36
|
+
"generators/schofield_controller/templates/unnested/controller.rb",
|
37
|
+
"generators/schofield_controller/templates/unnested/edit.rb",
|
38
|
+
"generators/schofield_controller/templates/unnested/index.rb",
|
39
|
+
"generators/schofield_controller/templates/unnested/new.rb",
|
40
|
+
"generators/schofield_controller/templates/unnested/show.rb",
|
41
|
+
"generators/schofield_controller/templates/view_spec.rb",
|
42
|
+
"lib/schofield.rb",
|
43
|
+
"schofield.gemspec",
|
44
|
+
"spec/schofield_spec.rb",
|
45
|
+
"spec/spec.opts",
|
46
|
+
"spec/spec_helper.rb",
|
47
|
+
"tasks/schofield.rake"
|
48
|
+
]
|
49
|
+
s.homepage = %q{http://github.com/sauberia/schofield}
|
50
|
+
s.rdoc_options = ["--charset=UTF-8"]
|
51
|
+
s.require_paths = ["lib"]
|
52
|
+
s.rubygems_version = %q{1.3.5}
|
53
|
+
s.summary = %q{Creates views and controller from defined routes and respective models}
|
54
|
+
s.test_files = [
|
55
|
+
"spec/schofield_spec.rb",
|
56
|
+
"spec/spec_helper.rb"
|
57
|
+
]
|
58
|
+
|
59
|
+
if s.respond_to? :specification_version then
|
60
|
+
current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
|
61
|
+
s.specification_version = 3
|
62
|
+
|
63
|
+
if Gem::Version.new(Gem::RubyGemsVersion) >= Gem::Version.new('1.2.0') then
|
64
|
+
s.add_development_dependency(%q<rspec>, [">= 1.2.9"])
|
65
|
+
s.add_development_dependency(%q<formtastic>, ["= 0.9.5"])
|
66
|
+
else
|
67
|
+
s.add_dependency(%q<rspec>, [">= 1.2.9"])
|
68
|
+
s.add_dependency(%q<formtastic>, ["= 0.9.5"])
|
69
|
+
end
|
70
|
+
else
|
71
|
+
s.add_dependency(%q<rspec>, [">= 1.2.9"])
|
72
|
+
s.add_dependency(%q<formtastic>, ["= 0.9.5"])
|
73
|
+
end
|
74
|
+
end
|
75
|
+
|
@@ -0,0 +1,13 @@
|
|
1
|
+
namespace :schofield do
|
2
|
+
|
3
|
+
desc "Generate controllers and views based on routes"
|
4
|
+
task :generate => :environment do
|
5
|
+
|
6
|
+
@generator = Schofield::Generator.new
|
7
|
+
ActionController::Routing::Routes.routes.each do |route|
|
8
|
+
@generator.process_route(route)
|
9
|
+
end
|
10
|
+
@generator.generate
|
11
|
+
|
12
|
+
end
|
13
|
+
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: schofield
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Marc Tauber
|
@@ -48,10 +48,28 @@ files:
|
|
48
48
|
- README.rdoc
|
49
49
|
- Rakefile
|
50
50
|
- VERSION
|
51
|
+
- generators/form/form_generator.rb
|
52
|
+
- generators/form/templates/view__form.html.haml
|
53
|
+
- generators/schofield_controller/schofield_controller_generator.rb
|
54
|
+
- generators/schofield_controller/templates/controller_spec.rb
|
55
|
+
- generators/schofield_controller/templates/helper_spec.rb
|
56
|
+
- generators/schofield_controller/templates/nested/controller.rb
|
57
|
+
- generators/schofield_controller/templates/nested/edit.rb
|
58
|
+
- generators/schofield_controller/templates/nested/index.rb
|
59
|
+
- generators/schofield_controller/templates/nested/new.rb
|
60
|
+
- generators/schofield_controller/templates/nested/show.rb
|
61
|
+
- generators/schofield_controller/templates/unnested/controller.rb
|
62
|
+
- generators/schofield_controller/templates/unnested/edit.rb
|
63
|
+
- generators/schofield_controller/templates/unnested/index.rb
|
64
|
+
- generators/schofield_controller/templates/unnested/new.rb
|
65
|
+
- generators/schofield_controller/templates/unnested/show.rb
|
66
|
+
- generators/schofield_controller/templates/view_spec.rb
|
51
67
|
- lib/schofield.rb
|
68
|
+
- schofield.gemspec
|
52
69
|
- spec/schofield_spec.rb
|
53
70
|
- spec/spec.opts
|
54
71
|
- spec/spec_helper.rb
|
72
|
+
- tasks/schofield.rake
|
55
73
|
has_rdoc: true
|
56
74
|
homepage: http://github.com/sauberia/schofield
|
57
75
|
licenses: []
|