Changesets can be listed by changeset number.
The Git repository is here.
- Revision:
- 98
- Log:
Initial import of Hub, an account management application.
- Author:
- adh
- Date:
- Thu Oct 19 15:18:43 +0100 2006
- Size:
- 4276 Bytes
1 | class AuthenticatedGenerator < Rails::Generator::NamedBase |
2 | attr_reader :controller_name, |
3 | :controller_class_path, |
4 | :controller_file_path, |
5 | :controller_class_nesting, |
6 | :controller_class_nesting_depth, |
7 | :controller_class_name, |
8 | :controller_singular_name, |
9 | :controller_plural_name |
10 | alias_method :controller_file_name, :controller_singular_name |
11 | alias_method :controller_table_name, :controller_plural_name |
12 | |
13 | def initialize(runtime_args, runtime_options = {}) |
14 | super |
15 | |
16 | # Take controller name from the next argument. Default to the pluralized model name. |
17 | @controller_name = args.shift |
18 | @controller_name ||= ActiveRecord::Base.pluralize_table_names ? @name.pluralize : @name |
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", |
34 | #"#{controller_class_name}ControllerTest", |
35 | "#{controller_class_name}Helper" |
36 | m.class_collisions class_path, "#{class_name}" |
37 | #"#{class_name}Test" |
38 | m.class_collisions [], 'AuthenticatedSystem', 'AuthenticatedTestHelper' |
39 | |
40 | # Controller, helper, views, and test directories. |
41 | m.directory File.join('app/models', class_path) |
42 | m.directory File.join('app/controllers', controller_class_path) |
43 | m.directory File.join('app/helpers', controller_class_path) |
44 | m.directory File.join('app/views', controller_class_path, controller_file_name) |
45 | m.directory File.join('test/functional', controller_class_path) |
46 | m.directory File.join('test/unit', class_path) |
47 | |
48 | m.template 'model.rb', |
49 | File.join('app/models', |
50 | class_path, |
51 | "#{file_name}.rb") |
52 | |
53 | m.template 'controller.rb', |
54 | File.join('app/controllers', |
55 | controller_class_path, |
56 | "#{controller_file_name}_controller.rb") |
57 | |
58 | m.template 'authenticated_system.rb', |
59 | File.join('lib', 'authenticated_system.rb') |
60 | |
61 | m.template 'authenticated_test_helper.rb', |
62 | File.join('lib', 'authenticated_test_helper.rb') |
63 | |
64 | m.template 'functional_test.rb', |
65 | File.join('test/functional', |
66 | controller_class_path, |
67 | "#{controller_file_name}_controller_test.rb") |
68 | |
69 | m.template 'helper.rb', |
70 | File.join('app/helpers', |
71 | controller_class_path, |
72 | "#{controller_file_name}_helper.rb") |
73 | |
74 | m.template 'unit_test.rb', |
75 | File.join('test/unit', |
76 | class_path, |
77 | "#{file_name}_test.rb") |
78 | |
79 | m.template 'fixtures.yml', |
80 | File.join('test/fixtures', |
81 | "#{table_name}.yml") |
82 | |
83 | # Controller templates |
84 | %w( index login signup ).each do |action| |
85 | m.template "#{action}.rhtml", |
86 | File.join('app/views', controller_class_path, controller_file_name, "#{action}.rhtml") |
87 | end |
88 | |
89 | unless options[:skip_migration] |
90 | m.migration_template 'migration.rb', 'db/migrate', :assigns => { |
91 | :migration_name => "Create#{class_name.pluralize.gsub(/::/, '')}" |
92 | }, :migration_file_name => "create_#{file_path.gsub(/\//, '_').pluralize}" |
93 | end |
94 | end |
95 | end |
96 | |
97 | protected |
98 | # Override with your own usage banner. |
99 | def banner |
100 | "Usage: #{$0} authenticated ModelName [ControllerName]" |
101 | end |
102 | end |