rubaidh-generators 1.0.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (37) hide show
  1. data/.gitignore +2 -0
  2. data/MIT-LICENSE +20 -0
  3. data/README.rdoc +8 -0
  4. data/Rakefile +29 -0
  5. data/TODO +11 -0
  6. data/bin/rubaidh_rails +11 -0
  7. data/generators/rubaidh_controller/USAGE +31 -0
  8. data/generators/rubaidh_controller/rubaidh_controller_generator.rb +40 -0
  9. data/generators/rubaidh_controller/templates/controller.rb +17 -0
  10. data/generators/rubaidh_controller/templates/controller_spec.rb +29 -0
  11. data/generators/rubaidh_controller/templates/view.html.erb +2 -0
  12. data/generators/rubaidh_helper/USAGE +23 -0
  13. data/generators/rubaidh_helper/rubaidh_helper_generator.rb +27 -0
  14. data/generators/rubaidh_helper/templates/helper.rb +12 -0
  15. data/generators/rubaidh_helper/templates/helper_spec.rb +14 -0
  16. data/generators/rubaidh_model/USAGE +25 -0
  17. data/generators/rubaidh_model/rubaidh_model_generator.rb +29 -0
  18. data/generators/rubaidh_model/templates/migration.rb +25 -0
  19. data/generators/rubaidh_model/templates/model.rb +15 -0
  20. data/generators/rubaidh_model/templates/model_exemplar.rb +13 -0
  21. data/generators/rubaidh_model/templates/model_spec.rb +31 -0
  22. data/generators/rubaidh_named_base.rb +31 -0
  23. data/generators/rubaidh_scaffold/USAGE +29 -0
  24. data/generators/rubaidh_scaffold/rubaidh_scaffold_generator.rb +90 -0
  25. data/generators/rubaidh_scaffold/templates/controller.rb +76 -0
  26. data/generators/rubaidh_scaffold/templates/controller_spec.rb +251 -0
  27. data/generators/rubaidh_scaffold/templates/partial_form.html.erb +13 -0
  28. data/generators/rubaidh_scaffold/templates/partial_layout.html.erb +13 -0
  29. data/generators/rubaidh_scaffold/templates/partial_model.html.erb +8 -0
  30. data/generators/rubaidh_scaffold/templates/routing_spec.rb +73 -0
  31. data/generators/rubaidh_scaffold/templates/view_edit.html.erb +6 -0
  32. data/generators/rubaidh_scaffold/templates/view_index.html.erb +5 -0
  33. data/generators/rubaidh_scaffold/templates/view_new.html.erb +5 -0
  34. data/generators/rubaidh_scaffold/templates/view_show.html.erb +11 -0
  35. data/generators.gemspec +52 -0
  36. data/templates/rubaidh.rb +82 -0
  37. metadata +97 -0
