dust-generators 0.2.8 → 0.3.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (121) hide show
  1. data/lib/dust/version.rb +2 -2
  2. data/lib/generators/dust/albums/templates/app/views/albums/show.html.haml +1 -1
  3. data/lib/generators/dust/scaffold/scaffold_generator.rb +24 -24
  4. data/lib/generators/dust/scaffold/templates/actions/create.rb +1 -1
  5. data/lib/generators/dust/scaffold/templates/actions/destroy.rb +2 -2
  6. data/lib/generators/dust/scaffold/templates/actions/edit.rb +1 -1
  7. data/lib/generators/dust/scaffold/templates/actions/index.rb +1 -1
  8. data/lib/generators/dust/scaffold/templates/actions/new.rb +1 -1
  9. data/lib/generators/dust/scaffold/templates/actions/show.rb +1 -1
  10. data/lib/generators/dust/scaffold/templates/actions/update.rb +2 -2
  11. data/lib/generators/dust/scaffold/templates/controller.rb +3 -2
  12. data/lib/generators/dust/scaffold/templates/migration.rb +2 -2
  13. data/lib/generators/dust/scaffold/templates/model.rb +13 -11
  14. data/lib/generators/dust/scaffold/templates/view_controller.rb +8 -6
  15. data/lib/generators/dust/scaffold/templates/views/front_end/haml/index.html.haml +6 -5
  16. data/lib/generators/dust/scaffold/templates/views/front_end/haml/show.html.haml +11 -11
  17. data/lib/generators/dust/scaffold/templates/views/haml/_form.html.haml +1 -1
  18. data/lib/generators/dust/scaffold/templates/views/haml/_search.html.haml +1 -1
  19. data/lib/generators/dust/scaffold/templates/views/haml/index.html.haml +2 -2
  20. data/lib/generators/dust/scaffold/templates/views/haml/show.html.haml +1 -1
  21. metadata +49 -174
  22. data/rails_generators/dust_albums/USAGE +0 -6
  23. data/rails_generators/dust_albums/dust_albums_generator.rb +0 -196
  24. data/rails_generators/dust_albums/templates/README +0 -5
  25. data/rails_generators/dust_albums/templates/app/controllers/albums_controller.rb +0 -56
  26. data/rails_generators/dust_albums/templates/app/controllers/photos_controller.rb +0 -89
  27. data/rails_generators/dust_albums/templates/app/controllers/view_albums_controller.rb +0 -17
  28. data/rails_generators/dust_albums/templates/app/helpers/albums_helper.rb +0 -2
  29. data/rails_generators/dust_albums/templates/app/helpers/photos_helper.rb +0 -2
  30. data/rails_generators/dust_albums/templates/app/helpers/view_albums_helper.rb +0 -2
  31. data/rails_generators/dust_albums/templates/app/models/album.rb +0 -42
  32. data/rails_generators/dust_albums/templates/app/models/photo.rb +0 -18
  33. data/rails_generators/dust_albums/templates/app/views/albums/_form.html.erb +0 -52
  34. data/rails_generators/dust_albums/templates/app/views/albums/_search.html.erb +0 -6
  35. data/rails_generators/dust_albums/templates/app/views/albums/_upload_script.html.erb +0 -37
  36. data/rails_generators/dust_albums/templates/app/views/albums/edit.html.erb +0 -5
  37. data/rails_generators/dust_albums/templates/app/views/albums/index.html.erb +0 -61
  38. data/rails_generators/dust_albums/templates/app/views/albums/manage.html.erb +0 -65
  39. data/rails_generators/dust_albums/templates/app/views/albums/new.html.erb +0 -6
  40. data/rails_generators/dust_albums/templates/app/views/albums/show.html.erb +0 -56
  41. data/rails_generators/dust_albums/templates/app/views/albums/show.js.erb +0 -1
  42. data/rails_generators/dust_albums/templates/app/views/photos/_form.html.erb +0 -23
  43. data/rails_generators/dust_albums/templates/app/views/photos/_photo.html.erb +0 -25
  44. data/rails_generators/dust_albums/templates/app/views/photos/_search.html.erb +0 -6
  45. data/rails_generators/dust_albums/templates/app/views/photos/array.js.erb +0 -3
  46. data/rails_generators/dust_albums/templates/app/views/photos/edit.html.erb +0 -28
  47. data/rails_generators/dust_albums/templates/app/views/photos/index.html.erb +0 -85
  48. data/rails_generators/dust_albums/templates/app/views/photos/new.html.erb +0 -7
  49. data/rails_generators/dust_albums/templates/app/views/photos/show.html.erb +0 -26
  50. data/rails_generators/dust_albums/templates/app/views/photos/show.js.erb +0 -9
  51. data/rails_generators/dust_albums/templates/app/views/view_albums/index.html.erb +0 -31
  52. data/rails_generators/dust_albums/templates/app/views/view_albums/show.html.erb +0 -31
  53. data/rails_generators/dust_albums/templates/images/browse.png +0 -0
  54. data/rails_generators/dust_albums/templates/images/cancel.png +0 -0
  55. data/rails_generators/dust_albums/templates/images/save_position.png +0 -0
  56. data/rails_generators/dust_albums/templates/images/upload.png +0 -0
  57. data/rails_generators/dust_albums/templates/initializers/flash_session_cookie_middleware.rb +0 -17
  58. data/rails_generators/dust_albums/templates/initializers/session_store_middleware.rb +0 -1
  59. data/rails_generators/dust_albums/templates/javascript/dragsort.js +0 -288
  60. data/rails_generators/dust_albums/templates/javascript/dust_album.js +0 -28
  61. data/rails_generators/dust_albums/templates/javascript/uploadify/jquery.uploadify.v2.1.0.js +0 -258
  62. data/rails_generators/dust_albums/templates/javascript/uploadify/swfobject.js +0 -4
  63. data/rails_generators/dust_albums/templates/javascript/uploadify/uploadify.swf +0 -0
  64. data/rails_generators/dust_albums/templates/migration/albums_migration.rb +0 -39
  65. data/rails_generators/dust_albums/templates/stylesheets/dust_album.css +0 -16
  66. data/rails_generators/dust_albums/templates/stylesheets/dust_album_app.css +0 -15
  67. data/rails_generators/dust_albums/templates/stylesheets/uploadify.css +0 -84
  68. data/rails_generators/dust_config/USAGE +0 -23
  69. data/rails_generators/dust_config/dust_config_generator.rb +0 -32
  70. data/rails_generators/dust_config/templates/config.yml +0 -8
  71. data/rails_generators/dust_config/templates/load_config.rb +0 -2
  72. data/rails_generators/dust_scaffold/USAGE +0 -51
  73. data/rails_generators/dust_scaffold/dust_scaffold_generator.rb +0 -291
  74. data/rails_generators/dust_scaffold/templates/actions/create.rb +0 -9
  75. data/rails_generators/dust_scaffold/templates/actions/destroy.rb +0 -6
  76. data/rails_generators/dust_scaffold/templates/actions/edit.rb +0 -3
  77. data/rails_generators/dust_scaffold/templates/actions/index.rb +0 -3
  78. data/rails_generators/dust_scaffold/templates/actions/new.rb +0 -3
  79. data/rails_generators/dust_scaffold/templates/actions/show.rb +0 -3
  80. data/rails_generators/dust_scaffold/templates/actions/update.rb +0 -9
  81. data/rails_generators/dust_scaffold/templates/controller.rb +0 -9
  82. data/rails_generators/dust_scaffold/templates/fixtures.yml +0 -9
  83. data/rails_generators/dust_scaffold/templates/helper.rb +0 -2
  84. data/rails_generators/dust_scaffold/templates/migration.rb +0 -20
  85. data/rails_generators/dust_scaffold/templates/model.rb +0 -37
  86. data/rails_generators/dust_scaffold/templates/tests/rspec/actions/create.rb +0 -11
  87. data/rails_generators/dust_scaffold/templates/tests/rspec/actions/destroy.rb +0 -6
  88. data/rails_generators/dust_scaffold/templates/tests/rspec/actions/edit.rb +0 -4
  89. data/rails_generators/dust_scaffold/templates/tests/rspec/actions/index.rb +0 -4
  90. data/rails_generators/dust_scaffold/templates/tests/rspec/actions/new.rb +0 -4
  91. data/rails_generators/dust_scaffold/templates/tests/rspec/actions/show.rb +0 -4
  92. data/rails_generators/dust_scaffold/templates/tests/rspec/actions/update.rb +0 -11
  93. data/rails_generators/dust_scaffold/templates/tests/rspec/controller.rb +0 -8
  94. data/rails_generators/dust_scaffold/templates/tests/rspec/model.rb +0 -7
  95. data/rails_generators/dust_scaffold/templates/tests/shoulda/actions/create.rb +0 -13
  96. data/rails_generators/dust_scaffold/templates/tests/shoulda/actions/destroy.rb +0 -8
  97. data/rails_generators/dust_scaffold/templates/tests/shoulda/actions/edit.rb +0 -6
  98. data/rails_generators/dust_scaffold/templates/tests/shoulda/actions/index.rb +0 -6
  99. data/rails_generators/dust_scaffold/templates/tests/shoulda/actions/new.rb +0 -6
  100. data/rails_generators/dust_scaffold/templates/tests/shoulda/actions/show.rb +0 -6
  101. data/rails_generators/dust_scaffold/templates/tests/shoulda/actions/update.rb +0 -13
  102. data/rails_generators/dust_scaffold/templates/tests/shoulda/controller.rb +0 -5
  103. data/rails_generators/dust_scaffold/templates/tests/shoulda/model.rb +0 -7
  104. data/rails_generators/dust_scaffold/templates/tests/testunit/actions/create.rb +0 -11
  105. data/rails_generators/dust_scaffold/templates/tests/testunit/actions/destroy.rb +0 -6
  106. data/rails_generators/dust_scaffold/templates/tests/testunit/actions/edit.rb +0 -4
  107. data/rails_generators/dust_scaffold/templates/tests/testunit/actions/index.rb +0 -4
  108. data/rails_generators/dust_scaffold/templates/tests/testunit/actions/new.rb +0 -4
  109. data/rails_generators/dust_scaffold/templates/tests/testunit/actions/show.rb +0 -4
  110. data/rails_generators/dust_scaffold/templates/tests/testunit/actions/update.rb +0 -11
  111. data/rails_generators/dust_scaffold/templates/tests/testunit/controller.rb +0 -5
  112. data/rails_generators/dust_scaffold/templates/tests/testunit/model.rb +0 -7
  113. data/rails_generators/dust_scaffold/templates/view_controller.rb +0 -17
  114. data/rails_generators/dust_scaffold/templates/views/erb/_form.html.erb +0 -16
  115. data/rails_generators/dust_scaffold/templates/views/erb/_search.html.erb +0 -6
  116. data/rails_generators/dust_scaffold/templates/views/erb/edit.html.erb +0 -4
  117. data/rails_generators/dust_scaffold/templates/views/erb/index.html.erb +0 -24
  118. data/rails_generators/dust_scaffold/templates/views/erb/new.html.erb +0 -5
  119. data/rails_generators/dust_scaffold/templates/views/erb/show.html.erb +0 -23
  120. data/rails_generators/dust_scaffold/templates/views/front_end/index.html.erb +0 -14
  121. data/rails_generators/dust_scaffold/templates/views/front_end/show.html.erb +0 -17
