rubigen 1.0.7 → 1.0.8

Sign up to get free protection for your applications and to get access to all the features.
Files changed (80) hide show
  1. data/History.txt +8 -0
  2. data/Manifest.txt +1 -72
  3. data/app_generators/ruby_app/ruby_app_generator.rb +1 -1
  4. data/app_generators/ruby_app/templates/configs/{empty.log → empty_log} +0 -0
  5. data/generators/install_rubigen_scripts/install_rubigen_scripts_generator.rb +7 -0
  6. data/lib/rubigen/lookup.rb +1 -1
  7. data/lib/rubigen/version.rb +1 -1
  8. data/website/index.html +2 -2
  9. metadata +3 -74
  10. data/examples/rails_generators/applications/app/USAGE +0 -16
  11. data/examples/rails_generators/applications/app/app_generator.rb +0 -177
  12. data/examples/rails_generators/components/controller/USAGE +0 -29
  13. data/examples/rails_generators/components/controller/controller_generator.rb +0 -37
  14. data/examples/rails_generators/components/controller/templates/controller.rb +0 -10
  15. data/examples/rails_generators/components/controller/templates/functional_test.rb +0 -18
  16. data/examples/rails_generators/components/controller/templates/helper.rb +0 -2
  17. data/examples/rails_generators/components/controller/templates/view.html.erb +0 -2
  18. data/examples/rails_generators/components/integration_test/USAGE +0 -8
  19. data/examples/rails_generators/components/integration_test/integration_test_generator.rb +0 -16
  20. data/examples/rails_generators/components/integration_test/templates/integration_test.rb +0 -10
  21. data/examples/rails_generators/components/mailer/USAGE +0 -16
  22. data/examples/rails_generators/components/mailer/mailer_generator.rb +0 -34
  23. data/examples/rails_generators/components/mailer/templates/fixture.erb +0 -3
  24. data/examples/rails_generators/components/mailer/templates/fixture.rhtml +0 -0
  25. data/examples/rails_generators/components/mailer/templates/mailer.rb +0 -13
  26. data/examples/rails_generators/components/mailer/templates/unit_test.rb +0 -37
  27. data/examples/rails_generators/components/mailer/templates/view.erb +0 -3
  28. data/examples/rails_generators/components/mailer/templates/view.rhtml +0 -0
  29. data/examples/rails_generators/components/migration/USAGE +0 -24
  30. data/examples/rails_generators/components/migration/migration_generator.rb +0 -20
  31. data/examples/rails_generators/components/migration/templates/migration.rb +0 -7
  32. data/examples/rails_generators/components/model/USAGE +0 -27
  33. data/examples/rails_generators/components/model/model_generator.rb +0 -38
  34. data/examples/rails_generators/components/model/templates/fixtures.yml +0 -15
  35. data/examples/rails_generators/components/model/templates/migration.rb +0 -14
  36. data/examples/rails_generators/components/model/templates/model.rb +0 -2
  37. data/examples/rails_generators/components/model/templates/unit_test.rb +0 -10
  38. data/examples/rails_generators/components/observer/USAGE +0 -13
  39. data/examples/rails_generators/components/observer/observer_generator.rb +0 -16
  40. data/examples/rails_generators/components/observer/templates/observer.rb +0 -2
  41. data/examples/rails_generators/components/observer/templates/unit_test.rb +0 -10
  42. data/examples/rails_generators/components/plugin/USAGE +0 -25
  43. data/examples/rails_generators/components/plugin/plugin_generator.rb +0 -39
  44. data/examples/rails_generators/components/plugin/templates/MIT-LICENSE +0 -20
  45. data/examples/rails_generators/components/plugin/templates/README +0 -13
  46. data/examples/rails_generators/components/plugin/templates/Rakefile +0 -22
  47. data/examples/rails_generators/components/plugin/templates/USAGE +0 -8
  48. data/examples/rails_generators/components/plugin/templates/generator.rb +0 -8
  49. data/examples/rails_generators/components/plugin/templates/init.rb +0 -1
  50. data/examples/rails_generators/components/plugin/templates/install.rb +0 -1
  51. data/examples/rails_generators/components/plugin/templates/plugin.rb +0 -1
  52. data/examples/rails_generators/components/plugin/templates/tasks.rake +0 -4
  53. data/examples/rails_generators/components/plugin/templates/uninstall.rb +0 -1
  54. data/examples/rails_generators/components/plugin/templates/unit_test.rb +0 -8
  55. data/examples/rails_generators/components/resource/USAGE +0 -23
  56. data/examples/rails_generators/components/resource/resource_generator.rb +0 -72
  57. data/examples/rails_generators/components/resource/templates/USAGE +0 -18
  58. data/examples/rails_generators/components/resource/templates/controller.rb +0 -2
  59. data/examples/rails_generators/components/resource/templates/fixtures.yml +0 -0
  60. data/examples/rails_generators/components/resource/templates/functional_test.rb +0 -20
  61. data/examples/rails_generators/components/resource/templates/helper.rb +0 -2
  62. data/examples/rails_generators/components/scaffold/USAGE +0 -25
  63. data/examples/rails_generators/components/scaffold/scaffold_generator.rb +0 -90
  64. data/examples/rails_generators/components/scaffold/templates/controller.rb +0 -85
  65. data/examples/rails_generators/components/scaffold/templates/functional_test.rb +0 -57
  66. data/examples/rails_generators/components/scaffold/templates/helper.rb +0 -2
  67. data/examples/rails_generators/components/scaffold/templates/layout.html.erb +0 -17
  68. data/examples/rails_generators/components/scaffold/templates/style.css +0 -74
  69. data/examples/rails_generators/components/scaffold/templates/view_edit.html.erb +0 -19
  70. data/examples/rails_generators/components/scaffold/templates/view_index.html.erb +0 -24
  71. data/examples/rails_generators/components/scaffold/templates/view_new.html.erb +0 -18
  72. data/examples/rails_generators/components/scaffold/templates/view_show.html.erb +0 -10
  73. data/examples/rails_generators/components/session_migration/USAGE +0 -10
  74. data/examples/rails_generators/components/session_migration/session_migration_generator.rb +0 -18
  75. data/examples/rails_generators/components/session_migration/templates/migration.rb +0 -16
  76. data/examples/rails_generators/components/web_service/USAGE +0 -24
  77. data/examples/rails_generators/components/web_service/templates/api_definition.rb +0 -5
  78. data/examples/rails_generators/components/web_service/templates/controller.rb +0 -8
  79. data/examples/rails_generators/components/web_service/templates/functional_test.rb +0 -19
  80. data/examples/rails_generators/components/web_service/web_service_generator.rb +0 -29
