scaffold_logic 1.6.0
Sign up to get free protection for your applications and to get access to all the features.
- data/.document +5 -0
- data/Capfile +4 -0
- data/README.rdoc +29 -0
- data/Rakefile +51 -0
- data/VERSION +1 -0
- data/config/deploy.rb +41 -0
- data/lib/generators/scaffold_logic/layout/USAGE +7 -0
- data/lib/generators/scaffold_logic/layout/layout_generator.rb +38 -0
- data/lib/generators/scaffold_logic/layout/templates/_nav_tabs.html.erb +3 -0
- data/lib/generators/scaffold_logic/layout/templates/images/icons/add.png +0 -0
- data/lib/generators/scaffold_logic/layout/templates/images/icons/collapsed.gif +0 -0
- data/lib/generators/scaffold_logic/layout/templates/images/icons/delete.png +0 -0
- data/lib/generators/scaffold_logic/layout/templates/images/icons/drag.png +0 -0
- data/lib/generators/scaffold_logic/layout/templates/images/icons/edit.png +0 -0
- data/lib/generators/scaffold_logic/layout/templates/images/icons/expanded.gif +0 -0
- data/lib/generators/scaffold_logic/layout/templates/images/icons/help_icon.png +0 -0
- data/lib/generators/scaffold_logic/layout/templates/images/icons/link_icon.png +0 -0
- data/lib/generators/scaffold_logic/layout/templates/images/icons/move.png +0 -0
- data/lib/generators/scaffold_logic/layout/templates/images/icons/move_white.png +0 -0
- data/lib/generators/scaffold_logic/layout/templates/images/icons/note.png +0 -0
- data/lib/generators/scaffold_logic/layout/templates/images/icons/note_white.png +0 -0
- data/lib/generators/scaffold_logic/layout/templates/images/icons/notification_icon_sprite.png +0 -0
- data/lib/generators/scaffold_logic/layout/templates/images/icons/spinner.gif +0 -0
- data/lib/generators/scaffold_logic/layout/templates/images/icons/view.png +0 -0
- data/lib/generators/scaffold_logic/layout/templates/images/icons/warning.png +0 -0
- data/lib/generators/scaffold_logic/layout/templates/images/icons/warning_2.png +0 -0
- data/lib/generators/scaffold_logic/layout/templates/images/icons/warning_box.png +0 -0
- data/lib/generators/scaffold_logic/layout/templates/images/icons/warning_icon.png +0 -0
- data/lib/generators/scaffold_logic/layout/templates/images/icons/warning_white.png +0 -0
- data/lib/generators/scaffold_logic/layout/templates/images/layout/arrow_asc.png +0 -0
- data/lib/generators/scaffold_logic/layout/templates/images/layout/arrow_desc.png +0 -0
- data/lib/generators/scaffold_logic/layout/templates/images/layout/back.png +0 -0
- data/lib/generators/scaffold_logic/layout/templates/images/layout/black_bar.png +0 -0
- data/lib/generators/scaffold_logic/layout/templates/images/layout/breadcrumb_bg.png +0 -0
- data/lib/generators/scaffold_logic/layout/templates/images/layout/button_bg.png +0 -0
- data/lib/generators/scaffold_logic/layout/templates/images/layout/content_left_bg.png +0 -0
- data/lib/generators/scaffold_logic/layout/templates/images/layout/content_right_bg.png +0 -0
- data/lib/generators/scaffold_logic/layout/templates/images/layout/credit_cards.gif +0 -0
- data/lib/generators/scaffold_logic/layout/templates/images/layout/footer_bg.png +0 -0
- data/lib/generators/scaffold_logic/layout/templates/images/layout/h1_bg.png +0 -0
- data/lib/generators/scaffold_logic/layout/templates/images/layout/h2_bg.png +0 -0
- data/lib/generators/scaffold_logic/layout/templates/images/layout/h2_bg_for_table.png +0 -0
- data/lib/generators/scaffold_logic/layout/templates/images/layout/header_bg_grey.png +0 -0
- data/lib/generators/scaffold_logic/layout/templates/images/layout/header_bg_purple.png +0 -0
- data/lib/generators/scaffold_logic/layout/templates/images/layout/legend_bg.png +0 -0
- data/lib/generators/scaffold_logic/layout/templates/images/layout/menu_box_bg.png +0 -0
- data/lib/generators/scaffold_logic/layout/templates/images/layout/shadow_border.png +0 -0
- data/lib/generators/scaffold_logic/layout/templates/images/layout/shadow_border_2.png +0 -0
- data/lib/generators/scaffold_logic/layout/templates/images/layout/shadow_border_3.png +0 -0
- data/lib/generators/scaffold_logic/layout/templates/images/layout/shadow_border_4.png +0 -0
- data/lib/generators/scaffold_logic/layout/templates/images/layout/tab.png +0 -0
- data/lib/generators/scaffold_logic/layout/templates/images/layout/tab_active.png +0 -0
- data/lib/generators/scaffold_logic/layout/templates/images/layout/table_header.png +0 -0
- data/lib/generators/scaffold_logic/layout/templates/images/layout/text_field_bg.jpg +0 -0
- data/lib/generators/scaffold_logic/layout/templates/images/layout/text_field_error_bg.png +0 -0
- data/lib/generators/scaffold_logic/layout/templates/images/layout/th_bg.png +0 -0
- data/lib/generators/scaffold_logic/layout/templates/images/layout/th_bg_selected.png +0 -0
- data/lib/generators/scaffold_logic/layout/templates/images/src/black_bar.psd +0 -0
- data/lib/generators/scaffold_logic/layout/templates/images/src/branding.psd +0 -0
- data/lib/generators/scaffold_logic/layout/templates/images/src/legend_bg.psd +0 -0
- data/lib/generators/scaffold_logic/layout/templates/images/src/menu_icons.psd +0 -0
- data/lib/generators/scaffold_logic/layout/templates/layout.html.erb +49 -0
- data/lib/generators/scaffold_logic/layout/templates/layout_helper.rb +16 -0
- data/lib/generators/scaffold_logic/layout/templates/stylesheets/application.css +881 -0
- data/lib/generators/scaffold_logic/layout/templates/stylesheets/core.css +1146 -0
- data/lib/generators/scaffold_logic/layout/templates/stylesheets/core_ie.css +52 -0
- data/lib/generators/scaffold_logic/layout/templates/stylesheets/csshover3.htc +14 -0
- data/lib/generators/scaffold_logic/scaffold/USAGE +48 -0
- data/lib/generators/scaffold_logic/scaffold/scaffold_generator.rb +230 -0
- data/lib/generators/scaffold_logic/scaffold/templates/actions/create.rb +9 -0
- data/lib/generators/scaffold_logic/scaffold/templates/actions/destroy.rb +6 -0
- data/lib/generators/scaffold_logic/scaffold/templates/actions/edit.rb +3 -0
- data/lib/generators/scaffold_logic/scaffold/templates/actions/index.rb +3 -0
- data/lib/generators/scaffold_logic/scaffold/templates/actions/new.rb +3 -0
- data/lib/generators/scaffold_logic/scaffold/templates/actions/show.rb +3 -0
- data/lib/generators/scaffold_logic/scaffold/templates/actions/update.rb +9 -0
- data/lib/generators/scaffold_logic/scaffold/templates/controller.rb +7 -0
- data/lib/generators/scaffold_logic/scaffold/templates/helper.rb +2 -0
- data/lib/generators/scaffold_logic/scaffold/templates/migration.rb +16 -0
- data/lib/generators/scaffold_logic/scaffold/templates/model.rb +18 -0
- data/lib/generators/scaffold_logic/scaffold/templates/mongoid_model.rb +30 -0
- data/lib/generators/scaffold_logic/scaffold/templates/tests/rspec/actions/create.rb +10 -0
- data/lib/generators/scaffold_logic/scaffold/templates/tests/rspec/actions/destroy.rb +5 -0
- data/lib/generators/scaffold_logic/scaffold/templates/tests/rspec/actions/edit.rb +4 -0
- data/lib/generators/scaffold_logic/scaffold/templates/tests/rspec/actions/index.rb +5 -0
- data/lib/generators/scaffold_logic/scaffold/templates/tests/rspec/actions/new.rb +4 -0
- data/lib/generators/scaffold_logic/scaffold/templates/tests/rspec/actions/show.rb +4 -0
- data/lib/generators/scaffold_logic/scaffold/templates/tests/rspec/actions/update.rb +11 -0
- data/lib/generators/scaffold_logic/scaffold/templates/tests/rspec/controller.rb +12 -0
- data/lib/generators/scaffold_logic/scaffold/templates/tests/rspec/model.rb +5 -0
- data/lib/generators/scaffold_logic/scaffold/templates/tests/shoulda/actions/create.rb +13 -0
- data/lib/generators/scaffold_logic/scaffold/templates/tests/shoulda/actions/destroy.rb +8 -0
- data/lib/generators/scaffold_logic/scaffold/templates/tests/shoulda/actions/edit.rb +6 -0
- data/lib/generators/scaffold_logic/scaffold/templates/tests/shoulda/actions/index.rb +6 -0
- data/lib/generators/scaffold_logic/scaffold/templates/tests/shoulda/actions/new.rb +6 -0
- data/lib/generators/scaffold_logic/scaffold/templates/tests/shoulda/actions/show.rb +6 -0
- data/lib/generators/scaffold_logic/scaffold/templates/tests/shoulda/actions/update.rb +13 -0
- data/lib/generators/scaffold_logic/scaffold/templates/tests/shoulda/controller.rb +5 -0
- data/lib/generators/scaffold_logic/scaffold/templates/tests/shoulda/model.rb +7 -0
- data/lib/generators/scaffold_logic/scaffold/templates/tests/testunit/actions/create.rb +11 -0
- data/lib/generators/scaffold_logic/scaffold/templates/tests/testunit/actions/destroy.rb +6 -0
- data/lib/generators/scaffold_logic/scaffold/templates/tests/testunit/actions/edit.rb +4 -0
- data/lib/generators/scaffold_logic/scaffold/templates/tests/testunit/actions/index.rb +4 -0
- data/lib/generators/scaffold_logic/scaffold/templates/tests/testunit/actions/new.rb +4 -0
- data/lib/generators/scaffold_logic/scaffold/templates/tests/testunit/actions/show.rb +4 -0
- data/lib/generators/scaffold_logic/scaffold/templates/tests/testunit/actions/update.rb +11 -0
- data/lib/generators/scaffold_logic/scaffold/templates/tests/testunit/controller.rb +5 -0
- data/lib/generators/scaffold_logic/scaffold/templates/tests/testunit/model.rb +7 -0
- data/lib/generators/scaffold_logic/scaffold/templates/views/erb/_form.html.erb +39 -0
- data/lib/generators/scaffold_logic/scaffold/templates/views/erb/edit.html.erb +5 -0
- data/lib/generators/scaffold_logic/scaffold/templates/views/erb/index.html.erb +32 -0
- data/lib/generators/scaffold_logic/scaffold/templates/views/erb/new.html.erb +5 -0
- data/lib/generators/scaffold_logic/scaffold/templates/views/erb/show.html.erb +22 -0
- data/lib/scaffold_logic.rb +198 -0
- data/lib/scaffold_logic/data_import.rb +80 -0
- data/lib/scaffold_logic/form_helper.rb +148 -0
- data/lib/scaffold_logic/helper.rb +174 -0
- data/lib/scaffold_logic/menu_helper.rb +27 -0
- data/lib/scaffold_logic/tab_interface_helper.rb +125 -0
- data/scaffold_logic.gemspec +154 -0
- metadata +184 -0
@@ -0,0 +1,52 @@
|
|
1
|
+
/* @group General IE Workarounds */
|
2
|
+
|
3
|
+
fieldset.form_container {
|
4
|
+
clear: both;
|
5
|
+
width: 96%;
|
6
|
+
z-index: 0;
|
7
|
+
}
|
8
|
+
|
9
|
+
legend {
|
10
|
+
display: none;
|
11
|
+
}
|
12
|
+
|
13
|
+
.faux_legend {
|
14
|
+
border: 1px solid #999999;
|
15
|
+
padding: .5em;
|
16
|
+
background-color: #79984c;
|
17
|
+
color: #ffffff;
|
18
|
+
margin-top: -2.5em;
|
19
|
+
margin-left: -1.4em;
|
20
|
+
width: 26.5em;
|
21
|
+
font-weight: bold;
|
22
|
+
font-size: .8em;
|
23
|
+
text-transform: uppercase;
|
24
|
+
padding-left: 1em;
|
25
|
+
}
|
26
|
+
|
27
|
+
/* @end */
|
28
|
+
|
29
|
+
/* @group IE6 Workarounds */
|
30
|
+
|
31
|
+
/* Add support for hover, for nav menu */
|
32
|
+
*html body {
|
33
|
+
behavior:url("/stylesheets/csshover3.htc");
|
34
|
+
}
|
35
|
+
|
36
|
+
* html fieldset.form_container {
|
37
|
+
width: 92%;
|
38
|
+
margin-top: 20px !important;
|
39
|
+
z-index: 0;
|
40
|
+
}
|
41
|
+
|
42
|
+
* html p {
|
43
|
+
margin-bottom: 1.5em;
|
44
|
+
}
|
45
|
+
|
46
|
+
* html .faux_legend {
|
47
|
+
margin-top: -12px;
|
48
|
+
}
|
49
|
+
|
50
|
+
|
51
|
+
/* @end */
|
52
|
+
|
@@ -0,0 +1,14 @@
|
|
1
|
+
<public:attach event="ondocumentready" onevent="CSSHover()" />
|
2
|
+
<script>
|
3
|
+
/**
|
4
|
+
* Whatever:hover - V3.00.081222
|
5
|
+
* --------------------------------------------------------
|
6
|
+
* Author - Peter Nederlof, http://www.xs4all.nl/~peterned
|
7
|
+
* License - http://creativecommons.org/licenses/LGPL/2.1
|
8
|
+
* Packed - http://dean.edwards.name/packer
|
9
|
+
*
|
10
|
+
* howto: body { behavior:url("csshover3.htc"); }
|
11
|
+
*/
|
12
|
+
eval(function(p,a,c,k,e,r){e=function(c){return(c<a?'':e(parseInt(c/a)))+((c=c%a)>35?String.fromCharCode(c+29):c.toString(36))};if(!''.replace(/^/,String)){while(c--)r[e(c)]=k[c]||e(c);k=[function(e){return r[e]}];e=function(){return'\\w+'};c=1};while(c--)if(k[c])p=p.replace(new RegExp('\\b'+e(c)+'\\b','g'),k[c]);return p}('r.R=(8(){4 f=/(^|\\s)((([^a]([^ ]+)?)|(a([^#.][^ ]+)+)):(C|D|E))/i,S=/(.*?)\\:(C|D|E)/i,T=/[^:]+:([a-z-]+).*/i,U=/(\\.([a-V-W-]+):[a-z]+)|(:[a-z]+)/1c,X=/\\.([a-V-W-]*Y(C|D|E))/i,Z=/1d (5|6|7)/i,10=/1e/i;4 g=\'1f-\';4 h={p:[],t:{},11:8(){n(!Z.F(1g.1h)&&!10.F(r.12.1i))u;4 a=r.12.1j,l=a.v;w(4 i=0;i<l;i++){3.G(a[i])}},G:8(a){n(a.H){I{4 b=a.H,l=b.v;w(4 i=0;i<l;i++){3.G(a.H[i])}}J(13){}}I{4 c=a.1k,l=c.v;w(4 j=0;j<l;j++){3.14(c[j],a)}}J(13){}},14:8(a,b){4 c=a.1l;n(f.F(c)){4 d=a.K.1m,L=S.15(c)[1],M=c.N(T,\'Y$1\'),O=c.N(U,\'.$2\'+M),o=X.15(O)[1];4 e=L+o;n(!3.t[e]){b.16(L,g+o+\':1n(R(3, "\'+M+\'", "\'+o+\'"))\');3.t[e]=17}b.16(O,d)}},18:8(a,b,c){4 d=g+c;n(a.K[d]){a.K[d]=q}n(!a.x)a.x=[];n(!a.x[c]){a.x[c]=17;4 e=19 P(a,b,c);3.p.1o(e)}u b},y:8(){I{4 l=3.p.v;w(4 i=0;i<l;i++){3.p[i].y()}3.p=[];3.t={}}J(e){}}};r.Q(\'1p\',8(){h.y()});4 k={1q:{9:\'1r\',m:\'1s\'},1t:{9:\'1u\',m:\'1v\'},1a:{9:\'1a\',m:\'1w\'}};8 P(a,b,c){3.A=a;3.B=b;4 d=19 1x(\'(^|\\\\s)\'+c+\'(\\\\s|$)\',\'g\');3.9=8(){a.o+=\' \'+c};3.m=8(){a.o=a.o.N(d,\' \')};a.Q(k[b].9,3.9);a.Q(k[b].m,3.m)}P.1y={y:8(){3.A.1b(k[3.B].9,3.9);3.A.1b(k[3.B].m,3.m);3.9=q;3.m=q;3.A=q;3.B=q}};u 8(a,b,c){n(a){u h.18(a,b,c)}1z{h.11()}}})();',62,98,'|||this|var||||function|activator|||||||||||||deactivator|if|className|elements|null|window||callbacks|return|length|for|csshover|unload||node|type|hover|active|focus|test|parseStylesheet|imports|try|catch|style|affected|pseudo|replace|newSelect|CSSHoverElement|attachEvent|CSSHover|REG_AFFECTED|REG_PSEUDO|REG_SELECT|z0|9_|REG_CLASS|on|REG_MSIE|REG_COMPAT|init|document|securityException|parseCSSRule|exec|addRule|true|patch|new|onfocus|detachEvent|gi|msie|backcompat|csh|navigator|userAgent|compatMode|styleSheets|rules|selectorText|cssText|expression|push|onbeforeunload|onhover|onmouseenter|onmouseleave|onactive|onmousedown|onmouseup|onblur|RegExp|prototype|else'.split('|'),0,{}));
|
13
|
+
|
14
|
+
</script>
|
@@ -0,0 +1,48 @@
|
|
1
|
+
Description:
|
2
|
+
Scaffolds an entire resource, from model and migration to controller and
|
3
|
+
views. The resource is ready to use as a starting point for your restful,
|
4
|
+
resource-oriented application. Tests or specs are also generated depending
|
5
|
+
on if you have a "spec" directory or not.
|
6
|
+
|
7
|
+
Usage:
|
8
|
+
Pass the name of the model, either CamelCased or under_scored, as the first
|
9
|
+
argument along with an optional list of attribute pairs and controller actions.
|
10
|
+
|
11
|
+
If no controller actions are specified, they will default to index, show,
|
12
|
+
new, create, edit, update, and destroy.
|
13
|
+
|
14
|
+
IMPORTANT: If no attribute pairs are specified, no model will be generated.
|
15
|
+
It will try to determine the attributes from an existing model.
|
16
|
+
|
17
|
+
Attribute pairs are column_name:sql_type arguments specifying the
|
18
|
+
model's attributes. Timestamps are added by default, so you don't have to
|
19
|
+
specify them by hand as 'created_at:datetime updated_at:datetime'.
|
20
|
+
|
21
|
+
For example, `scaffold_logic:scaffold post name:string content:text hidden:boolean`
|
22
|
+
gives you a model with those three attributes, a controller that handles
|
23
|
+
the create/show/update/destroy, forms to create and edit your posts, and
|
24
|
+
an index that lists them all, as well as a map.resources :posts
|
25
|
+
declaration in config/routes.rb.
|
26
|
+
|
27
|
+
Adding an "!" in the mix of arguments will invert the passed controller
|
28
|
+
actions. This will include all 7 controller actitons except the ones
|
29
|
+
mentioned. This option doesn't affect model attributes.
|
30
|
+
|
31
|
+
Examples:
|
32
|
+
rails generate scaffold_logic:scaffold post
|
33
|
+
|
34
|
+
Will create a controller called "posts" it will contain all seven
|
35
|
+
CRUD actions along with the views. A model will NOT be created,
|
36
|
+
instead it will look for an existing model and use those attributes.
|
37
|
+
|
38
|
+
rails generate scaffold_logic:scaffold post name:string content:text index new edit
|
39
|
+
|
40
|
+
Will create a Post model and migration file with the name and content
|
41
|
+
attributes. It will also create a controller with index, new, create,
|
42
|
+
edit, and update actions. Notice the create and update actions are
|
43
|
+
added automatically with new and edit.
|
44
|
+
|
45
|
+
rails generate scaffold_logic:scaffold post ! show new
|
46
|
+
|
47
|
+
Creates a posts controller (no model) with index, edit, update, and
|
48
|
+
destroy actions.
|
@@ -0,0 +1,230 @@
|
|
1
|
+
require File.expand_path("../../../../scaffold_logic", __FILE__)
|
2
|
+
require 'rails/generators/migration'
|
3
|
+
require 'rails/generators/generated_attribute'
|
4
|
+
|
5
|
+
module ScaffoldLogic
|
6
|
+
module Generators
|
7
|
+
class ScaffoldGenerator < Rails::Generators::Base
|
8
|
+
include Rails::Generators::Migration
|
9
|
+
no_tasks { attr_accessor :model_name, :model_attributes, :controller_actions }
|
10
|
+
|
11
|
+
argument :model_name, :type => :string, :required => true, :banner => 'ModelName'
|
12
|
+
argument :args_for_c_m, :type => :array, :default => [], :banner => 'controller_actions and model:attributes'
|
13
|
+
|
14
|
+
class_option :skip_model, :desc => 'Don\'t generate a model or migration file.', :type => :boolean
|
15
|
+
class_option :skip_migration, :desc => 'Dont generate migration file for model.', :type => :boolean
|
16
|
+
class_option :skip_timestamps, :desc => 'Don\'t add timestamps to migration file.', :type => :boolean
|
17
|
+
class_option :skip_controller, :desc => 'Don\'t generate controller, helper, or views.', :type => :boolean
|
18
|
+
class_option :invert, :desc => 'Generate all controller actions except these mentioned.', :type => :boolean
|
19
|
+
class_option :haml, :desc => 'Generate HAML views instead of ERB.', :type => :boolean
|
20
|
+
class_option :mongoid, :desc => 'Use Mongoid for models instead of AR.', :type => :boolean
|
21
|
+
class_option :testunit, :desc => 'Use test/unit for test files.', :group => 'Test framework', :type => :boolean
|
22
|
+
class_option :rspec, :desc => 'Use RSpec for test files.', :group => 'Test framework', :type => :boolean
|
23
|
+
class_option :shoulda, :desc => 'Use shoulda for test files.', :group => 'Test framework', :type => :boolean
|
24
|
+
|
25
|
+
def initialize(*args, &block)
|
26
|
+
super
|
27
|
+
|
28
|
+
@controller_actions = []
|
29
|
+
@model_attributes = []
|
30
|
+
@skip_model = options.skip_model?
|
31
|
+
@invert_actions = options.invert?
|
32
|
+
@mongoid = options.mongoid
|
33
|
+
|
34
|
+
args_for_c_m.each do |arg|
|
35
|
+
if arg == '!'
|
36
|
+
@invert_actions = true
|
37
|
+
elsif arg.include?(':')
|
38
|
+
@model_attributes << Rails::Generators::GeneratedAttribute.new(*arg.split(':'))
|
39
|
+
else
|
40
|
+
@controller_actions << arg
|
41
|
+
@controller_actions << 'create' if arg == 'new'
|
42
|
+
@controller_actions << 'update' if arg == 'edit'
|
43
|
+
end
|
44
|
+
end
|
45
|
+
|
46
|
+
@controller_actions.uniq!
|
47
|
+
@model_attributes.uniq!
|
48
|
+
|
49
|
+
if @invert_actions || @controller_actions.empty?
|
50
|
+
@controller_actions = all_actions - @controller_actions
|
51
|
+
end
|
52
|
+
|
53
|
+
if @model_attributes.empty?
|
54
|
+
@skip_model = true # skip model if no attributes
|
55
|
+
if model_exists?
|
56
|
+
model_columns_for_attributes.each do |column|
|
57
|
+
@model_attributes << Rails::Generators::GeneratedAttribute.new(column.name.to_s, column.type.to_s)
|
58
|
+
end
|
59
|
+
else
|
60
|
+
@model_attributes << Rails::Generators::GeneratedAttribute.new('name', 'string')
|
61
|
+
end
|
62
|
+
end
|
63
|
+
end
|
64
|
+
|
65
|
+
def create_model
|
66
|
+
unless @skip_model
|
67
|
+
if @mongoid
|
68
|
+
template 'mongoid_model.rb', "app/models/#{singular_name}.rb"
|
69
|
+
else
|
70
|
+
template 'model.rb', "app/models/#{singular_name}.rb"
|
71
|
+
end
|
72
|
+
template "tests/rspec/model.rb", "spec/models/#{singular_name}_spec.rb"
|
73
|
+
end
|
74
|
+
end
|
75
|
+
|
76
|
+
def create_migration
|
77
|
+
unless @skip_model || options.skip_migration? || @mongoid
|
78
|
+
migration_template 'migration.rb', "db/migrate/create_#{plural_name}.rb"
|
79
|
+
end
|
80
|
+
end
|
81
|
+
|
82
|
+
def create_controller
|
83
|
+
unless options.skip_controller?
|
84
|
+
template 'controller.rb', "app/controllers/#{plural_name}_controller.rb"
|
85
|
+
|
86
|
+
controller_actions.each do |action|
|
87
|
+
if %w[index show new edit].include?(action) # Actions with templates
|
88
|
+
template "views/#{view_language}/#{action}.html.#{view_language}", "app/views/#{plural_name}/#{action}.html.#{view_language}"
|
89
|
+
end
|
90
|
+
end
|
91
|
+
|
92
|
+
if form_partial?
|
93
|
+
template "views/#{view_language}/_form.html.#{view_language}", "app/views/#{plural_name}/_form.html.#{view_language}"
|
94
|
+
end
|
95
|
+
|
96
|
+
route "resources #{plural_name.to_sym.inspect}"
|
97
|
+
|
98
|
+
template "tests/#{test_framework}/controller.rb", "spec/controllers/#{plural_name}_controller_spec.rb"
|
99
|
+
end
|
100
|
+
end
|
101
|
+
|
102
|
+
private
|
103
|
+
|
104
|
+
def form_partial?
|
105
|
+
actions? :new, :edit
|
106
|
+
end
|
107
|
+
|
108
|
+
def all_actions
|
109
|
+
%w[index show new create edit update destroy]
|
110
|
+
end
|
111
|
+
|
112
|
+
def action?(name)
|
113
|
+
controller_actions.include? name.to_s
|
114
|
+
end
|
115
|
+
|
116
|
+
def actions?(*names)
|
117
|
+
names.all? { |name| action? name }
|
118
|
+
end
|
119
|
+
|
120
|
+
def singular_name
|
121
|
+
model_name.underscore
|
122
|
+
end
|
123
|
+
|
124
|
+
def plural_name
|
125
|
+
model_name.underscore.pluralize
|
126
|
+
end
|
127
|
+
|
128
|
+
def class_name
|
129
|
+
model_name.camelize
|
130
|
+
end
|
131
|
+
|
132
|
+
def plural_class_name
|
133
|
+
plural_name.camelize
|
134
|
+
end
|
135
|
+
|
136
|
+
def controller_methods(dir_name)
|
137
|
+
controller_actions.map do |action|
|
138
|
+
read_template("#{dir_name}/#{action}.rb")
|
139
|
+
end.join("\n").strip
|
140
|
+
end
|
141
|
+
|
142
|
+
def render_form
|
143
|
+
if form_partial?
|
144
|
+
if options.haml?
|
145
|
+
"= render 'form'"
|
146
|
+
else
|
147
|
+
"<%= render 'form' %>"
|
148
|
+
end
|
149
|
+
else
|
150
|
+
read_template("views/#{view_language}/_form.html.#{view_language}")
|
151
|
+
end
|
152
|
+
end
|
153
|
+
|
154
|
+
def items_path(suffix = 'path')
|
155
|
+
if action? :index
|
156
|
+
"#{plural_name}_#{suffix}"
|
157
|
+
else
|
158
|
+
"root_#{suffix}"
|
159
|
+
end
|
160
|
+
end
|
161
|
+
|
162
|
+
def item_path(suffix = 'path')
|
163
|
+
if action? :show
|
164
|
+
"@#{singular_name}"
|
165
|
+
else
|
166
|
+
items_path(suffix)
|
167
|
+
end
|
168
|
+
end
|
169
|
+
|
170
|
+
def item_path_for_spec(suffix = 'path')
|
171
|
+
if action? :show
|
172
|
+
"#{singular_name}_#{suffix}(assigns[:#{singular_name}])"
|
173
|
+
else
|
174
|
+
items_path(suffix)
|
175
|
+
end
|
176
|
+
end
|
177
|
+
|
178
|
+
def item_path_for_test(suffix = 'path')
|
179
|
+
if action? :show
|
180
|
+
"#{singular_name}_#{suffix}(assigns(:#{singular_name}))"
|
181
|
+
else
|
182
|
+
items_path(suffix)
|
183
|
+
end
|
184
|
+
end
|
185
|
+
|
186
|
+
def model_columns_for_attributes
|
187
|
+
class_name.constantize.columns.reject do |column|
|
188
|
+
column.name.to_s =~ /^(id|created_at|updated_at)$/
|
189
|
+
end
|
190
|
+
end
|
191
|
+
|
192
|
+
def view_language
|
193
|
+
options.haml? ? 'haml' : 'erb'
|
194
|
+
end
|
195
|
+
|
196
|
+
def test_framework
|
197
|
+
return @test_framework if defined?(@test_framework)
|
198
|
+
return @test_framework = :rspec
|
199
|
+
end
|
200
|
+
|
201
|
+
def default_test_framework
|
202
|
+
:rspec
|
203
|
+
end
|
204
|
+
|
205
|
+
def model_exists?
|
206
|
+
File.exist? destination_path("app/models/#{singular_name}.rb")
|
207
|
+
end
|
208
|
+
|
209
|
+
def read_template(relative_path)
|
210
|
+
ERB.new(File.read(find_in_source_paths(relative_path)), nil, '-').result(binding)
|
211
|
+
end
|
212
|
+
|
213
|
+
def destination_path(path)
|
214
|
+
File.join(destination_root, path)
|
215
|
+
end
|
216
|
+
|
217
|
+
# FIXME: Should be proxied to ActiveRecord::Generators::Base
|
218
|
+
# Implement the required interface for Rails::Generators::Migration.
|
219
|
+
def self.next_migration_number(dirname) #:nodoc:
|
220
|
+
if ActiveRecord::Base.timestamped_migrations
|
221
|
+
Time.now.utc.strftime("%Y%m%d%H%M%S")
|
222
|
+
else
|
223
|
+
"%.3d" % (current_migration_number(dirname) + 1)
|
224
|
+
end
|
225
|
+
end
|
226
|
+
end
|
227
|
+
end
|
228
|
+
end
|
229
|
+
|
230
|
+
ScaffoldLogic::Generators::ScaffoldGenerator.source_root("#{Gem.searcher.find('scaffold_logic').full_gem_path}/lib/generators/scaffold_logic/scaffold/templates/")
|
@@ -0,0 +1,9 @@
|
|
1
|
+
def create
|
2
|
+
@<%= singular_name %> = <%= class_name %>.new(params[:<%= singular_name %>])
|
3
|
+
if @<%= singular_name %>.save
|
4
|
+
flash[:notice] = 'Successfully created <%= model_name.underscore.humanize.downcase %>.'
|
5
|
+
redirect_to <%= item_path('url') %>
|
6
|
+
else
|
7
|
+
render :action => 'new'
|
8
|
+
end
|
9
|
+
end
|
@@ -0,0 +1,9 @@
|
|
1
|
+
def update
|
2
|
+
@<%= singular_name %> = <%= class_name %>.find(params[:id])
|
3
|
+
if @<%= singular_name %>.update_attributes(params[:<%= singular_name %>])
|
4
|
+
flash[:notice] = 'Successfully updated <%= model_name.underscore.humanize.downcase %>.'
|
5
|
+
redirect_to <%= item_path('url') %>
|
6
|
+
else
|
7
|
+
render :action => 'edit'
|
8
|
+
end
|
9
|
+
end
|
@@ -0,0 +1,7 @@
|
|
1
|
+
class <%= plural_class_name %>Controller < ApplicationController
|
2
|
+
before_filter :authenticate_user! if Object.const_defined?('Devise')
|
3
|
+
load_and_authorize_resource if Object.const_defined?('CanCan')
|
4
|
+
|
5
|
+
# CRUD ===========================================================================================
|
6
|
+
<%= controller_methods :actions %>
|
7
|
+
end
|
@@ -0,0 +1,16 @@
|
|
1
|
+
class Create<%= plural_class_name %> < ActiveRecord::Migration
|
2
|
+
def self.up
|
3
|
+
create_table :<%= plural_name %> do |t|
|
4
|
+
<%- for attribute in model_attributes -%>
|
5
|
+
t.<%= attribute.type %> :<%= attribute.name %>
|
6
|
+
<%- end -%>
|
7
|
+
<%- unless options[:skip_timestamps] -%>
|
8
|
+
t.timestamps
|
9
|
+
<%- end -%>
|
10
|
+
end
|
11
|
+
end
|
12
|
+
|
13
|
+
def self.down
|
14
|
+
drop_table :<%= plural_name %>
|
15
|
+
end
|
16
|
+
end
|
@@ -0,0 +1,18 @@
|
|
1
|
+
class <%= class_name %> < ActiveRecord::Base
|
2
|
+
# Constants ======================================================================================
|
3
|
+
SORTABLE_COLUMNS = ['id']
|
4
|
+
|
5
|
+
# Scopes =========================================================================================
|
6
|
+
|
7
|
+
# Relationships ==================================================================================
|
8
|
+
|
9
|
+
# Behavior =======================================================================================
|
10
|
+
|
11
|
+
# Callbacks ======================================================================================
|
12
|
+
|
13
|
+
# Validations ====================================================================================
|
14
|
+
|
15
|
+
# Class methods ==================================================================================
|
16
|
+
|
17
|
+
# Instance methods ===============================================================================
|
18
|
+
end
|