thorero-gen 0.9.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/LICENSE +20 -0
- data/README +21 -0
- data/Rakefile +65 -0
- data/TODO +13 -0
- data/bin/merb-gen +10 -0
- data/lib/merb-gen.rb +37 -0
- data/lib/merb-gen/controller.rb +69 -0
- data/lib/merb-gen/freezer.rb +19 -0
- data/lib/merb-gen/generator.rb +55 -0
- data/lib/merb-gen/helper.rb +53 -0
- data/lib/merb-gen/merb.rb +27 -0
- data/lib/merb-gen/merb/merb_flat.rb +31 -0
- data/lib/merb-gen/merb/merb_full.rb +35 -0
- data/lib/merb-gen/merb/merb_very_flat.rb +33 -0
- data/lib/merb-gen/merb_plugin.rb +33 -0
- data/lib/merb-gen/migration.rb +69 -0
- data/lib/merb-gen/model.rb +67 -0
- data/lib/merb-gen/part_controller.rb +55 -0
- data/lib/merb-gen/resource.rb +32 -0
- data/lib/merb-gen/resource_controller.rb +91 -0
- data/lib/merb-gen/session_migration.rb +44 -0
- data/lib/merb-gen/slice.rb +25 -0
- data/lib/merb-gen/slice/full.rb +31 -0
- data/lib/merb-gen/slice/thin.rb +31 -0
- data/lib/merb-gen/slice/very_thin.rb +31 -0
- data/spec/controller_spec.rb +94 -0
- data/spec/merb_spec.rb +28 -0
- data/spec/migration_spec.rb +47 -0
- data/spec/model_spec.rb +95 -0
- data/spec/resource_controller_spec.rb +98 -0
- data/spec/spec_helper.rb +7 -0
- data/templates/application/merb/Rakefile +76 -0
- data/templates/application/merb/app/controllers/application.rb +2 -0
- data/templates/application/merb/app/controllers/exceptions.rb +13 -0
- data/templates/application/merb/app/helpers/global_helpers.rb +5 -0
- data/templates/application/merb/app/views/exceptions/internal_server_error.html.erb +216 -0
- data/templates/application/merb/app/views/exceptions/not_acceptable.html.erb +63 -0
- data/templates/application/merb/app/views/exceptions/not_found.html.erb +47 -0
- data/templates/application/merb/app/views/layout/application.html.erb +11 -0
- data/templates/application/merb/autotest/discover.rb +1 -0
- data/templates/application/merb/autotest/merb.rb +149 -0
- data/templates/application/merb/autotest/merb_rspec.rb +166 -0
- data/templates/application/merb/config/environments/development.rb +7 -0
- data/templates/application/merb/config/environments/production.rb +7 -0
- data/templates/application/merb/config/environments/rake.rb +7 -0
- data/templates/application/merb/config/environments/test.rb +6 -0
- data/templates/application/merb/config/init.rb +164 -0
- data/templates/application/merb/config/rack.rb +12 -0
- data/templates/application/merb/config/router.rb +35 -0
- data/templates/application/merb/public/images/merb.jpg +0 -0
- data/templates/application/merb/public/merb.fcgi +22 -0
- data/templates/application/merb/public/stylesheets/master.css +119 -0
- data/templates/application/merb/spec/spec.opts +0 -0
- data/templates/application/merb/spec/spec_helper.rb +13 -0
- data/templates/application/merb/test/test_helper.rb +14 -0
- data/templates/application/merb_flat/README.txt +10 -0
- data/templates/application/merb_flat/application.rb +15 -0
- data/templates/application/merb_flat/config/framework.rb +7 -0
- data/templates/application/merb_flat/config/init.rb +18 -0
- data/templates/application/merb_flat/views/foo.html.erb +3 -0
- data/templates/application/merb_plugin/LICENSE +20 -0
- data/templates/application/merb_plugin/README +4 -0
- data/templates/application/merb_plugin/Rakefile +59 -0
- data/templates/application/merb_plugin/TODO +5 -0
- data/templates/application/merb_plugin/lib/%base_name%.rb +18 -0
- data/templates/application/merb_plugin/lib/%base_name%/merbtasks.rb +6 -0
- data/templates/application/merb_plugin/spec/%base_name%_spec.rb +7 -0
- data/templates/application/merb_plugin/spec/spec_helper.rb +2 -0
- data/templates/application/merb_plugin/test/%base_name%_test.rb +0 -0
- data/templates/application/merb_plugin/test/test_helper.rb +2 -0
- data/templates/application/merb_very_flat/application.rbt +17 -0
- data/templates/application/slice/full/LICENSE +20 -0
- data/templates/application/slice/full/README +170 -0
- data/templates/application/slice/full/Rakefile +48 -0
- data/templates/application/slice/full/TODO +15 -0
- data/templates/application/slice/full/app/controllers/application.rb +5 -0
- data/templates/application/slice/full/app/controllers/main.rb +7 -0
- data/templates/application/slice/full/app/helpers/application_helper.rb +64 -0
- data/templates/application/slice/full/app/views/layout/%underscored_base_name%.html.erb +16 -0
- data/templates/application/slice/full/app/views/main/index.html.erb +1 -0
- data/templates/application/slice/full/lib/%base_name%.rb +78 -0
- data/templates/application/slice/full/lib/%base_name%/merbtasks.rb +166 -0
- data/templates/application/slice/full/lib/%base_name%/slicetasks.rb +18 -0
- data/templates/application/slice/full/public/javascripts/master.js +0 -0
- data/templates/application/slice/full/public/stylesheets/master.css +2 -0
- data/templates/application/slice/full/spec/%base_name%_spec.rb +130 -0
- data/templates/application/slice/full/spec/controllers/main_spec.rb +61 -0
- data/templates/application/slice/full/spec/spec_helper.rb +44 -0
- data/templates/application/slice/full/stubs/app/controllers/application.rb +2 -0
- data/templates/application/slice/full/stubs/app/controllers/main.rb +2 -0
- data/templates/application/slice/thin/LICENSE +20 -0
- data/templates/application/slice/thin/README +130 -0
- data/templates/application/slice/thin/Rakefile +46 -0
- data/templates/application/slice/thin/TODO +7 -0
- data/templates/application/slice/thin/application.rb +36 -0
- data/templates/application/slice/thin/lib/%base_name%.rb +93 -0
- data/templates/application/slice/thin/lib/%base_name%/merbtasks.rb +106 -0
- data/templates/application/slice/thin/lib/%base_name%/slicetasks.rb +18 -0
- data/templates/application/slice/thin/public/javascripts/master.js +0 -0
- data/templates/application/slice/thin/public/stylesheets/master.css +2 -0
- data/templates/application/slice/thin/stubs/application.rb +9 -0
- data/templates/application/slice/thin/views/layout/%underscored_base_name%.html.erb +16 -0
- data/templates/application/slice/thin/views/main/index.html.erb +1 -0
- data/templates/application/slice/very_thin/LICENSE +20 -0
- data/templates/application/slice/very_thin/README +110 -0
- data/templates/application/slice/very_thin/Rakefile +46 -0
- data/templates/application/slice/very_thin/TODO +7 -0
- data/templates/application/slice/very_thin/application.rb +36 -0
- data/templates/application/slice/very_thin/lib/%base_name%.rb +89 -0
- data/templates/application/slice/very_thin/lib/%base_name%/merbtasks.rb +106 -0
- data/templates/application/slice/very_thin/lib/%base_name%/slicetasks.rb +18 -0
- data/templates/component/controller/app/controllers/%file_name%.rb +11 -0
- data/templates/component/controller/app/views/%file_name%/index.html.erb +1 -0
- data/templates/component/controller/spec/controllers/%file_name%_spec.rb +7 -0
- data/templates/component/controller/test/controllers/%file_name%_test.rb +17 -0
- data/templates/component/freezer/script/frozen_merb +43 -0
- data/templates/component/helper/app/helpers/%file_name%_helper.rb +7 -0
- data/templates/component/helper/spec/helpers/%file_name%_helper_spec.rb +5 -0
- data/templates/component/migration/activerecord/schema/migrations/%file_name%.rb +19 -0
- data/templates/component/migration/datamapper/schema/migrations/%file_name%.rb +7 -0
- data/templates/component/migration/sequel/schema/migrations/%file_name%.rb +24 -0
- data/templates/component/model/activerecord/app/models/%file_name%.rb +2 -0
- data/templates/component/model/datamapper/app/models/%file_name%.rb +6 -0
- data/templates/component/model/none/app/models/%file_name%.rb +5 -0
- data/templates/component/model/rspec/spec/models/%file_name%_spec.rb +7 -0
- data/templates/component/model/sequel/app/models/%file_name%.rb +2 -0
- data/templates/component/model/test_unit/test/models/%file_name%_test.rb +9 -0
- data/templates/component/part_controller/app/parts/%file_name%_part.rb +9 -0
- data/templates/component/part_controller/app/parts/views/%file_name%_part/index.html.erb +3 -0
- data/templates/component/resource_controller/activerecord/app/controllers/%file_name%.rb +57 -0
- data/templates/component/resource_controller/activerecord/app/views/%file_name%/edit.html.erb +3 -0
- data/templates/component/resource_controller/activerecord/app/views/%file_name%/index.html.erb +3 -0
- data/templates/component/resource_controller/activerecord/app/views/%file_name%/new.html.erb +3 -0
- data/templates/component/resource_controller/activerecord/app/views/%file_name%/show.html.erb +3 -0
- data/templates/component/resource_controller/datamapper/app/controllers/%file_name%.rb +59 -0
- data/templates/component/resource_controller/datamapper/app/views/%file_name%/edit.html.erb +21 -0
- data/templates/component/resource_controller/datamapper/app/views/%file_name%/index.html.erb +24 -0
- data/templates/component/resource_controller/datamapper/app/views/%file_name%/new.html.erb +20 -0
- data/templates/component/resource_controller/datamapper/app/views/%file_name%/show.html.erb +14 -0
- data/templates/component/resource_controller/none/app/controllers/%file_name%.rb +36 -0
- data/templates/component/resource_controller/none/app/views/%file_name%/edit.html.erb +3 -0
- data/templates/component/resource_controller/none/app/views/%file_name%/index.html.erb +3 -0
- data/templates/component/resource_controller/none/app/views/%file_name%/new.html.erb +3 -0
- data/templates/component/resource_controller/none/app/views/%file_name%/show.html.erb +3 -0
- data/templates/component/resource_controller/sequel/app/controllers/%file_name%.rb +59 -0
- data/templates/component/resource_controller/sequel/app/views/%file_name%/edit.html.erb +3 -0
- data/templates/component/resource_controller/sequel/app/views/%file_name%/index.html.erb +3 -0
- data/templates/component/resource_controller/sequel/app/views/%file_name%/new.html.erb +3 -0
- data/templates/component/resource_controller/sequel/app/views/%file_name%/show.html.erb +3 -0
- data/templates/component/session_migration/activerecord/schema/migrations/%version%_sessions.rb +12 -0
- data/templates/component/session_migration/sequel/schema/migrations/%version%_sessions.rb +16 -0
- metadata +362 -0
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
module Merb::Generators
|
|
2
|
+
|
|
3
|
+
class MerbVeryFlatGenerator < ApplicationGenerator
|
|
4
|
+
|
|
5
|
+
def self.source_root
|
|
6
|
+
File.join(super, 'merb_very_flat')
|
|
7
|
+
end
|
|
8
|
+
|
|
9
|
+
desc <<-DESC
|
|
10
|
+
This generates a very flat merb application: the whole application
|
|
11
|
+
fits in one file, very much like Sinatra or Camping.
|
|
12
|
+
DESC
|
|
13
|
+
|
|
14
|
+
first_argument :name, :required => true, :desc => "Application name"
|
|
15
|
+
|
|
16
|
+
template :application do
|
|
17
|
+
source('application.rbt')
|
|
18
|
+
destination("#{app_name}.rb")
|
|
19
|
+
end
|
|
20
|
+
|
|
21
|
+
def app_name
|
|
22
|
+
self.name.snake_case
|
|
23
|
+
end
|
|
24
|
+
|
|
25
|
+
def class_name
|
|
26
|
+
self.name.camel_case
|
|
27
|
+
end
|
|
28
|
+
|
|
29
|
+
end
|
|
30
|
+
|
|
31
|
+
add_private :app_very_flat, MerbVeryFlatGenerator
|
|
32
|
+
|
|
33
|
+
end
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
module Merb::Generators
|
|
2
|
+
|
|
3
|
+
class MerbPluginGenerator < ApplicationGenerator
|
|
4
|
+
|
|
5
|
+
def self.source_root
|
|
6
|
+
File.join(super, 'merb_plugin')
|
|
7
|
+
end
|
|
8
|
+
|
|
9
|
+
option :testing_framework, :default => :rspec, :desc => 'Testing framework to use (one of: spec, test_unit)'
|
|
10
|
+
option :orm, :default => :none, :desc => 'Object-Relation Mapper to use (one of: none, activerecord, datamapper, sequel)'
|
|
11
|
+
option :bin, :as => :boolean # TODO: explain this
|
|
12
|
+
|
|
13
|
+
desc <<-DESC
|
|
14
|
+
Merb plugin generator: lets you kick start your Merb plugin.
|
|
15
|
+
DESC
|
|
16
|
+
|
|
17
|
+
glob!
|
|
18
|
+
|
|
19
|
+
first_argument :name, :required => true, :desc => "Plugin name"
|
|
20
|
+
|
|
21
|
+
def base_name
|
|
22
|
+
self.name.snake_case
|
|
23
|
+
end
|
|
24
|
+
|
|
25
|
+
def destination_root
|
|
26
|
+
File.join(@destination_root, base_name)
|
|
27
|
+
end
|
|
28
|
+
|
|
29
|
+
end
|
|
30
|
+
|
|
31
|
+
add :plugin, MerbPluginGenerator
|
|
32
|
+
|
|
33
|
+
end
|
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
module Merb::Generators
|
|
2
|
+
|
|
3
|
+
class MigrationGenerator < ComponentGenerator
|
|
4
|
+
|
|
5
|
+
def self.source_root
|
|
6
|
+
File.join(super, 'migration')
|
|
7
|
+
end
|
|
8
|
+
|
|
9
|
+
desc <<-DESC
|
|
10
|
+
This is a migration generator
|
|
11
|
+
DESC
|
|
12
|
+
|
|
13
|
+
option :orm, :desc => 'Object-Relation Mapper to use (one of: none, activerecord, datamapper, sequel)'
|
|
14
|
+
option :model, :as => :boolean, :desc => 'Specify this option to generate a migration which creates a table for the provided model'
|
|
15
|
+
|
|
16
|
+
first_argument :name, :required => true
|
|
17
|
+
second_argument :attributes, :as => :hash, :default => {}
|
|
18
|
+
|
|
19
|
+
template :migration_activerecord, :orm => :activerecord do
|
|
20
|
+
source('activerecord/schema/migrations/%file_name%.rb')
|
|
21
|
+
destination("schema/migrations/#{file_name}.rb")
|
|
22
|
+
end
|
|
23
|
+
|
|
24
|
+
template :migration_datamapper, :orm => :datamapper do
|
|
25
|
+
source('datamapper/schema/migrations/%file_name%.rb')
|
|
26
|
+
destination("schema/migrations/#{file_name}.rb")
|
|
27
|
+
end
|
|
28
|
+
|
|
29
|
+
template :migration_sequel, :orm => :sequel do
|
|
30
|
+
source('sequel/schema/migrations/%file_name%.rb')
|
|
31
|
+
destination("schema/migrations/#{file_name}.rb")
|
|
32
|
+
end
|
|
33
|
+
|
|
34
|
+
def table_name
|
|
35
|
+
self.name.snake_case.pluralize
|
|
36
|
+
end
|
|
37
|
+
|
|
38
|
+
def class_name
|
|
39
|
+
self.name.camel_case
|
|
40
|
+
end
|
|
41
|
+
|
|
42
|
+
def migration_name
|
|
43
|
+
self.name.snake_case
|
|
44
|
+
end
|
|
45
|
+
|
|
46
|
+
def file_name
|
|
47
|
+
"#{version}_#{migration_name}"
|
|
48
|
+
end
|
|
49
|
+
|
|
50
|
+
def version
|
|
51
|
+
# TODO: handle ActiveRecord timestamped migrations
|
|
52
|
+
format("%03d", current_migration_nr + 1)
|
|
53
|
+
end
|
|
54
|
+
|
|
55
|
+
protected
|
|
56
|
+
|
|
57
|
+
def destination_directory
|
|
58
|
+
File.join(destination_root, 'schema', 'migrations')
|
|
59
|
+
end
|
|
60
|
+
|
|
61
|
+
def current_migration_nr
|
|
62
|
+
current_migration_number = Dir["#{destination_directory}/*"].map{|f| File.basename(f).match(/^(\d+)/)[0].to_i }.max.to_i
|
|
63
|
+
end
|
|
64
|
+
|
|
65
|
+
end
|
|
66
|
+
|
|
67
|
+
add :migration, MigrationGenerator
|
|
68
|
+
|
|
69
|
+
end
|
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
module Merb::Generators
|
|
2
|
+
|
|
3
|
+
class ModelGenerator < ComponentGenerator
|
|
4
|
+
|
|
5
|
+
def self.source_root
|
|
6
|
+
File.join(super, 'model')
|
|
7
|
+
end
|
|
8
|
+
|
|
9
|
+
desc <<-DESC
|
|
10
|
+
Generates a new model. You can specify an ORM different from what the rest
|
|
11
|
+
of the application uses.
|
|
12
|
+
DESC
|
|
13
|
+
|
|
14
|
+
option :testing_framework, :desc => 'Testing framework to use (one of: spec, test_unit)'
|
|
15
|
+
option :orm, :desc => 'Object-Relation Mapper to use (one of: none, activerecord, datamapper, sequel)'
|
|
16
|
+
|
|
17
|
+
first_argument :name, :required => true, :desc => "model name"
|
|
18
|
+
second_argument :attributes, :as => :hash, :default => {}, :desc => "space separated model properties in form of name:type. Example: state:string"
|
|
19
|
+
|
|
20
|
+
invoke :migration do |generator|
|
|
21
|
+
generator.new(destination_root, options.merge(:model => true), name, attributes)
|
|
22
|
+
end
|
|
23
|
+
|
|
24
|
+
[:none, :activerecord, :sequel, :datamapper].each do |orm|
|
|
25
|
+
|
|
26
|
+
template "model_#{orm}".to_sym, :orm => orm do
|
|
27
|
+
source("#{orm}/app/models/%file_name%.rb")
|
|
28
|
+
destination("app/models/#{file_name}.rb")
|
|
29
|
+
end
|
|
30
|
+
|
|
31
|
+
end
|
|
32
|
+
|
|
33
|
+
template :spec, :testing_framework => :rspec do
|
|
34
|
+
source('rspec/spec/models/%file_name%_spec.rb')
|
|
35
|
+
destination('spec/models/' + file_name + '_spec.rb')
|
|
36
|
+
end
|
|
37
|
+
|
|
38
|
+
template :test_unit, :testing_framework => :test_unit do
|
|
39
|
+
source('test_unit/test/models/%file_name%_test.rb')
|
|
40
|
+
destination('test/models/' + file_name + '_test.rb')
|
|
41
|
+
end
|
|
42
|
+
|
|
43
|
+
def class_name
|
|
44
|
+
self.name.camel_case
|
|
45
|
+
end
|
|
46
|
+
|
|
47
|
+
def test_class_name
|
|
48
|
+
self.class_name + "Test"
|
|
49
|
+
end
|
|
50
|
+
|
|
51
|
+
def file_name
|
|
52
|
+
self.name.snake_case
|
|
53
|
+
end
|
|
54
|
+
|
|
55
|
+
def attributes?
|
|
56
|
+
self.attributes && !self.attributes.empty?
|
|
57
|
+
end
|
|
58
|
+
|
|
59
|
+
def attributes_for_accessor
|
|
60
|
+
self.attributes.keys.map{|a| ":#{a}" }.compact.uniq.join(", ")
|
|
61
|
+
end
|
|
62
|
+
|
|
63
|
+
end
|
|
64
|
+
|
|
65
|
+
add :model, ModelGenerator
|
|
66
|
+
|
|
67
|
+
end
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
module Merb::Generators
|
|
2
|
+
|
|
3
|
+
class PartControllerGenerator < ComponentGenerator
|
|
4
|
+
|
|
5
|
+
def self.source_root
|
|
6
|
+
File.join(super, 'part_controller')
|
|
7
|
+
end
|
|
8
|
+
|
|
9
|
+
desc <<-DESC
|
|
10
|
+
This is a part controller generator
|
|
11
|
+
DESC
|
|
12
|
+
|
|
13
|
+
first_argument :name, :required => true
|
|
14
|
+
|
|
15
|
+
invoke :helper do |generator|
|
|
16
|
+
generator.new(destination_root, options, "#{full_class_name}Part")
|
|
17
|
+
end
|
|
18
|
+
|
|
19
|
+
template :controller do
|
|
20
|
+
source('app/parts/%file_name%_part.rb')
|
|
21
|
+
destination("app/parts/#{file_name}_part.rb")
|
|
22
|
+
end
|
|
23
|
+
|
|
24
|
+
template :index do
|
|
25
|
+
source('app/parts/views/%file_name%_part/index.html.erb')
|
|
26
|
+
destination("app/parts/views/#{file_name}_part/index.html.erb")
|
|
27
|
+
end
|
|
28
|
+
|
|
29
|
+
def controller_modules
|
|
30
|
+
chunks[0..-2]
|
|
31
|
+
end
|
|
32
|
+
|
|
33
|
+
def controller_class_name
|
|
34
|
+
chunks.last
|
|
35
|
+
end
|
|
36
|
+
|
|
37
|
+
def full_class_name
|
|
38
|
+
chunks.join('::')
|
|
39
|
+
end
|
|
40
|
+
|
|
41
|
+
def file_name
|
|
42
|
+
controller_class_name.snake_case
|
|
43
|
+
end
|
|
44
|
+
|
|
45
|
+
protected
|
|
46
|
+
|
|
47
|
+
def chunks
|
|
48
|
+
name.gsub('/', '::').split('::').map { |c| c.camel_case }
|
|
49
|
+
end
|
|
50
|
+
|
|
51
|
+
end
|
|
52
|
+
|
|
53
|
+
add :part, PartControllerGenerator
|
|
54
|
+
|
|
55
|
+
end
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
module Merb::Generators
|
|
2
|
+
|
|
3
|
+
class ResourceGenerator < ComponentGenerator
|
|
4
|
+
|
|
5
|
+
desc <<-DESC
|
|
6
|
+
Generates a new resource.
|
|
7
|
+
DESC
|
|
8
|
+
|
|
9
|
+
first_argument :name, :required => true, :desc => "resource name"
|
|
10
|
+
second_argument :attributes, :as => :hash, :default => {}, :desc => "space separated resource model properties in form of name:type. Example: state:string"
|
|
11
|
+
|
|
12
|
+
invoke :model do |generator|
|
|
13
|
+
generator.new(destination_root, options, model_name, attributes)
|
|
14
|
+
end
|
|
15
|
+
|
|
16
|
+
invoke :resource_controller do |generator|
|
|
17
|
+
generator.new(destination_root, options, controller_name, attributes)
|
|
18
|
+
end
|
|
19
|
+
|
|
20
|
+
def controller_name
|
|
21
|
+
name.pluralize
|
|
22
|
+
end
|
|
23
|
+
|
|
24
|
+
def model_name
|
|
25
|
+
name.singularize
|
|
26
|
+
end
|
|
27
|
+
|
|
28
|
+
end
|
|
29
|
+
|
|
30
|
+
add :resource, ResourceGenerator
|
|
31
|
+
|
|
32
|
+
end
|
|
@@ -0,0 +1,91 @@
|
|
|
1
|
+
module Merb::Generators
|
|
2
|
+
|
|
3
|
+
class ResourceControllerGenerator < ComponentGenerator
|
|
4
|
+
|
|
5
|
+
def self.source_root
|
|
6
|
+
File.join(super, 'resource_controller')
|
|
7
|
+
end
|
|
8
|
+
|
|
9
|
+
desc <<-DESC
|
|
10
|
+
Generates a new resource controller.
|
|
11
|
+
DESC
|
|
12
|
+
|
|
13
|
+
option :testing_framework, :desc => 'Testing framework to use (one of: spec, test_unit)'
|
|
14
|
+
option :orm, :desc => 'Object-Relation Mapper to use (one of: none, activerecord, datamapper, sequel)'
|
|
15
|
+
|
|
16
|
+
first_argument :name, :required => true,
|
|
17
|
+
:desc => "model name"
|
|
18
|
+
second_argument :attributes, :as => :hash,
|
|
19
|
+
:default => {},
|
|
20
|
+
:desc => "space separated resource model properties in form of name:type. Example: state:string"
|
|
21
|
+
|
|
22
|
+
invoke :helper do |generator|
|
|
23
|
+
generator.new(destination_root, options, name)
|
|
24
|
+
end
|
|
25
|
+
|
|
26
|
+
# add controller and view templates for each of the four big ORM's
|
|
27
|
+
[:none, :activerecord, :sequel, :datamapper].each do |orm|
|
|
28
|
+
|
|
29
|
+
template "controller_#{orm}".to_sym, :orm => orm do
|
|
30
|
+
source("#{orm}/app/controllers/%file_name%.rb")
|
|
31
|
+
destination("app/controllers/#{file_name}.rb")
|
|
32
|
+
end
|
|
33
|
+
|
|
34
|
+
[:index, :show, :edit, :new].each do |view|
|
|
35
|
+
template "view_#{view}_#{orm}".to_sym, :orm => orm do
|
|
36
|
+
source("#{orm}/app/views/%file_name%/#{view}.html.erb")
|
|
37
|
+
destination("app/views/#{file_name}/#{view}.html.erb")
|
|
38
|
+
end
|
|
39
|
+
end
|
|
40
|
+
|
|
41
|
+
end
|
|
42
|
+
|
|
43
|
+
def controller_modules
|
|
44
|
+
chunks[0..-2]
|
|
45
|
+
end
|
|
46
|
+
|
|
47
|
+
def controller_class_name
|
|
48
|
+
chunks.last
|
|
49
|
+
end
|
|
50
|
+
|
|
51
|
+
def test_class_name
|
|
52
|
+
controller_class_name + "Test"
|
|
53
|
+
end
|
|
54
|
+
|
|
55
|
+
def file_name
|
|
56
|
+
controller_class_name.snake_case
|
|
57
|
+
end
|
|
58
|
+
|
|
59
|
+
def model_class_name
|
|
60
|
+
controller_class_name.singularize
|
|
61
|
+
end
|
|
62
|
+
|
|
63
|
+
def plural_model
|
|
64
|
+
controller_class_name.snake_case
|
|
65
|
+
end
|
|
66
|
+
|
|
67
|
+
def singular_model
|
|
68
|
+
plural_model.singularize
|
|
69
|
+
end
|
|
70
|
+
|
|
71
|
+
# TODO: fix this for Datamapper, so that it returns the primary keys for the model
|
|
72
|
+
def params_for_get
|
|
73
|
+
"params[:id]"
|
|
74
|
+
end
|
|
75
|
+
|
|
76
|
+
# TODO: implement this for Datamapper so that we get the model properties
|
|
77
|
+
def properties
|
|
78
|
+
[]
|
|
79
|
+
end
|
|
80
|
+
|
|
81
|
+
protected
|
|
82
|
+
|
|
83
|
+
def chunks
|
|
84
|
+
name.gsub('/', '::').split('::').map { |c| c.camel_case }
|
|
85
|
+
end
|
|
86
|
+
|
|
87
|
+
end
|
|
88
|
+
|
|
89
|
+
add :resource_controller, ResourceControllerGenerator
|
|
90
|
+
|
|
91
|
+
end
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
module Merb::Generators
|
|
2
|
+
|
|
3
|
+
class SessionMigrationGenerator < ComponentGenerator
|
|
4
|
+
|
|
5
|
+
def self.source_root
|
|
6
|
+
File.join(super, 'session_migration')
|
|
7
|
+
end
|
|
8
|
+
|
|
9
|
+
desc <<-DESC
|
|
10
|
+
Generates a new session migration.
|
|
11
|
+
DESC
|
|
12
|
+
|
|
13
|
+
option :orm, :desc => 'Object-Relation Mapper to use (one of: none, activerecord, datamapper, sequel)'
|
|
14
|
+
|
|
15
|
+
template :session_migration_activerecord, :orm => :activerecord do
|
|
16
|
+
source('activerecord/schema/migrations/%version%_sessions.rb')
|
|
17
|
+
destination("schema/migrations/#{version}_sessions.rb")
|
|
18
|
+
end
|
|
19
|
+
|
|
20
|
+
template :session_migration_sequel, :orm => :sequel do
|
|
21
|
+
source('sequel/schema/migrations/%version%_sessions.rb')
|
|
22
|
+
destination("schema/migrations/#{version}_sessions.rb")
|
|
23
|
+
end
|
|
24
|
+
|
|
25
|
+
def version
|
|
26
|
+
# TODO: handle ActiveRecord timestamped migrations
|
|
27
|
+
format("%03d", current_migration_nr + 1)
|
|
28
|
+
end
|
|
29
|
+
|
|
30
|
+
protected
|
|
31
|
+
|
|
32
|
+
def destination_directory
|
|
33
|
+
File.join(destination_root, 'schema', 'migrations')
|
|
34
|
+
end
|
|
35
|
+
|
|
36
|
+
def current_migration_nr
|
|
37
|
+
current_migration_number = Dir["#{destination_directory}/*"].map{|f| File.basename(f).match(/^(\d+)/)[0].to_i }.max.to_i
|
|
38
|
+
end
|
|
39
|
+
|
|
40
|
+
end
|
|
41
|
+
|
|
42
|
+
add :session_migration, SessionMigrationGenerator
|
|
43
|
+
|
|
44
|
+
end
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
module Merb::Generators
|
|
2
|
+
|
|
3
|
+
class SliceGenerator < ApplicationGenerator
|
|
4
|
+
|
|
5
|
+
def self.source_root
|
|
6
|
+
File.join(super, 'merb')
|
|
7
|
+
end
|
|
8
|
+
|
|
9
|
+
option :thin, :as => :boolean, :desc => 'Generates a thin slice'
|
|
10
|
+
option :very_thin, :as => :boolean, :desc => 'Generates an even thinner slice'
|
|
11
|
+
|
|
12
|
+
desc <<-DESC
|
|
13
|
+
Generates a merb slice.
|
|
14
|
+
DESC
|
|
15
|
+
|
|
16
|
+
first_argument :name, :required => true
|
|
17
|
+
|
|
18
|
+
invoke :full_slice, :thin => nil, :very_thin => nil
|
|
19
|
+
invoke :thin_slice, :thin => true
|
|
20
|
+
invoke :very_thin_slice, :very_thin => true
|
|
21
|
+
end
|
|
22
|
+
|
|
23
|
+
add :slice, SliceGenerator
|
|
24
|
+
|
|
25
|
+
end
|