@@ -1,34 +0,0 @@
1
- class MailerGenerator < RubiGen::NamedBase
2
- def manifest
3
- record do |m|
4
- # Check for class naming collisions.
5
- m.class_collisions class_path, class_name, "#{class_name}Test"
6
-
7
- # Mailer, view, test, and fixture directories.
8
- m.directory File.join('app/models', class_path)
9
- m.directory File.join('app/views', file_path)
10
- m.directory File.join('test/unit', class_path)
11
- m.directory File.join('test/fixtures', file_path)
12
-
13
- # Mailer class and unit test.
14
- m.template "mailer.rb", File.join('app/models',
15
- class_path,
16
- "#{file_name}.rb")
17
- m.template "unit_test.rb", File.join('test/unit',
18
- class_path,
19
- "#{file_name}_test.rb")
20
-
21
- # View template and fixture for each action.
22
- actions.each do |action|
23
- relative_path = File.join(file_path, action)
24
- view_path = File.join('app/views', "#{relative_path}.erb")
25
- fixture_path = File.join('test/fixtures', relative_path)
26
-
27
- m.template "view.erb", view_path,
28
- :assigns => { :action => action, :path => view_path }
29
- m.template "fixture.erb", fixture_path,
30
- :assigns => { :action => action, :path => view_path }
31
- end
32
- end
33
- end
34
- end
@@ -1,3 +0,0 @@
1
- <%= class_name %>#<%= action %>
2
-
3
- Find me in <%= path %>
@@ -1,13 +0,0 @@
1
- class <%= class_name %> < ActionMailer::Base
2
- <% for action in actions -%>
3
-
4
- def <%= action %>(sent_at = Time.now)
5
- @subject = '<%= class_name %>#<%= action %>'
6
- @body = {}
7
- @recipients = ''
8
- @from = ''
9
- @sent_on = sent_at
10
- @headers = {}
11
- end
12
- <% end -%>
13
- end
@@ -1,37 +0,0 @@
1
- require File.dirname(__FILE__) + '<%= '/..' * class_nesting_depth %>/../test_helper'
2
-
3
- class <%= class_name %>Test < Test::Unit::TestCase
4
- FIXTURES_PATH = File.dirname(__FILE__) + '<%= '/..' * class_nesting_depth %>/../fixtures'
5
- CHARSET = "utf-8"
6
-
7
- include ActionMailer::Quoting
8
-
9
- def setup
10
- ActionMailer::Base.delivery_method = :test
11
- ActionMailer::Base.perform_deliveries = true
12
- ActionMailer::Base.deliveries = []
13
-
14
- @expected = TMail::Mail.new
15
- @expected.set_content_type "text", "plain", { "charset" => CHARSET }
16
- @expected.mime_version = '1.0'
17
- end
18
-
19
- <% for action in actions -%>
20
- def test_<%= action %>
21
- @expected.subject = '<%= class_name %>#<%= action %>'
22
- @expected.body = read_fixture('<%= action %>')
23
- @expected.date = Time.now
24
-
25
- assert_equal @expected.encoded, <%= class_name %>.create_<%= action %>(@expected.date).encoded
26
- end
27
-
28
- <% end -%>
29
- private
30
- def read_fixture(action)
31
- IO.readlines("#{FIXTURES_PATH}/<%= file_path %>/#{action}")
32
- end
33
-
34
- def encode(subject)
35
- quoted_printable(subject, CHARSET)
36
- end
37
- end
@@ -1,3 +0,0 @@
1
- <%= class_name %>#<%= action %>
2
-
3
- Find me in <%= path %>
@@ -1,24 +0,0 @@
1
- Description:
2
- Stubs out a new database migration. Pass the migration name, either
3
- CamelCased or under_scored, as an argument. A migration class is generated
4
- in db/migrate prefixed by the latest migration number.
5
-
6
- You can name your migration in either of these formats to generate add/remove
7
- column lines: AddColumnToTable or RemoveColumnFromTable
8
-
9
- Example:
10
- `./script/generate migration AddSslFlag`
11
-
12
- With 4 existing migrations, this creates the AddSslFlag migration in
13
- db/migrate/005_add_ssl_flag.rb
14
-
15
- `./script/generate migration AddSslFlagToAccount`
16
-
17
- This will create the AddSslFlagToAccount in db/migrate/005_add_ssl_flag_to_account.rb with
18
- this in the Up migration:
19
-
20
- add_column :accounts, :ssl_flag, :type, :null => :no?, :default => :maybe?
21
-
22
- And this in the Down migration:
23
-
24
- remove_column :accounts, :ssl_flag
@@ -1,20 +0,0 @@
1
- class MigrationGenerator < RubiGen::NamedBase
2
- def manifest
3
- record do |m|
4
- m.migration_template 'migration.rb', 'db/migrate'
5
- end
6
- end
7
-
8
- def auto_migration direction
9
- case class_name.underscore
10
- when /^(add|remove)_(.*)_(?:to|from)_(.*)/ then
11
- action, col, tbl = $1, $2, $3.pluralize
12
-
13
- unless (action == "add") ^ (direction == :up) then
14
- %(\n add_column :#{tbl}, :#{col}, :type, :null => :no?, :default => :maybe?)
15
- else
16
- %(\n remove_column :#{tbl}, :#{col})
17
- end
18
- end
19
- end
20
- end
@@ -1,7 +0,0 @@
1
- class <%= class_name.underscore.camelize %> < ActiveRecord::Migration
2
- def self.up<%= auto_migration :up %>
3
- end
4
-
5
- def self.down<%= auto_migration :down %>
6
- end
7
- end
@@ -1,27 +0,0 @@
1
- Description:
2
- Stubs out a new model. Pass the model name, either CamelCased or
3
- under_scored, and an optional list of attribute pairs as arguments.
4
-
5
- Attribute pairs are column_name:sql_type arguments specifying the
6
- model's attributes. Timestamps are added by default, so you don't have to
7
- specify them by hand as 'created_at:datetime updated_at:datetime'.
8
-
9
- You don't have to think up every attribute up front, but it helps to
10
- sketch out a few so you can start working with the model immediately.
11
-
12
- This generates a model class in app/models, a unit test in test/unit,
13
- a test fixture in test/fixtures/singular_name.yml, and a migration in
14
- db/migrate.
15
-
16
- Examples:
17
- `./script/generate model account`
18
-
19
- creates an Account model, test, fixture, and migration:
20
- Model: app/models/account.rb
21
- Test: test/unit/account_test.rb
22
- Fixtures: test/fixtures/accounts.yml
23
- Migration: db/migrate/XXX_add_accounts.rb
24
-
25
- `./script/generate model post title:string body:text published:boolean`
26
-
27
- creates a Post model with a string title, text body, and published flag.
@@ -1,38 +0,0 @@
1
- class ModelGenerator < RubiGen::NamedBase
2
- default_options :skip_migration => false
3
-
4
- def manifest
5
- record do |m|
6
- # Check for class naming collisions.
7
- m.class_collisions class_path, class_name, "#{class_name}Test"
8
-
9
- # Model, test, and fixture directories.
10
- m.directory File.join('app/models', class_path)
11
- m.directory File.join('test/unit', class_path)
12
- m.directory File.join('test/fixtures', class_path)
13
-
14
- # Model class, unit test, and fixtures.
15
- m.template 'model.rb', File.join('app/models', class_path, "#{file_name}.rb")
16
- m.template 'unit_test.rb', File.join('test/unit', class_path, "#{file_name}_test.rb")
17
- m.template 'fixtures.yml', File.join('test/fixtures', class_path, "#{table_name}.yml")
18
-
19
- unless options[:skip_migration]
20
- m.migration_template 'migration.rb', 'db/migrate', :assigns => {
21
- :migration_name => "Create#{class_name.pluralize.gsub(/::/, '')}"
22
- }, :migration_file_name => "create_#{file_path.gsub(/\//, '_').pluralize}"
23
- end
24
- end
25
- end
26
-
27
- protected
28
- def banner
29
- "Usage: #{$0} generate ModelName [field:type, field:type]"
30
- end
31
-
32
- def add_options!(opt)
33
- opt.separator ''
34
- opt.separator 'Options:'
35
- opt.on("--skip-migration",
36
- "Don't generate a migration file for this model") { |v| options[:skip_migration] = v }
37
- end
38
- end
@@ -1,15 +0,0 @@
1
- # Read about fixtures at http://ar.rubyonrails.org/classes/Fixtures.html
2
- one:
3
- id: 1
4
- <% for attribute in attributes -%>
5
- <%= attribute.name %>: <%= attribute.default %>
6
- <% end -%>
7
- created_at: <%= Time.now.to_s(:db) %>
8
- updated_at: <%= Time.now.to_s(:db) %>
9
- two:
10
- id: 2
11
- <% for attribute in attributes -%>
12
- <%= attribute.name %>: <%= attribute.default %>
13
- <% end -%>
14
- created_at: <%= Time.now.to_s(:db) %>
15
- updated_at: <%= Time.now.to_s(:db) %>
@@ -1,14 +0,0 @@
1
- class <%= migration_name %> < ActiveRecord::Migration
2
- def self.up
3
- create_table :<%= table_name %> do |t|
4
- <% for attribute in attributes -%>
5
- t.<%= attribute.type %> :<%= attribute.name %>
6
- <% end %>
7
- t.timestamps
8
- end
9
- end
10
-
11
- def self.down
12
- drop_table :<%= table_name %>
13
- end
14
- end
@@ -1,2 +0,0 @@
1
- class <%= class_name %> < ActiveRecord::Base
2
- end
@@ -1,10 +0,0 @@
1
- require File.dirname(__FILE__) + '<%= '/..' * class_nesting_depth %>/../test_helper'
2
-
3
- class <%= class_name %>Test < Test::Unit::TestCase
4
- fixtures :<%= table_name %>
5
-
6
- # Replace this with your real tests.
7
- def test_truth
8
- assert true
9
- end
10
- end
@@ -1,13 +0,0 @@
1
- Description:
2
- Stubs out a new observer. Pass the observer name, either CamelCased or
3
- under_scored, as an argument.
4
-
5
- The generator creates an observer class in app/models and a unit test in
6
- test/unit.
7
-
8
- Example:
9
- `./script/generate observer Account`
10
-
11
- creates an Account observer and unit test:
12
- Observer: app/models/account_observer.rb
13
- Test: test/unit/account_observer_test.rb
@@ -1,16 +0,0 @@
1
- class ObserverGenerator < RubiGen::NamedBase
2
- def manifest
3
- record do |m|
4
- # Check for class naming collisions.
5
- m.class_collisions class_path, "#{class_name}Observer", "#{class_name}ObserverTest"
6
-
7
- # Observer, and test directories.
8
- m.directory File.join('app/models', class_path)
9
- m.directory File.join('test/unit', class_path)
10
-
11
- # Observer class and unit test fixtures.
12
- m.template 'observer.rb', File.join('app/models', class_path, "#{file_name}_observer.rb")
13
- m.template 'unit_test.rb', File.join('test/unit', class_path, "#{file_name}_observer_test.rb")
14
- end
15
- end
16
- end
@@ -1,2 +0,0 @@
1
- class <%= class_name %>Observer < ActiveRecord::Observer
2
- end
@@ -1,10 +0,0 @@
1
- require File.dirname(__FILE__) + '<%= '/..' * class_nesting_depth %>/../test_helper'
2
-
3
- class <%= class_name %>ObserverTest < Test::Unit::TestCase
4
- fixtures :<%= table_name %>
5
-
6
- # Replace this with your real tests.
7
- def test_truth
8
- assert true
9
- end
10
- end
@@ -1,25 +0,0 @@
1
- Description:
2
- Stubs out a new plugin. Pass the plugin name, either CamelCased or
3
- under_scored, as an argument. Pass --with-generator to add an example
4
- generator also.
5
-
6
- This creates a plugin in vendor/plugins including an init.rb and README
7
- as well as standard lib, task, and test directories.
8
-
9
- Example:
10
- `./script/generate plugin BrowserFilters`
11
-
12
- creates a standard browser_filters plugin:
13
- vendor/plugins/browser_filters/README
14
- vendor/plugins/browser_filters/init.rb
15
- vendor/plugins/browser_filters/install.rb
16
- vendor/plugins/browser_filters/lib/browser_filters.rb
17
- vendor/plugins/browser_filters/test/browser_filters_test.rb
18
- vendor/plugins/browser_filters/tasks/browser_filters_tasks.rake
19
-
20
- ./script/generate plugin BrowserFilters --with-generator
21
-
22
- creates a browser_filters generator also:
23
- vendor/plugins/browser_filters/generators/browser_filters/browser_filters_generator.rb
24
- vendor/plugins/browser_filters/generators/browser_filters/USAGE
25
- vendor/plugins/browser_filters/generators/browser_filters/templates/
@@ -1,39 +0,0 @@
1
- class PluginGenerator < RubiGen::NamedBase
2
- attr_reader :plugin_path
3
-
4
- def initialize(runtime_args, runtime_options = {})
5
- @with_generator = runtime_args.delete("--with-generator")
6
- super
7
- @plugin_path = "vendor/plugins/#{file_name}"
8
- end
9
-
10
- def manifest
11
- record do |m|
12
- # Check for class naming collisions.
13
- m.class_collisions class_path, class_name
14
-
15
- m.directory "#{plugin_path}/lib"
16
- m.directory "#{plugin_path}/tasks"
17
- m.directory "#{plugin_path}/test"
18
-
19
- m.template 'README', "#{plugin_path}/README"
20
- m.template 'MIT-LICENSE', "#{plugin_path}/MIT-LICENSE"
21
- m.template 'Rakefile', "#{plugin_path}/Rakefile"
22
- m.template 'init.rb', "#{plugin_path}/init.rb"
23
- m.template 'install.rb', "#{plugin_path}/install.rb"
24
- m.template 'uninstall.rb', "#{plugin_path}/uninstall.rb"
25
- m.template 'plugin.rb', "#{plugin_path}/lib/#{file_name}.rb"
26
- m.template 'tasks.rake', "#{plugin_path}/tasks/#{file_name}_tasks.rake"
27
- m.template 'unit_test.rb', "#{plugin_path}/test/#{file_name}_test.rb"
28
-
29
- if @with_generator
30
- m.directory "#{plugin_path}/generators"
31
- m.directory "#{plugin_path}/generators/#{file_name}"
32
- m.directory "#{plugin_path}/generators/#{file_name}/templates"
33
-
34
- m.template 'generator.rb', "#{plugin_path}/generators/#{file_name}/#{file_name}_generator.rb"
35
- m.template 'USAGE', "#{plugin_path}/generators/#{file_name}/USAGE"
36
- end
37
- end
38
- end
39
- end
@@ -1,20 +0,0 @@
1
- Copyright (c) 2007 [name of plugin creator]
2
-
3
- Permission is hereby granted, free of charge, to any person obtaining
4
- a copy of this software and associated documentation files (the
5
- "Software"), to deal in the Software without restriction, including
6
- without limitation the rights to use, copy, modify, merge, publish,
7
- distribute, sublicense, and/or sell copies of the Software, and to
8
- permit persons to whom the Software is furnished to do so, subject to
9
- the following conditions:
10
-
11
- The above copyright notice and this permission notice shall be
12
- included in all copies or substantial portions of the Software.
13
-
14
- THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15
- EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16
- MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17
- NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
18
- LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
19
- OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20
- WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
@@ -1,13 +0,0 @@
1
- <%= class_name %>
2
- <%= "=" * class_name.size %>
3
-
4
- Introduction goes here.
5
-
6
-
7
- Example
8
- =======
9
-
10
- Example goes here.
11
-
12
-
13
- Copyright (c) 2007 [name of plugin creator], released under the MIT license
@@ -1,22 +0,0 @@
1
- require 'rake'
2
- require 'rake/testtask'
3
- require 'rake/rdoctask'
4
-
5
- desc 'Default: run unit tests.'
6
- task :default => :test
7
-
8
- desc 'Test the <%= file_name %> plugin.'
9
- Rake::TestTask.new(:test) do |t|
10
- t.libs << 'lib'
11
- t.pattern = 'test/**/*_test.rb'
12
- t.verbose = true
13
- end
14
-
15
- desc 'Generate documentation for the <%= file_name %> plugin.'
16
- Rake::RDocTask.new(:rdoc) do |rdoc|
17
- rdoc.rdoc_dir = 'rdoc'
18
- rdoc.title = '<%= class_name %>'
19
- rdoc.options << '--line-numbers' << '--inline-source'
20
- rdoc.rdoc_files.include('README')
21
- rdoc.rdoc_files.include('lib/**/*.rb')
22
- end
@@ -1,8 +0,0 @@
1
- Description:
2
- Explain the generator
3
-
4
- Example:
5
- ./script/generate <%= file_name %> Thing
6
-
7
- This will create:
8
- what/will/it/create
@@ -1,8 +0,0 @@
1
- class <%= class_name %>Generator < RubiGen::NamedBase
2
- def manifest
3
- record do |m|
4
- # m.directory "lib"
5
- # m.template 'README', "README"
6
- end
7
- end
8
- end
@@ -1 +0,0 @@
1
- # Include hook code here
@@ -1 +0,0 @@
1
- # Install hook code here
@@ -1 +0,0 @@
1
- # <%= class_name %>
@@ -1,4 +0,0 @@
1
- # desc "Explaining what the task does"
2
- # task :<%= file_name %> do
3
- # # Task goes here
4
- # end
@@ -1 +0,0 @@
1
- # Uninstall hook code here
@@ -1,8 +0,0 @@
1
- require 'test/unit'
2
-
3
- class <%= class_name %>Test < Test::Unit::TestCase
4
- # Replace this with your real tests.
5
- def test_this_plugin
6
- flunk
7
- end
8
- end
@@ -1,23 +0,0 @@
1
- Description:
2
- Stubs out a new resource including an empty model and controller suitable
3
- for a restful, resource-oriented application. Pass the singular model name,
4
- either CamelCased or under_scored, as the first argument, and an optional
5
- list of attribute pairs.
6
-
7
- Attribute pairs are column_name:sql_type arguments specifying the
8
- model's attributes. Timestamps are added by default, so you don't have to
9
- specify them by hand as 'created_at:datetime updated_at:datetime'.
10
-
11
- You don't have to think up every attribute up front, but it helps to
12
- sketch out a few so you can start working with the resource immediately.
13
-
14
- This creates a model, controller, tests and fixtures for both, and the
15
- corresponding map.resources declaration in config/routes.rb
16
-
17
- Unlike the scaffold generator, the resource generator does not create
18
- views or add any methods to the generated controller.
19
-
20
- Examples:
21
- `./script/generate resource post` # no attributes
22
- `./script/generate resource post title:string body:text published:boolean`
23
- `./script/generate resource purchase order_id:integer amount:decimal`
@@ -1,72 +0,0 @@
1
- class ResourceGenerator < RubiGen::NamedBase
2
- default_options :skip_migration => false
3
-
4
- attr_reader :controller_name,
5
- :controller_class_path,
6
- :controller_file_path,
7
- :controller_class_nesting,
8
- :controller_class_nesting_depth,
9
- :controller_class_name,
10
- :controller_singular_name,
11
- :controller_plural_name
12
- alias_method :controller_file_name, :controller_singular_name
13
- alias_method :controller_table_name, :controller_plural_name
14
-
15
- def initialize(runtime_args, runtime_options = {})
16
- super
17
-
18
- @controller_name = @name.pluralize
19
-
20
- base_name, @controller_class_path, @controller_file_path, @controller_class_nesting, @controller_class_nesting_depth = extract_modules(@controller_name)
21
- @controller_class_name_without_nesting, @controller_singular_name, @controller_plural_name = inflect_names(base_name)
22
-
23
- if @controller_class_nesting.empty?
24
- @controller_class_name = @controller_class_name_without_nesting
25
- else
26
- @controller_class_name = "#{@controller_class_nesting}::#{@controller_class_name_without_nesting}"
27
- end
28
- end
29
-
30
- def manifest
31
- record do |m|
32
- # Check for class naming collisions.
33
- m.class_collisions(controller_class_path, "#{controller_class_name}Controller", "#{controller_class_name}Helper")
34
- m.class_collisions(class_path, "#{class_name}")
35
-
36
- # Controller, helper, views, and test directories.
37
- m.directory(File.join('app/models', class_path))
38
- m.directory(File.join('app/controllers', controller_class_path))
39
- m.directory(File.join('app/helpers', controller_class_path))
40
- m.directory(File.join('app/views', controller_class_path, controller_file_name))
41
- m.directory(File.join('test/functional', controller_class_path))
42
- m.directory(File.join('test/unit', class_path))
43
-
44
- m.dependency 'model', [singular_name] + @args, :collision => :skip
45
-
46
- m.template(
47
- 'controller.rb', File.join('app/controllers', controller_class_path, "#{controller_file_name}_controller.rb")
48
- )
49
-
50
- m.template('functional_test.rb', File.join('test/functional', controller_class_path, "#{controller_file_name}_controller_test.rb"))
51
- m.template('helper.rb', File.join('app/helpers', controller_class_path, "#{controller_file_name}_helper.rb"))
52
-
53
- m.route_resources controller_file_name
54
- end
55
- end
56
-
57
- protected
58
- def banner
59
- "Usage: #{$0} resource ModelName [field:type, field:type]"
60
- end
61
-
62
- def add_options!(opt)
63
- opt.separator ''
64
- opt.separator 'Options:'
65
- opt.on("--skip-migration",
66
- "Don't generate a migration file for this model") { |v| options[:skip_migration] = v }
67
- end
68
-
69
- def model_name
70
- class_name.demodulize
71
- end
72
- end
@@ -1,18 +0,0 @@
1
- Description:
2
- The resource generator creates an empty model and controller for use in a REST-friendly, resource-oriented
3
- application. Say you want to a resource called post. Normally, you could just call "script/generate model post" and
4
- "script/generate controller posts". This generator basically just collapses these two generators into one step.
5
-
6
- The generator takes the name of the model as its first argument. This model name is then pluralized to get the
7
- controller name. So "resource post" will generate a Post model and a PostsController and will be intended
8
- for URLs like /posts and /posts/45.
9
-
10
- As additional parameters, the generator will take attribute pairs described by name and type. These attributes will
11
- be used to prepopulate the migration to create the table for the model and give you a set of predefined fixture.
12
- You don't have to think up all attributes up front, but it's a good idea of adding just the baseline of what's
13
- needed to start really working with the resource.
14
-
15
- Examples:
16
- ./script/generate resource post
17
- ./script/generate resource post title:string created_on:date body:text published:boolean
18
- ./script/generate resource purchase order_id:integer created_at:datetime amount:decimal
@@ -1,2 +0,0 @@
1
- class <%= controller_class_name %>Controller < ApplicationController
2
- end
@@ -1,20 +0,0 @@
1
- require File.dirname(__FILE__) + '<%= '/..' * controller_class_nesting_depth %>/../test_helper'
2
- require '<%= controller_file_path %>_controller'
3
-
4
- # Re-raise errors caught by the controller.
5
- class <%= controller_class_name %>Controller; def rescue_action(e) raise e end; end
6
-
7
- class <%= controller_class_name %>ControllerTest < Test::Unit::TestCase
8
- fixtures :<%= table_name %>
9
-
10
- def setup
11
- @controller = <%= controller_class_name %>Controller.new
12
- @request = ActionController::TestRequest.new
13
- @response = ActionController::TestResponse.new
14
- end
15
-
16
- # Replace this with your real tests.
17
- def test_truth
18
- assert true
19
- end
20
- end
@@ -1,2 +0,0 @@
1
- module <%= controller_class_name %>Helper
2
- end