@@ -1,15 +0,0 @@
1
- /*================================================ ALBUMS =======================================================*/
2
-
3
- #uploadify h3 { display:block; text-align:center; color:#767D87; font-weight: normal; }
4
-
5
- tr.even td { background: #fff;}
6
-
7
- #uploads{overflow:hidden; width: 845px; margin:0 auto}
8
- .<%=child_singular_name%> { text-align:center; float:left; width:130px; height: 175px; margin: 5px; }
9
- .<%=parent_singular_name%>_thumb{ width: 288px; height:125px; margin:10px; float:left }
10
- .<%=parent_singular_name%>_thumb a{ text-align:left; }
11
-
12
- table.<%=child_plural_name%>{ margin: 0 auto; width:100%; border:1px solid #C5CCD6; }
13
- tr th { background: #D3DAE6; padding:5px; }
14
- tr.even td { background: #D3DAE6; padding:15px;}
15
- tr.odd td { padding:15px;}
@@ -1,84 +0,0 @@
1
- /*
2
- Uploadify v2.1.0
3
- Release Date: August 24, 2009
4
-
5
- Copyright (c) 2009 Ronnie Garcia, Travis Nickels
6
-
7
- Permission is hereby granted, free of charge, to any person obtaining a copy
8
- of this software and associated documentation files (the "Software"), to deal
9
- in the Software without restriction, including without limitation the rights
10
- to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
11
- copies of the Software, and to permit persons to whom the Software is
12
- furnished to do so, subject to the following conditions:
13
-
14
- The above copyright notice and this permission notice shall be included in
15
- all copies or substantial portions of the Software.
16
-
17
- THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
18
- IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
19
- FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
20
- AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
21
- LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
22
- OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
23
- THE SOFTWARE.
24
- */
25
- .uploadifyQueue {
26
- position:relative;
27
- top:30px;
28
- left: -14px;
29
- width: 238px;
30
- padding: 0;
31
- }
32
-
33
- .uploadifyButtons {
34
- width: 207px;
35
- margin: 5px auto;
36
- position:relative;
37
- }
38
-
39
- .uploadifyButtons #<%=child_singular_name%>_submit {
40
- position: absolute;
41
- right: 0px ;
42
- }
43
-
44
- .uploadifyButtons object {
45
- position: absolute;
46
- left: 0px ;
47
- }
48
-
49
-
50
- .uploadifyQueueItem {
51
- font: 11px Helvetica, Arial, sans-serif;
52
- border: 1px solid #E5E5E5;
53
- background-color: #F5F5F5;
54
- margin: 5px 0px ;
55
- padding: 10px;
56
- width: 215px;
57
- }
58
- .uploadifyError {
59
- border: 2px solid #FBCBBC !important;
60
- background-color: #FDE5DD !important;
61
- }
62
- .uploadifyQueueItem .cancel {
63
- float: right;
64
- }
65
- .uploadifyProgress {
66
- background-color: #FFFFFF;
67
- border-top: 1px solid #808080;
68
- border-left: 1px solid #808080;
69
- border-right: 1px solid #C5C5C5;
70
- border-bottom: 1px solid #C5C5C5;
71
- margin-top: 10px;
72
- width: 100%;
73
- }
74
- .uploadifyProgressBar {
75
- background-color: #545C6D;
76
- width: 1px;
77
- height: 3px;
78
- }
79
-
80
- .cancel img {
81
- border: none;
82
- padding: none;
83
- margin: none;
84
- }
@@ -1,23 +0,0 @@
1
- Description:
2
- The dust_config generator creates YAML file in your config
3
- directory and an initializer to load this config. The config has a
4
- separate section for each environment. This is a great place to put
5
- any config settings you don't want in your app.
6
-
7
- The config is loaded into a constant called APP_CONFIG by default,
8
- this changes depending on the name you choose to pass the generator.
9
- Use this constant to access the config settings like this.
10
-
11
- APP_CONFIG[:some_setting]
12
-
13
-
14
- Examples:
15
- script/generate dust_config
16
-
17
- Config: config/app_config.yml
18
- Initializer: config/initializers/load_app_config.rb
19
-
20
- script/generate dust_config passwords
21
-
22
- Config: config/passwords_config.yml
23
- Initializer: config/initializers/load_passwords_config.rb
@@ -1,32 +0,0 @@
1
- class DustConfigGenerator < Rails::Generator::Base
2
- def initialize(runtime_args, runtime_options = {})
3
- super
4
- @name = @args.first || 'app'
5
- end
6
-
7
- def manifest
8
- record do |m|
9
- m.directory 'config/initializers'
10
-
11
- m.template "load_config.rb", "config/initializers/load_#{file_name}_config.rb"
12
- m.file "config.yml", "config/#{file_name}_config.yml"
13
- end
14
- end
15
-
16
- def file_name
17
- @name.underscore
18
- end
19
-
20
- def constant_name
21
- @name.underscore.upcase
22
- end
23
-
24
- protected
25
- def banner
26
- <<-EOS
27
- Creates config and loader files.
28
-
29
- USAGE: #{$0} #{spec.name} [config_name]
30
- EOS
31
- end
32
- end
@@ -1,8 +0,0 @@
1
- development:
2
- domain: localhost:3000
3
-
4
- test:
5
- domain: test.host
6
-
7
- production:
8
- domain: example.com
@@ -1,2 +0,0 @@
1
- raw_config = File.read(RAILS_ROOT + "/config/<%= file_name %>_config.yml")
2
- <%= constant_name %>_CONFIG = YAML.load(raw_config)[RAILS_ENV].symbolize_keys
@@ -1,51 +0,0 @@
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
- IMPORTANT: This generator uses the "title" helper method which is generated
8
- by the dust_layout generator. You may want to run that generator first.
9
-
10
- Usage:
11
- Pass the name of the model, either CamelCased or under_scored, as the first
12
- argument along with an optional list of attribute pairs and controller actions.
13
-
14
- If no controller actions are specified, they will default to index, show,
15
- new, create, edit, update, and destroy.
16
-
17
- IMPORTANT: If no attribute pairs are specified, no model will be generated.
18
- It will try to determine the attributes from an existing model.
19
-
20
- Attribute pairs are column_name:sql_type arguments specifying the
21
- model's attributes. Timestamps are added by default, so you don't have to
22
- specify them by hand as 'created_at:datetime updated_at:datetime'.
23
-
24
- For example, `dust_scaffold post name:string content:text hidden:boolean`
25
- gives you a model with those three attributes, a controller that handles
26
- the create/show/update/destroy, forms to create and edit your posts, and
27
- an index that lists them all, as well as a map.resources :posts
28
- declaration in config/routes.rb.
29
-
30
- Adding an "!" in the mix of arguments will invert the passed controller
31
- actions. This will include all 7 controller actitons except the ones
32
- mentioned. This option doesn't affect model attributes.
33
-
34
- Examples:
35
- script/generate dust_scaffold post
36
-
37
- Will create a controller called "posts" it will contain all seven
38
- CRUD actions along with the views. A model will NOT be created,
39
- instead it will look for an existing model and use those attributes.
40
-
41
- script/generate dust_scaffold post name:string content:text index new edit
42
-
43
- Will create a Post model and migration file with the name and content
44
- attributes. It will also create a controller with index, new, create,
45
- edit, and update actions. Notice the create and update actions are
46
- added automatically with new and edit.
47
-
48
- script/generate dust_scaffold post ! show new
49
-
50
- Creates a posts controller (no model) with index, edit, update, and
51
- destroy actions.
@@ -1,291 +0,0 @@
1
- class DustScaffoldGenerator < Rails::Generator::Base
2
- attr_accessor :name, :attributes, :controller_actions
3
-
4
- def initialize(runtime_args, runtime_options = {})
5
- super
6
- usage if @args.empty?
7
-
8
- @name = @args.first
9
- @controller_actions = []
10
- @attributes = []
11
-
12
- @args[1..-1].each do |arg|
13
- if arg == '!'
14
- options[:invert] = true
15
- elsif arg.include? ':'
16
- @attributes << Rails::Generator::GeneratedAttribute.new(*arg.split(":"))
17
- else
18
- @controller_actions << arg
19
- @controller_actions << 'create' if arg == 'new'
20
- @controller_actions << 'update' if arg == 'edit'
21
- end
22
- end
23
-
24
- @controller_actions.uniq!
25
- @attributes.uniq!
26
-
27
- if options[:invert] || @controller_actions.empty?
28
- @controller_actions = all_actions - @controller_actions
29
- end
30
-
31
- if @attributes.empty?
32
- options[:skip_model] = true # default to skipping model if no attributes passed
33
- if model_exists?
34
- model_columns_for_attributes.each do |column|
35
- @attributes << Rails::Generator::GeneratedAttribute.new(column.name.to_s, column.type.to_s)
36
- end
37
- else
38
- @attributes << Rails::Generator::GeneratedAttribute.new('name', 'string')
39
- end
40
- end
41
- end
42
-
43
- def manifest
44
- record do |m|
45
- unless options[:skip_model]
46
- m.directory "app/models"
47
- m.template "model.rb", "app/models/#{singular_name}.rb"
48
- unless options[:skip_migration]
49
- m.migration_template "migration.rb", "db/migrate", :migration_file_name => "create_#{plural_name}"
50
- end
51
-
52
- if rspec?
53
- m.directory "spec/models"
54
- m.template "tests/#{test_framework}/model.rb", "spec/models/#{singular_name}_spec.rb"
55
- m.directory "spec/fixtures"
56
- m.template "fixtures.yml", "spec/fixtures/#{plural_name}.yml"
57
- else
58
- m.directory "test/unit"
59
- m.template "tests/#{test_framework}/model.rb", "test/unit/#{singular_name}_test.rb"
60
- m.directory "test/fixtures"
61
- m.template "fixtures.yml", "test/fixtures/#{plural_name}.yml"
62
- end
63
- end
64
-
65
- unless options[:skip_controller]
66
- m.directory "app/controllers"
67
- m.template "controller.rb", "app/controllers/#{plural_name}_controller.rb"
68
-
69
- m.directory "app/helpers"
70
- m.template "helper.rb", "app/helpers/#{plural_name}_helper.rb"
71
-
72
- m.directory "app/views/#{plural_name}"
73
- controller_actions.each do |action|
74
- if File.exist? source_path("views/#{view_language}/#{action}.html.#{view_language}")
75
- m.template "views/#{view_language}/#{action}.html.#{view_language}", "app/views/#{plural_name}/#{action}.html.#{view_language}"
76
- end
77
- end
78
- m.template "views/erb/_search.html.erb", "app/views/#{plural_name}/_search.html.erb"
79
-
80
- if form_partial?
81
- m.template "views/#{view_language}/_form.html.#{view_language}", "app/views/#{plural_name}/_form.html.#{view_language}"
82
- end
83
-
84
- unless options[:skip_front_end]
85
- m.directory "app/controllers"
86
- m.template "view_controller.rb", "app/controllers/view_#{plural_name}_controller.rb"
87
-
88
- m.route :name => "view_#{plural_name}",
89
- :url => "view-#{plural_name}",
90
- :controller => "view_#{plural_name}",
91
- :action => 'index'
92
- m.route :name => "view_#{singular_name}",
93
- :url => "view-#{singular_name}/:filename",
94
- :controller => "view_#{plural_name}",
95
- :action => 'show'
96
-
97
- m.directory "app/views/view_#{plural_name}"
98
- m.template "views/front_end/index.html.erb", "app/views/view_#{plural_name}/index.html.erb"
99
- m.template "views/front_end/show.html.erb", "app/views/view_#{plural_name}/show.html.erb"
100
- end
101
-
102
- m.route_resources plural_name
103
-
104
- if rspec?
105
- m.directory "spec/controllers"
106
- m.template "tests/#{test_framework}/controller.rb", "spec/controllers/#{plural_name}_controller_spec.rb"
107
- else
108
- m.directory "test/functional"
109
- m.template "tests/#{test_framework}/controller.rb", "test/functional/#{plural_name}_controller_test.rb"
110
- end
111
- end
112
- end
113
- end
114
-
115
- def form_partial?
116
- actions? :new, :edit
117
- end
118
-
119
- def all_actions
120
- %w[index show new create edit update destroy]
121
- end
122
-
123
- def action?(name)
124
- controller_actions.include? name.to_s
125
- end
126
-
127
- def actions?(*names)
128
- names.all? { |n| action? n.to_s }
129
- end
130
-
131
- def singular_name
132
- name.underscore
133
- end
134
-
135
- def plural_name
136
- name.underscore.pluralize
137
- end
138
-
139
- def class_name
140
- name.camelize
141
- end
142
-
143
- def plural_class_name
144
- plural_name.camelize
145
- end
146
-
147
- def controller_methods(dir_name)
148
- controller_actions.map do |action|
149
- read_template("#{dir_name}/#{action}.rb")
150
- end.join(" \n").strip
151
- end
152
-
153
- def render_form
154
- if form_partial?
155
- if options[:haml]
156
- "= render :partial => 'form'"
157
- else
158
- "<%= render :partial => 'form' %>"
159
- end
160
- else
161
- read_template("views/#{view_language}/_form.html.#{view_language}")
162
- end
163
- end
164
-
165
- def items_path(suffix = 'path')
166
- if action? :index
167
- "#{plural_name}_#{suffix}"
168
- else
169
- "root_#{suffix}"
170
- end
171
- end
172
-
173
- def item_path(suffix = 'path')
174
- if action? :show
175
- "@#{singular_name}"
176
- else
177
- items_path(suffix)
178
- end
179
- end
180
-
181
- def item_path_for_spec(suffix = 'path')
182
- if action? :show
183
- "#{singular_name}_#{suffix}(assigns[:#{singular_name}])"
184
- else
185
- items_path(suffix)
186
- end
187
- end
188
-
189
- def item_path_for_test(suffix = 'path')
190
- if action? :show
191
- "#{singular_name}_#{suffix}(assigns(:#{singular_name}))"
192
- else
193
- items_path(suffix)
194
- end
195
- end
196
-
197
- def model_columns_for_attributes
198
- class_name.constantize.columns.reject do |column|
199
- column.name.to_s =~ /^(id|created_at|updated_at)$/
200
- end
201
- end
202
-
203
- def rspec?
204
- test_framework == :rspec
205
- end
206
-
207
- protected
208
-
209
- def view_language
210
- options[:haml] ? 'haml' : 'erb'
211
- end
212
-
213
- def test_framework
214
- options[:test_framework] ||= default_test_framework
215
- end
216
-
217
- def default_test_framework
218
- File.exist?(destination_path("spec")) ? :rspec : :testunit
219
- end
220
-
221
- def add_options!(opt)
222
- opt.separator ''
223
- opt.separator 'Options:'
224
- opt.on("--skip-model", "Don't generate a model or migration file.") { |v| options[:skip_model] = v }
225
- opt.on("--skip-migration", "Don't generate migration file for model.") { |v| options[:skip_migration] = v }
226
- opt.on("--skip-timestamps", "Don't add timestamps to migration file.") { |v| options[:skip_timestamps] = v }
227
- opt.on("--skip-controller", "Don't generate controller, helper, or views.") { |v| options[:skip_controller] = v }
228
- opt.on("--skip-front-end", "Dont generate a views controller.") { |v| options[:skip_front_end] = v }
229
- opt.on("--invert", "Generate all controller actions except these mentioned.") { |v| options[:invert] = v }
230
- opt.on("--haml", "Generate HAML views instead of ERB.") { |v| options[:haml] = v }
231
- opt.on("--testunit", "Use test/unit for test files.") { options[:test_framework] = :testunit }
232
- opt.on("--rspec", "Use RSpec for test files.") { options[:test_framework] = :rspec }
233
- opt.on("--shoulda", "Use Shoulda for test files.") { options[:test_framework] = :shoulda }
234
- end
235
-
236
- # is there a better way to do this? Perhaps with const_defined?
237
- def model_exists?
238
- File.exist? destination_path("app/models/#{singular_name}.rb")
239
- end
240
-
241
- def read_template(relative_path)
242
- ERB.new(File.read(source_path(relative_path)), nil, '-').result(binding)
243
- end
244
-
245
- def banner
246
- <<-EOS
247
- Creates a controller and optional model given the name, actions, and attributes.
248
-
249
- USAGE: #{$0} #{spec.name} ModelName [controller_actions and model:attributes] [options]
250
- EOS
251
- end
252
- end
253
-
254
- module Rails
255
- module Generator
256
- module Commands
257
-
258
- class Base
259
- def route_code(route_options)
260
- "map.#{route_options[:name]} '#{route_options[:url]}', :controller => '#{route_options[:controller]}', :action => '#{route_options[:action]}'"
261
- end
262
- end
263
-
264
- # Here's a readable version of the long string used above in route_code;
265
- # but it should be kept on one line to avoid inserting extra whitespace
266
- # into routes.rb when the generator is run:
267
- # "map.#{route_options[:name]} '#{route_options[:name]}',
268
- # :controller => '#{route_options[:controller]}',
269
- # :action => '#{route_options[:action]}'"
270
-
271
- class Create
272
- def route(route_options)
273
- sentinel = 'ActionController::Routing::Routes.draw do |map|'
274
- logger.route route_code(route_options)
275
- gsub_file 'config/routes.rb', /(#{Regexp.escape(sentinel)})/mi do |m|
276
- "#{m}\n #{route_code(route_options)}\n"
277
- end
278
- end
279
- end
280
-
281
- class Destroy
282
- def route(route_options)
283
- logger.remove_route route_code(route_options)
284
- to_remove = "\n #{route_code(route_options)}"
285
- gsub_file 'config/routes.rb', /(#{to_remove})/mi, ''
286
- end
287
- end
288
-
289
- end
290
- end
291
- end
@@ -1,9 +0,0 @@
1
- def create
2
- @<%= singular_name %> = <%= class_name %>.new(params[:<%= singular_name %>])
3
- if @<%= singular_name %>.save
4
- flash[:notice] = "Successfully created <%= name.underscore.humanize.downcase %>."
5
- redirect_to <%= item_path('url') %>
6
- else
7
- render :action => 'new'
8
- end
9
- end
@@ -1,6 +0,0 @@
1
- def destroy
2
- @<%= singular_name %> = <%= class_name %>.find(params[:id])
3
- @<%= singular_name %>.destroy
4
- flash[:notice] = "Successfully destroyed <%= name.underscore.humanize.downcase %>."
5
- redirect_to <%= items_path('url') %>
6
- end
@@ -1,3 +0,0 @@
1
- def edit
2
- @<%= singular_name %> = <%= class_name %>.find(params[:id])
3
- end
@@ -1,3 +0,0 @@
1
- def index
2
- @<%= plural_name %> = <%= class_name %>.page(params[:search], params[:page])
3
- end
@@ -1,3 +0,0 @@
1
- def new
2
- @<%= singular_name %> = <%= class_name %>.new
3
- end
@@ -1,3 +0,0 @@
1
- def show
2
- @<%= singular_name %> = <%= class_name %>.find(params[:id])
3
- end
@@ -1,9 +0,0 @@
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 <%= name.underscore.humanize.downcase %>."
5
- redirect_to <%= item_path('url') %>
6
- else
7
- render :action => 'edit'
8
- end
9
- end
@@ -1,9 +0,0 @@
1
- class <%= plural_class_name %>Controller < ApplicationController
2
-
3
- filter_resource_access
4
-
5
- layout 'cms'
6
-
7
- <%= controller_methods :actions %>
8
-
9
- end
@@ -1,9 +0,0 @@
1
- one:
2
- <%- for attribute in attributes -%>
3
- <%= attribute.name %>: <%= attribute.default %>
4
- <%- end -%>
5
-
6
- two:
7
- <%- for attribute in attributes -%>
8
- <%= attribute.name %>: <%= attribute.default %>
9
- <%- end -%>
@@ -1,2 +0,0 @@
1
- module <%= plural_class_name %>Helper
2
- end
@@ -1,20 +0,0 @@
1
- <%- first_attribute = attributes.first -%>
2
- class Create<%= plural_class_name %> < ActiveRecord::Migration
3
- def self.up
4
- create_table :<%= plural_name %> do |t|
5
- <%- for attribute in attributes -%>
6
- t.<%= attribute.type %> :<%= attribute.name %>
7
- <%- end -%>
8
- <%- unless options[:skip_timestamps] -%>
9
- t.timestamps
10
- <%- end -%>
11
- end
12
- end
13
-
14
- AdminMenuItem.create({:title =>"<%= plural_class_name %>", :controller_name => "<%= plural_name %>", :url => "/<%= plural_name %>"})
15
- MenuItem.create({:title => "View <%= plural_class_name %>", :url => "/view-<%= plural_name %>", :active => true})
16
-
17
- def self.down
18
- drop_table :<%= plural_name %>
19
- end
20
- end
@@ -1,37 +0,0 @@
1
- class <%= class_name %> < ActiveRecord::Base
2
- attr_accessible <%= attributes.map { |a| ":#{a.name}" }.join(", ") %>
3
-
4
- <%- first_attribute = attributes.first -%>
5
- def self.page(search, page)
6
- paginate :per_page => 10, :page => page,
7
- :order => '<%= first_attribute.name %>',
8
- :conditions => ["<%= first_attribute.name %> LIKE ?", "%#{search}%"]
9
- end
10
-
11
- has_one :menu_item, :as => :linkable, :dependent => :destroy
12
-
13
- after_create :create_menu_item
14
- after_update :update_menu_item
15
-
16
- def update_menu_item
17
- @menu_item = self.menu_item
18
- if @menu_item == nil
19
- self.create_menu_item
20
- else
21
- @menu_item.update_attributes(
22
- :title => self.<%= first_attribute.name %>,
23
- :url => "/view-<%= singular_name %>/#{self.<%= first_attribute.name %>}",
24
- :active => self.<%= first_attribute.name %>
25
- )
26
- end
27
- end
28
-
29
- def create_menu_item
30
- @menu_item = self.build_menu_item(
31
- :title => self.<%= first_attribute.name %>,
32
- :url => "/view-<%= singular_name %>/#{<%= first_attribute.name %>}",
33
- :active => self.<%= first_attribute.name %>
34
- )
35
- @menu_item.save
36
- end
37
- end
@@ -1,11 +0,0 @@
1
- it "create action should render new template when model is invalid" do
2
- <%= class_name %>.any_instance.stubs(:valid?).returns(false)
3
- post :create
4
- response.should render_template(:new)
5
- end
6
-
7
- it "create action should redirect when model is valid" do
8
- <%= class_name %>.any_instance.stubs(:valid?).returns(true)
9
- post :create
10
- response.should redirect_to(<%= item_path_for_spec('url') %>)
11
- end
@@ -1,6 +0,0 @@
1
- it "destroy action should destroy model and redirect to index action" do
2
- <%= singular_name %> = <%= class_name %>.first
3
- delete :destroy, :id => <%= singular_name %>
4
- response.should redirect_to(<%= items_path('url') %>)
5
- <%= class_name %>.exists?(<%= singular_name %>.id).should be_false
6
- end
@@ -1,4 +0,0 @@
1
- it "edit action should render edit template" do
2
- get :edit, :id => <%= class_name %>.first
3
- response.should render_template(:edit)
4
- end