data/.gitignore ADDED
@@ -0,0 +1,2 @@
1
+ /rdoc
2
+ /pkg
data/MIT-LICENSE ADDED
@@ -0,0 +1,20 @@
1
+ Copyright (c) 2009 [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.
data/README.rdoc ADDED
@@ -0,0 +1,8 @@
1
+ = Rubaidh Generators
2
+
3
+ Rails ships with its own generators for creating models, controllers and
4
+ complete scaffolds. RSpec ships with its own take on these generators. We ship
5
+ with yet another slightly different take on the generators, suited to
6
+ Rubaidh's tastes.
7
+
8
+ Copyright (c) 2009 Rubaidh Ltd, released under the MIT license.
data/Rakefile ADDED
@@ -0,0 +1,29 @@
1
+ require 'rake'
2
+ require 'rake/testtask'
3
+ require 'rake/rdoctask'
4
+ require 'rake/gempackagetask'
5
+
6
+ desc 'Default: run unit tests.'
7
+ task :default => :test
8
+
9
+ desc 'Test the generators plugin.'
10
+ Rake::TestTask.new(:test) do |t|
11
+ t.libs << 'lib'
12
+ t.libs << 'test'
13
+ t.pattern = 'test/**/*_test.rb'
14
+ t.verbose = true
15
+ end
16
+
17
+ desc 'Generate documentation for the generators plugin.'
18
+ Rake::RDocTask.new(:rdoc) do |rdoc|
19
+ rdoc.rdoc_dir = 'rdoc'
20
+ rdoc.title = 'Generators'
21
+ rdoc.options << '--line-numbers' << '--inline-source'
22
+ rdoc.rdoc_files.include('README.rdoc')
23
+ rdoc.rdoc_files.include('lib/**/*.rb')
24
+ end
25
+
26
+ Rake::GemPackageTask.new(eval(File.read('generators.gemspec'))) do |p|
27
+ p.need_tar = false
28
+ p.need_zip = false
29
+ end
data/TODO ADDED
@@ -0,0 +1,11 @@
1
+ = To do
2
+
3
+ * Fix the scaffold to successfully create singleton resources too.
4
+
5
+ * Create a layout generator which creates a sensible default layout using YUI
6
+ grids.
7
+
8
+ * Figure out how to do automated testing of generators.
9
+
10
+ * Figure a way to keep track of changes to the Rails (and RSpec) generators
11
+ used as inspiration so we can merge in changes.
data/bin/rubaidh_rails ADDED
@@ -0,0 +1,11 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require 'rubygems'
4
+ gem 'rails'
5
+
6
+ require 'rails/version'
7
+ require 'rails_generator'
8
+ require 'rails_generator/scripts/generate'
9
+
10
+ Rails::Generator::Base.use_application_sources!
11
+ Rails::Generator::Scripts::Generate.new.run(["-d", "mysql", "-m", File.join(File.dirname(__FILE__), '..', 'templates', 'rubaidh.rb')] + ARGV, :generator => 'app')
@@ -0,0 +1,31 @@
1
+ Description:
2
+ Stubs out a new controller, along with its helper, views and associated
3
+ specs. Pass the controller name, either CamelCased or under_scored, and a
4
+ list of views as arguments.
5
+
6
+ To create a controller within a module, specify the controller name as a
7
+ path like 'parent_module/controller_name'.
8
+
9
+ This generates a controller class in app/controllers, view templates in
10
+ app/views/controller_name, a helper class in app/helpers, a controller
11
+ spec in spec/controllers and a helper spec in spec/helpers.
12
+
13
+ Example:
14
+ `./script/generate controller CreditCard open debit credit close`
15
+
16
+ Credit card controller with URLs like /credit_card/debit.
17
+ Controller: app/controllers/credit_card_controller.rb
18
+ Controller Spec: spec/controllers/credit_card_controller_spec.rb
19
+ Views: app/views/credit_card/debit.html.erb [...]
20
+ Helper: app/helpers/credit_card_helper.rb
21
+ Helper Spec: spec/helpers/credit_card_helper_spec.rb
22
+
23
+ Modules Example:
24
+ `./script/generate controller 'admin/credit_card' suspend late_fee`
25
+
26
+ Credit card admin controller with URLs /admin/credit_card/suspend.
27
+ Controller: app/controllers/admin/credit_card_controller.rb
28
+ Controller Spec: spec/controllers/admin/credit_card_controller_spec.rb
29
+ Views: app/views/admin/credit_card/debit.html.erb [...]
30
+ Helper: app/helpers/admin/credit_card_helper.rb
31
+ Helper Spec: spec/helpers/admin/credit_card_helper_spec.rb
@@ -0,0 +1,40 @@
1
+ require File.join(File.dirname(__FILE__), '..', 'rubaidh_named_base')
2
+
3
+ class RubaidhControllerGenerator < RubaidhNamedBase
4
+ def manifest
5
+ record do |m|
6
+ # Check for class naming collisions.
7
+ m.class_collisions "#{class_name}Controller"
8
+
9
+ # Controller, helper, views, and spec directories.
10
+ m.directory File.join('app/controllers', class_path)
11
+ m.directory File.join('app/views', class_path, file_name)
12
+ m.directory File.join('spec/controllers', class_path)
13
+
14
+ # Controller spec, class, and helper.
15
+ m.template 'controller.rb',
16
+ File.join('app/controllers',
17
+ class_path,
18
+ "#{file_name}_controller.rb")
19
+
20
+ m.template 'controller_spec.rb',
21
+ File.join('spec/controllers',
22
+ class_path,
23
+ "#{file_name}_controller_spec.rb")
24
+
25
+ # View template for each action.
26
+ actions.each do |action|
27
+ path = File.join('app/views', class_path, file_name, "#{action}.html.erb")
28
+ m.template 'view.html.erb', path,
29
+ :assigns => { :action => action, :path => path }
30
+ end
31
+
32
+ m.dependency 'rubaidh_helper', [name] + @args
33
+ end
34
+ end
35
+
36
+ protected
37
+ def banner
38
+ "Usage: #{$0} #{spec.name} ControllerName [action]..."
39
+ end
40
+ end
@@ -0,0 +1,17 @@
1
+ # <%= class_name %> Controller
2
+ #
3
+ # Created on <%= Time.now.to_s :long %> by <%= user_full_name %> as part
4
+ # of the "<%= project_name %>" project.
5
+ #
6
+ #--
7
+ # Copyright (c) 2006-<%= Time.now.year %> Rubaidh Ltd. All rights reserved.
8
+ # See LICENSE in the top level source code folder for permissions.
9
+ #++
10
+
11
+ class <%= class_name %>Controller < ApplicationController
12
+ <% for action in actions -%>
13
+
14
+ def <%= action %>
15
+ end
16
+ <% end -%>
17
+ end
@@ -0,0 +1,29 @@
1
+ # <%= class_name %> Controller Spec
2
+ #
3
+ # Created on <%= Time.now.to_s :long %> by <%= user_full_name %> as part
4
+ # of the "<%= project_name %>" project.
5
+ #
6
+ #--
7
+ # Copyright (c) 2006-<%= Time.now.year %> Rubaidh Ltd. All rights reserved.
8
+ # See LICENSE in the top level source code folder for permissions.
9
+ #++
10
+
11
+ require File.expand_path(File.dirname(__FILE__) + '<%= '/..' * class_nesting_depth %>/../spec_helper')
12
+
13
+ describe <%= class_name %>Controller do
14
+ <% unless actions.empty? -%>
15
+ <% for action in actions -%>
16
+
17
+ describe "responding to GET '<%= action %>'" do
18
+ def do_get
19
+ get :<%= action %>
20
+ end
21
+
22
+ it "should be successful" do
23
+ do_get
24
+ response.should be_success
25
+ end
26
+ end
27
+ <% end -%>
28
+ <% end -%>
29
+ end
@@ -0,0 +1,2 @@
1
+ <h1><%= class_name %>#<%= action %></h1>
2
+ <p>Find me in <%= path %></p>
@@ -0,0 +1,23 @@
1
+ Description:
2
+ Stubs out a new helper. Pass the helper name, either
3
+ CamelCased or under_scored.
4
+
5
+ To create a helper within a module, specify the helper name as a
6
+ path like 'parent_module/helper_name'.
7
+
8
+ This generates a helper class in app/helpers and a helper spec
9
+ in spec/helpers.
10
+
11
+ Example:
12
+ `./script/generate helper CreditCard`
13
+
14
+ Credit card helper.
15
+ Helper: app/helpers/credit_card_helper.rb
16
+ Spec: spec/helpers/credit_card_helper_spec.rb
17
+
18
+ Modules Example:
19
+ `./script/generate helper 'admin/credit_card'`
20
+
21
+ Credit card admin helper.
22
+ Helper: app/helpers/admin/credit_card_helper.rb
23
+ Spec: spec/helpers/admin/credit_card_helper_spec.rb
@@ -0,0 +1,27 @@
1
+ require File.join(File.dirname(__FILE__), '..', 'rubaidh_named_base')
2
+
3
+ class RubaidhHelperGenerator < RubaidhNamedBase
4
+ def manifest
5
+ record do |m|
6
+ # Check for class naming collisions.
7
+ m.class_collisions "#{class_name}Helper"
8
+
9
+ # Helper and helper test directories.
10
+ m.directory File.join('app/helpers', class_path)
11
+ m.directory File.join('spec/helpers', class_path)
12
+
13
+ # Helper and helper test class.
14
+
15
+ m.template 'helper.rb',
16
+ File.join('app/helpers',
17
+ class_path,
18
+ "#{file_name}_helper.rb")
19
+
20
+ m.template 'helper_spec.rb',
21
+ File.join('spec/helpers',
22
+ class_path,
23
+ "#{file_name}_helper_spec.rb")
24
+
25
+ end
26
+ end
27
+ end
@@ -0,0 +1,12 @@
1
+ # <%= class_name %> Helper
2
+ #
3
+ # Created on <%= Time.now.to_s :long %> by <%= user_full_name %> as part
4
+ # of the "<%= project_name %>" project.
5
+ #
6
+ #--
7
+ # Copyright (c) 2006-<%= Time.now.year %> Rubaidh Ltd. All rights reserved.
8
+ # See LICENSE in the top level source code folder for permissions.
9
+ #++
10
+
11
+ module <%= class_name %>Helper
12
+ end
@@ -0,0 +1,14 @@
1
+ # <%= class_name %> Helper Spec
2
+ #
3
+ # Created on <%= Time.now.to_s :long %> by <%= user_full_name %> as part
4
+ # of the "<%= project_name %>" project.
5
+ #
6
+ #--
7
+ # Copyright (c) 2006-<%= Time.now.year %> Rubaidh Ltd. All rights reserved.
8
+ # See LICENSE in the top level source code folder for permissions.
9
+ #++
10
+
11
+ require File.expand_path(File.dirname(__FILE__) + '<%= '/..' * class_nesting_depth %>/../spec_helper')
12
+
13
+ describe <%= class_name %>Helper do
14
+ end
@@ -0,0 +1,25 @@
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, an rspec specification in
13
+ spec/models and a migration in db/migrate.
14
+
15
+ Examples:
16
+ `./script/generate model account`
17
+
18
+ creates an Account model, spec and migration:
19
+ Model: app/models/account.rb
20
+ Spec: spec/models/account_spec.rb
21
+ Migration: db/migrate/XXX_add_accounts.rb
22
+
23
+ `./script/generate model post title:string body:text published:boolean`
24
+
25
+ creates a Post model with a string title, text body, and published flag.
@@ -0,0 +1,29 @@
1
+ require File.join(File.dirname(__FILE__), '..', 'rubaidh_named_base')
2
+
3
+ class RubaidhModelGenerator < RubaidhNamedBase
4
+ def manifest
5
+ record do |m|
6
+ # Check for class naming collisions.
7
+ m.class_collisions class_name
8
+
9
+ # Model, test, and fixture directories.
10
+ m.directory File.join('app/models', class_path)
11
+ m.directory File.join('spec/models', class_path)
12
+ m.directory File.join('spec/exemplars', 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 'model_spec.rb', File.join('spec/models', class_path, "#{file_name}_spec.rb")
17
+ m.template 'model_exemplar.rb', File.join('spec/exemplars', class_path, "#{file_name}_exemplar.rb")
18
+
19
+ m.migration_template 'migration.rb', 'db/migrate', :assigns => {
20
+ :migration_name => "Create#{class_name.pluralize.gsub(/::/, '')}"
21
+ }, :migration_file_name => "create_#{file_path.gsub(/\//, '_').pluralize}"
22
+ end
23
+ end
24
+
25
+ protected
26
+ def banner
27
+ "Usage: #{$0} #{spec.name} ModelName [field:type] ..."
28
+ end
29
+ end
@@ -0,0 +1,25 @@
1
+ # <%= migration_name %> Migration
2
+ #
3
+ # Created on <%= Time.now.to_s :long %> by <%= user_full_name %> as part
4
+ # of the "<%= project_name %>" project.
5
+ #
6
+ #--
7
+ # Copyright (c) 2006-<%= Time.now.year %> Rubaidh Ltd. All rights reserved.
8
+ # See LICENSE in the top level source code folder for permissions.
9
+ #++
10
+
11
+ class <%= migration_name %> < ActiveRecord::Migration
12
+ def self.up
13
+ create_table :<%= table_name %> do |t|
14
+ <% attributes.each do |attribute| -%>
15
+ t.<%= attribute.type %> :<%= attribute.name %>
16
+ <% end -%>
17
+
18
+ t.timestamps
19
+ end
20
+ end
21
+
22
+ def self.down
23
+ drop_table :<%= table_name %>
24
+ end
25
+ end
@@ -0,0 +1,15 @@
1
+ # <%= class_name %> Model
2
+ #
3
+ # Created on <%= Time.now.to_s :long %> by <%= user_full_name %> as part
4
+ # of the "<%= project_name %>" project.
5
+ #
6
+ #--
7
+ # Copyright (c) 2006-<%= Time.now.year %> Rubaidh Ltd. All rights reserved.
8
+ # See LICENSE in the top level source code folder for permissions.
9
+ #++
10
+
11
+ class <%= class_name %> < ActiveRecord::Base
12
+ <% attributes.select(&:reference?).each do |attribute| -%>
13
+ belongs_to :<%= attribute.name %>
14
+ <% end -%>
15
+ end
@@ -0,0 +1,13 @@
1
+ # <%= class_name %> Exemplar
2
+ #
3
+ # Created on <%= Time.now.to_s :long %> by <%= user_full_name %> as part
4
+ # of the "<%= project_name %>" project.
5
+ #
6
+ #--
7
+ # Copyright (c) 2006-<%= Time.now.year %> Rubaidh Ltd. All rights reserved.
8
+ # See LICENSE in the top level source code folder for permissions.
9
+ #++
10
+
11
+ <%= class_name %>.class_eval do
12
+
13
+ end
@@ -0,0 +1,31 @@
1
+ # <%= class_name %> Specification
2
+ #
3
+ # Created on <%= Time.now.to_s :long %> by <%= user_full_name %> as part
4
+ # of the "<%= project_name %>" project.
5
+ #
6
+ #--
7
+ # Copyright (c) 2006-<%= Time.now.year %> Rubaidh Ltd. All rights reserved.
8
+ # See LICENSE in the top level source code folder for permissions.
9
+ #++
10
+
11
+ require File.expand_path(File.dirname(__FILE__) + '<%= '/..' * class_nesting_depth %>/../spec_helper')
12
+
13
+ describe <%= class_name %> do
14
+ describe "generator" do
15
+ it "should successfully create a new instance" do
16
+ lambda { <%= class_name %>.generate! }.should_not raise_error
17
+ end
18
+
19
+ it "should persist the new instance in the database" do
20
+ lambda { <%= class_name %>.generate }.should change(<%= class_name %>, :count).by(1)
21
+ end
22
+
23
+ it "should be valid" do
24
+ <%= class_name %>.generate.should be_valid
25
+ end
26
+ end
27
+
28
+ describe "validations" do
29
+
30
+ end
31
+ end
@@ -0,0 +1,31 @@
1
+ require 'grit'
2
+
3
+ class RubaidhNamedBase < Rails::Generator::NamedBase
4
+ attr_reader :project_name, :user_full_name
5
+
6
+ def initialize(runtime_args, runtime_options = {})
7
+ super
8
+
9
+ assign_additional_names!
10
+ end
11
+
12
+ private
13
+ def assign_additional_names!
14
+ @user_full_name = figure_out_full_name_from_git_repository
15
+ @project_name = figure_out_project_name_from_rails_root
16
+ end
17
+
18
+ def figure_out_full_name_from_git_repository
19
+ repos = Grit::Repo.new(RAILS_ROOT)
20
+
21
+ repos.config['user.name']
22
+ rescue StandardError => e
23
+ # If Grit::Repo raises an error, chances are it's not a git repository.
24
+ # It's not super-important, so just give up.
25
+ "a Rubaidh staff member"
26
+ end
27
+
28
+ def figure_out_project_name_from_rails_root
29
+ File.basename(RAILS_ROOT).humanize
30
+ end
31
+ end
@@ -0,0 +1,29 @@
1
+ Description:
2
+ Scaffolds an entire resource, from model and migration to controller and
3
+ views, along with a full rspec test suite. The resource is ready to use as
4
+ a starting point for your RESTful, resource-oriented application.
5
+
6
+ Pass the name of the model (in singular form), either CamelCased or
7
+ under_scored, as the first argument, and an optional list of attribute
8
+ pairs.
9
+
10
+ Attribute pairs are column_name:sql_type arguments specifying the
11
+ model's attributes. Timestamps are added by default, so you don't have to
12
+ specify them by hand as 'created_at:datetime updated_at:datetime'.
13
+
14
+ You don't have to think up every attribute up front, but it helps to
15
+ sketch out a few so you can start working with the resource immediately.
16
+
17
+ For example, 'scaffold post title:string body:text published:boolean'
18
+ gives you a model with those three attributes, a controller that handles
19
+ the create/show/update/destroy, forms to create and edit your posts, and
20
+ an index that lists them all, as well as a map.resources :posts
21
+ declaration in config/routes.rb.
22
+
23
+ If you want to remove all the generated files, run
24
+ 'script/destroy scaffold ModelName'.
25
+
26
+ Examples:
27
+ `./script/generate scaffold post`
28
+ `./script/generate scaffold post title:string body:text published:boolean`
29
+ `./script/generate scaffold purchase order_id:integer amount:decimal`
@@ -0,0 +1,90 @@
1
+ require File.join(File.dirname(__FILE__), '..', 'rubaidh_named_base')
2
+
3
+ class RubaidhScaffoldGenerator < RubaidhNamedBase
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_underscore_name,
11
+ :controller_singular_name,
12
+ :controller_plural_name
13
+ alias_method :controller_file_name, :controller_underscore_name
14
+ alias_method :controller_table_name, :controller_plural_name
15
+
16
+ def initialize(runtime_args, runtime_options = {})
17
+ super
18
+
19
+ if @name == @name.pluralize && !options[:force_plural]
20
+ logger.warning "Plural version of the model detected, using singularized version. Override with --force-plural."
21
+ @name = @name.singularize
22
+ end
23
+
24
+ @controller_name = @name.pluralize
25
+
26
+ base_name, @controller_class_path, @controller_file_path, @controller_class_nesting, @controller_class_nesting_depth = extract_modules(@controller_name)
27
+ @controller_class_name_without_nesting, @controller_underscore_name, @controller_plural_name = inflect_names(base_name)
28
+ @controller_singular_name=base_name.singularize
29
+ if @controller_class_nesting.empty?
30
+ @controller_class_name = @controller_class_name_without_nesting
31
+ else
32
+ @controller_class_name = "#{@controller_class_nesting}::#{@controller_class_name_without_nesting}"
33
+ end
34
+ end
35
+
36
+ def manifest
37
+ record do |m|
38
+ # Check for class naming collisions.
39
+ m.class_collisions "#{controller_class_name}Controller"
40
+
41
+ # Controller, helper, views, test and stylesheets directories.
42
+ m.directory(File.join('app/controllers', controller_class_path))
43
+ m.directory(File.join('app/views', controller_class_path, controller_file_name))
44
+ m.directory(File.join('spec/controllers', controller_class_path))
45
+
46
+ [ :index, :show, :new, :edit ].each do |view|
47
+ m.template(
48
+ "view_#{view}.html.erb",
49
+ File.join('app/views', controller_class_path, controller_file_name, "#{view}.html.erb")
50
+ )
51
+ end
52
+
53
+ m.template(
54
+ "partial_form.html.erb",
55
+ File.join('app/views', controller_class_path, controller_file_name, "_form.html.erb")
56
+ )
57
+
58
+ m.template(
59
+ "partial_layout.html.erb",
60
+ File.join('app/views', controller_class_path, controller_file_name, "_#{plural_name}.html.erb")
61
+ )
62
+
63
+ m.template(
64
+ "partial_model.html.erb",
65
+ File.join('app/views', controller_class_path, controller_file_name, "_#{singular_name}.html.erb")
66
+ )
67
+
68
+ m.template(
69
+ 'controller.rb', File.join('app/controllers', controller_class_path, "#{controller_file_name}_controller.rb")
70
+ )
71
+
72
+ m.template('routing_spec.rb', File.join('spec/controllers', controller_class_path, "#{controller_file_name}_routing_spec.rb"))
73
+ m.template('controller_spec.rb', File.join('spec/controllers', controller_class_path, "#{controller_file_name}_controller_spec.rb"))
74
+
75
+ m.route_resources controller_file_name
76
+
77
+ m.dependency 'rubaidh_model', [name] + @args
78
+ m.dependency 'rubaidh_helper', [plural_name] + @args
79
+ end
80
+ end
81
+
82
+ protected
83
+ def banner
84
+ "Usage: #{$0} #{spec.name} ModelName [field:type] ..."
85
+ end
86
+
87
+ def model_name
88
+ class_name.demodulize
89
+ end
90
+ end
@@ -0,0 +1,76 @@
1
+ # <%= class_name %> Controller
2
+ #
3
+ # Created on <%= Time.now.to_s :long %> by <%= user_full_name %> as part
4
+ # of the "<%= project_name %>" project.
5
+ #
6
+ #--
7
+ # Copyright (c) 2006-<%= Time.now.year %> Rubaidh Ltd. All rights reserved.
8
+ # See LICENSE in the top level source code folder for permissions.
9
+ #++
10
+
11
+ class <%= controller_class_name %>Controller < ApplicationController
12
+ def index
13
+ @<%= table_name %> = <%= class_name %>.all
14
+
15
+ respond_to do |format|
16
+ format.html # index.html.erb
17
+ end
18
+ end
19
+
20
+ def show
21
+ @<%= file_name %> = <%= class_name %>.find(params[:id])
22
+
23
+ respond_to do |format|
24
+ format.html # show.html.erb
25
+ end
26
+ end
27
+
28
+ def new
29
+ @<%= file_name %> = <%= class_name %>.new
30
+
31
+ respond_to do |format|
32
+ format.html # new.html.erb
33
+ end
34
+ end
35
+
36
+ def edit
37
+ @<%= file_name %> = <%= class_name %>.find(params[:id])
38
+
39
+ respond_to do |format|
40
+ format.html # edit.html.erb
41
+ end
42
+ end
43
+
44
+ def create
45
+ @<%= file_name %> = <%= class_name %>.new(params[:<%= file_name %>])
46
+
47
+ respond_to do |format|
48
+ if @<%= file_name %>.save
49
+ format.html { redirect_to(@<%= file_name %>) }
50
+ else
51
+ format.html { render :action => "new" }
52
+ end
53
+ end
54
+ end
55
+
56
+ def update
57
+ @<%= file_name %> = <%= class_name %>.find(params[:id])
58
+
59
+ respond_to do |format|
60
+ if @<%= file_name %>.update_attributes(params[:<%= file_name %>])
61
+ format.html { redirect_to(@<%= file_name %>) }
62
+ else
63
+ format.html { render :action => "edit" }
64
+ end
65
+ end
66
+ end
67
+
68
+ def destroy
69
+ @<%= file_name %> = <%= class_name %>.find(params[:id])
70
+ @<%= file_name %>.destroy
71
+
72
+ respond_to do |format|
73
+ format.html { redirect_to(<%= table_name %>_url) }
74
+ end
75
+ end
76
+ end