merb-gen 0.9.8 → 0.9.9

Sign up to get free protection for your applications and to get access to all the features.
Files changed (116) hide show
  1. data/README +6 -3
  2. data/Rakefile +6 -4
  3. data/bin/merb-gen +1 -23
  4. data/lib/generators/controller.rb +4 -2
  5. data/lib/generators/helper.rb +0 -5
  6. data/lib/generators/merb/merb_core.rb +95 -0
  7. data/lib/generators/merb/merb_flat.rb +70 -69
  8. data/lib/generators/merb/merb_stack.rb +110 -0
  9. data/lib/generators/merb/merb_very_flat.rb +61 -64
  10. data/lib/generators/merb_plugin.rb +5 -0
  11. data/lib/generators/model.rb +5 -2
  12. data/lib/generators/resource.rb +7 -2
  13. data/lib/generators/resource_controller.rb +4 -4
  14. data/lib/generators/templates/application/common/Rakefile +2 -6
  15. data/lib/generators/templates/application/common/doc.thor +149 -0
  16. data/lib/generators/templates/application/common/dothtaccess +17 -0
  17. data/lib/generators/templates/application/common/jquery.js +32 -0
  18. data/lib/generators/templates/application/common/merb.thor +1550 -861
  19. data/lib/generators/templates/application/{merb → merb_core}/app/controllers/application.rb +0 -0
  20. data/lib/generators/templates/application/{merb → merb_core}/app/controllers/exceptions.rb +0 -0
  21. data/lib/generators/templates/application/{merb → merb_core}/app/helpers/global_helpers.rb +0 -0
  22. data/lib/generators/templates/application/{merb → merb_core}/app/views/exceptions/internal_server_error.html.erb +0 -0
  23. data/lib/generators/templates/application/{merb → merb_core}/app/views/exceptions/not_acceptable.html.erb +0 -0
  24. data/lib/generators/templates/application/{merb → merb_core}/app/views/exceptions/not_found.html.erb +0 -0
  25. data/lib/generators/templates/application/{merb → merb_core}/autotest/discover.rb +0 -0
  26. data/lib/generators/templates/application/{merb → merb_core}/autotest/merb.rb +0 -0
  27. data/lib/generators/templates/application/{merb → merb_core}/autotest/merb_rspec.rb +0 -0
  28. data/lib/generators/templates/application/{merb → merb_core}/config/environments/development.rb +7 -2
  29. data/lib/generators/templates/application/{merb → merb_core}/config/environments/production.rb +5 -2
  30. data/lib/generators/templates/application/{merb → merb_core}/config/environments/rake.rb +6 -2
  31. data/lib/generators/templates/application/merb_core/config/environments/staging.rb +10 -0
  32. data/lib/generators/templates/application/merb_core/config/environments/test.rb +12 -0
  33. data/lib/generators/templates/application/{merb → merb_core}/config/init.rb +6 -6
  34. data/lib/generators/templates/application/{merb → merb_core}/config/rack.rb +0 -0
  35. data/lib/generators/templates/application/{merb → merb_core}/config/router.rb +0 -0
  36. data/lib/generators/templates/application/merb_core/doc/rdoc/generators/merb_generator.rb +1362 -0
  37. data/lib/generators/templates/application/merb_core/doc/rdoc/generators/template/merb/api_grease.js +640 -0
  38. data/lib/generators/templates/application/merb_core/doc/rdoc/generators/template/merb/index.html.erb +37 -0
  39. data/lib/generators/templates/application/merb_core/doc/rdoc/generators/template/merb/merb.css +252 -0
  40. data/lib/generators/templates/application/merb_core/doc/rdoc/generators/template/merb/merb.rb +351 -0
  41. data/lib/generators/templates/application/merb_core/doc/rdoc/generators/template/merb/merb_doc_styles.css +492 -0
  42. data/lib/generators/templates/application/merb_core/doc/rdoc/generators/template/merb/prototype.js +2515 -0
  43. data/lib/generators/templates/application/{merb/app/models → merb_core/lib}/merb/session.rb +0 -0
  44. data/lib/generators/templates/application/{merb → merb_core}/public/favicon.ico +0 -0
  45. data/lib/generators/templates/application/{merb → merb_core}/public/images/merb.jpg +0 -0
  46. data/lib/generators/templates/application/merb_core/public/javascripts/application.js +1 -0
  47. data/lib/generators/templates/application/{merb → merb_core}/public/merb.fcgi +0 -0
  48. data/lib/generators/templates/application/{merb → merb_core}/public/robots.txt +0 -0
  49. data/lib/generators/templates/application/{merb → merb_core}/public/stylesheets/master.css +0 -0
  50. data/lib/generators/templates/application/{merb → merb_core}/spec/spec.opts +0 -0
  51. data/lib/generators/templates/application/{merb → merb_core}/spec/spec_helper.rb +0 -0
  52. data/lib/generators/templates/application/{merb → merb_core}/test/test_helper.rb +0 -0
  53. data/lib/generators/templates/application/merb_flat/application.rbt +1 -1
  54. data/lib/generators/templates/application/merb_flat/config/init.rb +8 -3
  55. data/lib/generators/templates/application/merb_plugin/LICENSE +1 -1
  56. data/lib/generators/templates/application/merb_stack/app/controllers/application.rb +2 -0
  57. data/lib/generators/templates/application/merb_stack/app/controllers/exceptions.rb +13 -0
  58. data/lib/generators/templates/application/merb_stack/app/helpers/global_helpers.rb +5 -0
  59. data/lib/generators/templates/application/merb_stack/app/models/user.rb +17 -0
  60. data/lib/generators/templates/application/merb_stack/app/views/exceptions/internal_server_error.html.erb +216 -0
  61. data/lib/generators/templates/application/merb_stack/app/views/exceptions/not_acceptable.html.erb +63 -0
  62. data/lib/generators/templates/application/merb_stack/app/views/exceptions/not_found.html.erb +47 -0
  63. data/lib/generators/templates/application/merb_stack/autotest/discover.rb +1 -0
  64. data/lib/generators/templates/application/merb_stack/autotest/merb.rb +149 -0
  65. data/lib/generators/templates/application/merb_stack/autotest/merb_rspec.rb +165 -0
  66. data/lib/generators/templates/application/merb_stack/config/database.yml +33 -0
  67. data/lib/generators/templates/application/merb_stack/config/dependencies.rb +15 -0
  68. data/lib/generators/templates/application/merb_stack/config/environments/development.rb +15 -0
  69. data/lib/generators/templates/application/merb_stack/config/environments/production.rb +10 -0
  70. data/lib/generators/templates/application/merb_stack/config/environments/rake.rb +11 -0
  71. data/lib/generators/templates/application/merb_stack/config/environments/staging.rb +10 -0
  72. data/lib/generators/templates/application/merb_stack/config/environments/test.rb +12 -0
  73. data/lib/generators/templates/application/merb_stack/config/init.rb +24 -0
  74. data/lib/generators/templates/application/merb_stack/config/rack.rb +12 -0
  75. data/lib/generators/templates/application/merb_stack/config/router.rb +44 -0
  76. data/lib/generators/templates/application/merb_stack/doc/rdoc/generators/merb_generator.rb +1362 -0
  77. data/lib/generators/templates/application/merb_stack/doc/rdoc/generators/template/merb/api_grease.js +640 -0
  78. data/lib/generators/templates/application/merb_stack/doc/rdoc/generators/template/merb/index.html.erb +37 -0
  79. data/lib/generators/templates/application/merb_stack/doc/rdoc/generators/template/merb/merb.css +252 -0
  80. data/lib/generators/templates/application/merb_stack/doc/rdoc/generators/template/merb/merb.rb +351 -0
  81. data/lib/generators/templates/application/merb_stack/doc/rdoc/generators/template/merb/merb_doc_styles.css +492 -0
  82. data/lib/generators/templates/application/merb_stack/doc/rdoc/generators/template/merb/prototype.js +2515 -0
  83. data/lib/generators/templates/application/merb_stack/merb/merb-auth/setup.rb +44 -0
  84. data/lib/generators/templates/application/merb_stack/merb/merb-auth/strategies.rb +11 -0
  85. data/lib/generators/templates/application/merb_stack/merb/session/session.rb +9 -0
  86. data/lib/generators/templates/application/merb_stack/public/favicon.ico +0 -0
  87. data/lib/generators/templates/application/merb_stack/public/images/merb.jpg +0 -0
  88. data/lib/generators/templates/application/merb_stack/public/javascripts/application.js +1 -0
  89. data/lib/generators/templates/application/merb_stack/public/merb.fcgi +22 -0
  90. data/lib/generators/templates/application/merb_stack/public/robots.txt +5 -0
  91. data/lib/generators/templates/application/merb_stack/public/stylesheets/master.css +119 -0
  92. data/lib/generators/templates/application/merb_stack/spec/spec.opts +0 -0
  93. data/lib/generators/templates/application/merb_stack/spec/spec_helper.rb +20 -0
  94. data/lib/generators/templates/application/merb_stack/test/test_helper.rb +19 -0
  95. data/lib/generators/templates/application/merb_very_flat/application.rbt +11 -5
  96. data/lib/generators/templates/component/layout/app/views/layout/%file_name%.html.erb +1 -0
  97. data/lib/generators/templates/component/resource_controller/spec/requests/%file_name%_spec.rb +53 -0
  98. data/lib/merb-gen/app_generator.rb +13 -0
  99. data/lib/merb-gen/generator.rb +36 -1
  100. data/lib/merb-gen/named_generator.rb +5 -2
  101. data/lib/merb-gen.rb +6 -8
  102. data/spec/controller_spec.rb +0 -20
  103. data/spec/{merb_full_spec.rb → merb_core_spec.rb} +11 -3
  104. data/spec/merb_stack_spec.rb +47 -0
  105. data/spec/part_controller_spec.rb +0 -39
  106. data/spec/resource_controller_spec.rb +1 -35
  107. data/spec/spec_helper.rb +4 -2
  108. metadata +133 -111
  109. data/lib/generators/merb/merb_full.rb +0 -85
  110. data/lib/generators/merb.rb +0 -24
  111. data/lib/generators/templates/application/merb/config/environments/staging.rb +0 -7
  112. data/lib/generators/templates/application/merb/config/environments/test.rb +0 -7
  113. data/lib/generators/templates/component/helper/spec/helpers/%file_name%_helper_spec.rb +0 -5
  114. data/lib/generators/templates/component/resource_controller/spec/controllers/%file_name%_spec.rb +0 -7
  115. data/spec/helper_spec.rb +0 -43
  116. data/spec/merb_spec.rb +0 -20
data/README CHANGED
@@ -6,10 +6,13 @@ generators for Merb.
6
6
  ==== Usage
7
7
 
8
8
  To generate directory structure for a new merb app, run merb-gen app <app-name>.
9
- For instance, <tt>merb-gen app foo</tt> would create a new foo merb app inside of the foo directory.
9
+ For instance, <tt>merb-gen app foo</tt> would create a new foo merb stack application
10
+ inside of the foo directory. Merb stack sets up commonly used Merb and DataMapper gems
11
+ to quickly get you started.
10
12
 
11
- Use <tt>--flat</tt> to generate a flattened application (very simple directory structure)
12
- and <tt>--very-flat</tt> to generate a single file application.
13
+ Use <tt>merb-gen core</tt> to generate minimal merb-core application with full layout.
14
+ Use <tt>merb-gen flat</tt> to generate a flattened application (very simple directory structure)
15
+ and <tt>merb-gen very-flat</tt> to generate a single file application.
13
16
 
14
17
  To generate a new merb plugin, run merb-gen plugin &lt;plugin_name&gt;.
15
18
 
data/Rakefile CHANGED
@@ -4,6 +4,8 @@ require "extlib"
4
4
  require 'merb-core/tasks/merb_rake_helper'
5
5
  require "spec/rake/spectask"
6
6
 
7
+ require File.join(File.dirname(__FILE__), "../merb-core/lib/merb-core/version.rb")
8
+
7
9
  ##############################################################################
8
10
  # Package && release
9
11
  ##############################################################################
@@ -17,7 +19,7 @@ GEM_EMAIL = "jonas.nicklas@gmail.com"
17
19
 
18
20
  GEM_NAME = "merb-gen"
19
21
  PKG_BUILD = ENV['PKG_BUILD'] ? '.' + ENV['PKG_BUILD'] : ''
20
- GEM_VERSION = (Merb::MORE_VERSION rescue "0.9.8") + PKG_BUILD
22
+ GEM_VERSION = Merb::VERSION + PKG_BUILD
21
23
 
22
24
  RELEASE_NAME = "REL #{GEM_VERSION}"
23
25
 
@@ -38,11 +40,11 @@ spec = Gem::Specification.new do |s|
38
40
  s.bindir = "bin"
39
41
  s.executables = %w( merb-gen )
40
42
 
41
- s.add_dependency "merb-core", ">= 0.9.8"
42
- s.add_dependency "templater", ">= 0.3.0"
43
+ s.add_dependency "merb-core", ">= 0.9.9"
44
+ s.add_dependency "templater", ">= 0.3.3"
43
45
 
44
46
  s.require_path = 'lib'
45
- s.files = %w(LICENSE README Rakefile TODO) + Dir.glob("{lib,bin,spec}/**/*")
47
+ s.files = %w(LICENSE README Rakefile TODO) + Dir.glob("{lib,bin,spec,merb}/**/*")
46
48
  end
47
49
 
48
50
  Rake::GemPackageTask.new(spec) do |pkg|
data/bin/merb-gen CHANGED
@@ -3,26 +3,4 @@
3
3
  require 'rubygems'
4
4
  require 'merb-gen'
5
5
 
6
- if ARGV[0] == "app"
7
- Merb::Generators.run_cli(Dir.pwd, 'merb-gen', Merb::VERSION, ARGV)
8
- else
9
- Merb::BootLoader.after_app_loads do
10
- Merb::Generators.run_cli(Dir.pwd, 'merb-gen', Merb::VERSION, ARGV)
11
- end
12
-
13
- Merb::Config.setup({
14
- :log_level => :fatal,
15
- :log_delimiter => " ~ ",
16
- :log_auto_flush => false,
17
- :reload_templates => false,
18
- :reload_classes => false
19
- })
20
-
21
- Merb::BootLoader::Logger.run
22
- Merb::BootLoader::BuildFramework.run
23
- Merb::BootLoader::Dependencies.run
24
-
25
- Merb::BootLoader::BeforeAppLoads.run
26
- Merb::BootLoader::ReloadClasses.run
27
- Merb::BootLoader::AfterAppLoads.run
28
- end
6
+ Merb::Generators.run_cli(Dir.pwd, 'merb-gen', Merb::VERSION, ARGV)
@@ -36,9 +36,11 @@ module Merb::Generators
36
36
  template.source = 'test/controllers/%file_name%_test.rb'
37
37
  template.destination = "test/controllers" / base_path / "#{file_name}_test.rb"
38
38
  end
39
-
39
+
40
+ def after_generation
41
+ STDOUT.puts "\n\nDon't forget to add request/controller tests first."
42
+ end
40
43
  end
41
44
 
42
45
  add :controller, ControllerGenerator
43
-
44
46
  end
@@ -19,11 +19,6 @@ module Merb::Generators
19
19
  template.destination = "app/helpers" / base_path / "#{file_name}_helper.rb"
20
20
  end
21
21
 
22
- template :helper_spec, :testing_framework => :rspec do |template|
23
- template.source = 'spec/helpers/%file_name%_helper_spec.rb'
24
- template.destination = "spec/helpers" / base_path / "#{file_name}_helper_spec.rb"
25
- end
26
-
27
22
  end
28
23
 
29
24
  add :helper, HelperGenerator
@@ -0,0 +1,95 @@
1
+ module Merb
2
+ module Generators
3
+ class MerbCoreGenerator < AppGenerator
4
+ #
5
+ # ==== Paths
6
+ #
7
+
8
+ def self.source_root
9
+ File.join(super, 'application', 'merb_core')
10
+ end
11
+
12
+ def self.common_templates_dir
13
+ File.expand_path(File.join(File.dirname(__FILE__), '..',
14
+ 'templates', 'application', 'common'))
15
+ end
16
+
17
+ def destination_root
18
+ File.join(@destination_root, base_name)
19
+ end
20
+
21
+ def common_templates_dir
22
+ self.class.common_templates_dir
23
+ end
24
+
25
+ #
26
+ # ==== Generator options
27
+ #
28
+
29
+ option :testing_framework, :default => :rspec,
30
+ :desc => 'Testing framework to use (one of: rspec, test_unit).'
31
+ option :orm, :default => :none,
32
+ :desc => 'Object-Relation Mapper to use (one of: none, activerecord, datamapper, sequel).'
33
+ option :template_engine, :default => :erb,
34
+ :desc => 'Template engine to prefer for this application (one of: erb, haml).'
35
+
36
+ desc <<-DESC
37
+ This generates a Merb application with Ruby on Rails like structure.
38
+ Generator lets you configure your ORM and testing framework of choice.
39
+ DESC
40
+
41
+ first_argument :name, :required => true, :desc => "Application name"
42
+
43
+ #
44
+ # ==== Common directories & files
45
+ #
46
+
47
+ empty_directory :gems, 'gems'
48
+ file :thorfile do |file|
49
+ file.source = File.join(common_templates_dir, "merb.thor")
50
+ file.destination = "merb.thor"
51
+ end
52
+
53
+ template :rakefile do |template|
54
+ template.source = File.join(common_templates_dir, "Rakefile")
55
+ template.destination = "Rakefile"
56
+ end
57
+
58
+ file :gitignore do |file|
59
+ file.source = File.join(common_templates_dir, 'dotgitignore')
60
+ file.destination = ".gitignore"
61
+ end
62
+
63
+ file :htaccess do |file|
64
+ file.source = File.join(common_templates_dir, 'dothtaccess')
65
+ file.destination = 'public/.htaccess'
66
+ end
67
+
68
+ directory :test_dir do |directory|
69
+ dir = testing_framework == :rspec ? "spec" : "test"
70
+
71
+ directory.source = File.join(source_root, dir)
72
+ directory.destination = dir
73
+ end
74
+
75
+ #
76
+ # ==== Layout specific things
77
+ #
78
+
79
+ # empty array means all files are considered to be just
80
+ # files, not templates
81
+ glob! "app"
82
+ glob! "autotest"
83
+ glob! "config"
84
+ glob! "doc", []
85
+ glob! "public"
86
+
87
+ invoke :layout do |generator|
88
+ generator.new(destination_root, options, 'application')
89
+ end
90
+ end
91
+
92
+ add :core, MerbCoreGenerator
93
+
94
+ end
95
+ end
@@ -1,90 +1,91 @@
1
- module Merb::Generators
2
- class MerbFlatGenerator < NamedGenerator
3
- #
4
- # ==== Paths
5
- #
6
-
7
- def self.source_root
8
- File.join(super, 'application', 'merb_flat')
9
- end
10
-
11
- def self.common_templates_dir
12
- File.expand_path(File.join(File.dirname(__FILE__), '..',
13
- 'templates', 'application', 'common'))
14
- end
15
-
16
- def destination_root
17
- File.join(@destination_root, base_name)
18
- end
19
-
20
- def common_templates_dir
21
- self.class.common_templates_dir
22
- end
23
-
24
- #
25
- # ==== Generator options
26
- #
27
-
28
- option :testing_framework, :default => :rspec,
29
- :desc => 'Testing framework to use (one of: rspec, test_unit).'
30
- option :orm, :default => :none,
31
- :desc => 'Object-Relation Mapper to use (one of: none, activerecord, datamapper, sequel).'
32
- option :template_engine, :default => :erb,
33
- :desc => 'Template engine to prefer for this application (one of: erb, haml).'
34
-
35
- desc <<-DESC
1
+ module Merb
2
+ module Generators
3
+ class MerbFlatGenerator < AppGenerator
4
+ #
5
+ # ==== Paths
6
+ #
7
+
8
+ def self.source_root
9
+ File.join(super, 'application', 'merb_flat')
10
+ end
11
+
12
+ def self.common_templates_dir
13
+ File.expand_path(File.join(File.dirname(__FILE__), '..',
14
+ 'templates', 'application', 'common'))
15
+ end
16
+
17
+ def destination_root
18
+ File.join(@destination_root, base_name)
19
+ end
20
+
21
+ def common_templates_dir
22
+ self.class.common_templates_dir
23
+ end
24
+
25
+ #
26
+ # ==== Generator options
27
+ #
28
+
29
+ option :testing_framework, :default => :rspec,
30
+ :desc => 'Testing framework to use (one of: rspec, test_unit).'
31
+ option :orm, :default => :none,
32
+ :desc => 'Object-Relation Mapper to use (one of: none, activerecord, datamapper, sequel).'
33
+ option :template_engine, :default => :erb,
34
+ :desc => 'Template engine to prefer for this application (one of: erb, haml).'
35
+
36
+ desc <<-DESC
36
37
  This generates a flat merb application: all code but config files and
37
38
  templates fits in one application. This is something in between Sinatra
38
39
  and "regular" Merb application.
39
40
  DESC
40
41
 
41
- first_argument :name, :required => true, :desc => "Application name"
42
+ first_argument :name, :required => true, :desc => "Application name"
42
43
 
43
- #
44
- # ==== Common directories & files
45
- #
44
+ #
45
+ # ==== Common directories & files
46
+ #
46
47
 
47
- empty_directory :gems, 'gems'
48
- file :thorfile do |file|
49
- file.source = File.join(common_templates_dir, "merb.thor")
50
- file.destination = "merb.thor"
51
- end
48
+ empty_directory :gems, 'gems'
49
+ file :thorfile do |file|
50
+ file.source = File.join(common_templates_dir, "merb.thor")
51
+ file.destination = "merb.thor"
52
+ end
52
53
 
53
- template :rakefile do |template|
54
- template.source = File.join(common_templates_dir, "Rakefile")
55
- template.destination = "Rakefile"
56
- end
54
+ template :rakefile do |template|
55
+ template.source = File.join(common_templates_dir, "Rakefile")
56
+ template.destination = "Rakefile"
57
+ end
57
58
 
58
- template :gitignore do |template|
59
- template.source = File.join(common_templates_dir, 'dotgitignore')
60
- template.destination = ".gitignore"
61
- end
59
+ file :gitignore do |file|
60
+ file.source = File.join(common_templates_dir, 'dotgitignore')
61
+ file.destination = ".gitignore"
62
+ end
62
63
 
63
- directory :test_dir do |directory|
64
- dir = testing_framework == :rspec ? "spec" : "test"
64
+ directory :test_dir do |directory|
65
+ dir = testing_framework == :rspec ? "spec" : "test"
65
66
 
66
- directory.source = File.join(source_root, dir)
67
- directory.destination = dir
68
- end
67
+ directory.source = File.join(source_root, dir)
68
+ directory.destination = dir
69
+ end
69
70
 
70
- #
71
- # ==== Layout specific things
72
- #
71
+ #
72
+ # ==== Layout specific things
73
+ #
73
74
 
74
- file :readme, "README.txt"
75
+ file :readme, "README.txt"
75
76
 
76
- template :application, "application.rb"
77
+ template :application, "application.rb"
77
78
 
78
- glob! "config"
79
- glob! "views"
79
+ glob! "config"
80
+ glob! "views"
80
81
 
81
- def class_name
82
- self.name.gsub("-", "_").camel_case
82
+ def class_name
83
+ self.name.gsub("-", "_").camel_case
84
+ end
83
85
  end
84
- end
85
-
86
- add_private :app_flat, MerbFlatGenerator
87
86
 
87
+ add :flat, MerbFlatGenerator
88
+ end
88
89
  end
89
90
 
90
91
 
@@ -0,0 +1,110 @@
1
+ module Merb
2
+ module Generators
3
+ class MerbStackGenerator < AppGenerator
4
+ #
5
+ # ==== Paths
6
+ #
7
+
8
+ def self.source_root
9
+ File.join(super, 'application', 'merb_stack')
10
+ end
11
+
12
+ def self.common_templates_dir
13
+ File.expand_path(File.join(File.dirname(__FILE__), '..',
14
+ 'templates', 'application', 'common'))
15
+ end
16
+
17
+ def destination_root
18
+ File.join(@destination_root, base_name)
19
+ end
20
+
21
+ def common_templates_dir
22
+ self.class.common_templates_dir
23
+ end
24
+
25
+ def testing_framework
26
+ :rspec
27
+ end
28
+
29
+ def orm
30
+ :datamapper
31
+ end
32
+
33
+ #
34
+ # ==== Generator options
35
+ #
36
+
37
+ option :template_engine, :default => :erb,
38
+ :desc => 'Template engine to prefer for this application (one of: erb, haml).'
39
+
40
+ desc <<-DESC
41
+ This generates a "prepackaged" (or "opinionated") Merb application that uses DataMapper,
42
+ RSpec, helpers, assets, mailer, caching, slices and merb-auth all out of the box.
43
+ DESC
44
+
45
+ first_argument :name, :required => true, :desc => "Application name"
46
+
47
+ #
48
+ # ==== Common directories & files
49
+ #
50
+
51
+ empty_directory :gems, 'gems'
52
+ file :thorfile do |file|
53
+ file.source = File.join(common_templates_dir, "merb.thor")
54
+ file.destination = "tasks/merb.thor"
55
+ end
56
+
57
+ template :rakefile do |template|
58
+ template.source = File.join(common_templates_dir, "Rakefile")
59
+ template.destination = "Rakefile"
60
+ end
61
+
62
+ file :gitignore do |file|
63
+ file.source = File.join(common_templates_dir, 'dotgitignore')
64
+ file.destination = ".gitignore"
65
+ end
66
+
67
+ file :htaccess do |file|
68
+ file.source = File.join(common_templates_dir, 'dothtaccess')
69
+ file.destination = 'public/.htaccess'
70
+ end
71
+
72
+ file :doctask do |file|
73
+ file.source = File.join(common_templates_dir, 'doc.thor')
74
+ file.destination = 'tasks/doc.thor'
75
+ end
76
+
77
+ file :jquery do |file|
78
+ file.source = File.join(common_templates_dir, 'jquery.js')
79
+ file.destination = 'public/javascripts/jquery.js'
80
+ end
81
+
82
+ directory :test_dir do |directory|
83
+ dir = testing_framework == :rspec ? "spec" : "test"
84
+
85
+ directory.source = File.join(source_root, dir)
86
+ directory.destination = dir
87
+ end
88
+
89
+ #
90
+ # ==== Layout specific things
91
+ #
92
+
93
+ # empty array means all files are considered to be just
94
+ # files, not templates
95
+ glob! "app"
96
+ glob! "autotest"
97
+ glob! "config"
98
+ glob! "doc", []
99
+ glob! "public"
100
+ glob! "lib"
101
+ glob! "merb"
102
+
103
+ invoke :layout do |generator|
104
+ generator.new(destination_root, options, 'application')
105
+ end
106
+ end
107
+
108
+ add :app, MerbStackGenerator
109
+ end
110
+ end
@@ -1,72 +1,69 @@
1
- module Merb::Generators
2
-
3
- class MerbVeryFlatGenerator < NamedGenerator
4
-
5
- def self.source_root
6
- File.join(super, 'application', 'merb_very_flat')
7
- end
8
-
9
- def self.common_templates_dir
10
- File.expand_path(File.join(File.dirname(__FILE__), '..',
11
- 'templates', 'application', 'common'))
12
- end
13
-
14
- def destination_root
15
- File.join(@destination_root, base_name)
16
- end
17
-
18
- def common_templates_dir
19
- File.expand_path(File.join(File.dirname(__FILE__), '..',
20
- 'templates', 'application', 'common'))
21
- end
22
-
23
-
24
- option :testing_framework, :default => :rspec,
25
- :desc => 'Testing framework to use (one of: rspec, test_unit).'
26
- option :orm, :default => :none,
27
- :desc => 'Object-Relation Mapper to use (one of: none, activerecord, datamapper, sequel).'
28
- option :template_engine, :default => :erb,
29
- :desc => 'Template engine to prefer for this application (one of: erb, haml).'
30
-
31
-
32
- desc <<-DESC
1
+ module Merb
2
+ module Generators
3
+ class MerbVeryFlatGenerator < AppGenerator
4
+ def self.source_root
5
+ File.join(super, 'application', 'merb_very_flat')
6
+ end
7
+
8
+ def self.common_templates_dir
9
+ File.expand_path(File.join(File.dirname(__FILE__), '..',
10
+ 'templates', 'application', 'common'))
11
+ end
12
+
13
+ def destination_root
14
+ File.join(@destination_root, base_name)
15
+ end
16
+
17
+ def common_templates_dir
18
+ File.expand_path(File.join(File.dirname(__FILE__), '..',
19
+ 'templates', 'application', 'common'))
20
+ end
21
+
22
+ option :testing_framework, :default => :rspec,
23
+ :desc => 'Testing framework to use (one of: rspec, test_unit).'
24
+ option :orm, :default => :none,
25
+ :desc => 'Object-Relation Mapper to use (one of: none, activerecord, datamapper, sequel).'
26
+ option :template_engine, :default => :erb,
27
+ :desc => 'Template engine to prefer for this application (one of: erb, haml).'
28
+
29
+ desc <<-DESC
33
30
  This generates a very flat merb application: the whole application
34
31
  fits in one file, very much like Sinatra or Camping.
35
32
  DESC
36
33
 
37
- first_argument :name, :required => true, :desc => "Application name"
38
-
39
- template :application do |template|
40
- template.source = 'application.rbt'
41
- template.destination = "#{base_name}.rb"
42
- end
43
-
44
- template :gitignore do |template|
45
- template.source = File.join(common_templates_dir, 'dotgitignore')
46
- template.destination = ".gitignore"
47
- end
48
-
49
- directory :test_dir do |directory|
50
- dir = testing_framework == :rspec ? "spec" : "test"
51
-
52
- directory.source = dir
53
- directory.destination = dir
34
+ first_argument :name, :required => true, :desc => "Application name"
35
+
36
+ template :application do |template|
37
+ template.source = 'application.rbt'
38
+ template.destination = "#{base_name}.rb"
39
+ end
40
+
41
+ file :gitignore do |file|
42
+ file.source = File.join(common_templates_dir, 'dotgitignore')
43
+ file.destination = ".gitignore"
44
+ end
45
+
46
+ directory :test_dir do |directory|
47
+ dir = testing_framework == :rspec ? "spec" : "test"
48
+ directory.source = dir
49
+ directory.destination = dir
50
+ end
51
+
52
+ template :rakefile do |template|
53
+ template.source = File.join(common_templates_dir, "Rakefile")
54
+ template.destination = "Rakefile"
55
+ end
56
+
57
+ file :thorfile do |file|
58
+ file.source = File.join(common_templates_dir, "merb.thor")
59
+ file.destination = "merb.thor"
60
+ end
61
+
62
+ def class_name
63
+ self.name.gsub("-", "_").camel_case
64
+ end
54
65
  end
55
66
 
56
- template :rakefile do |template|
57
- template.source = File.join(common_templates_dir, "Rakefile")
58
- template.destination = "Rakefile"
59
- end
60
-
61
- file :thorfile do |file|
62
- file.source = File.join(common_templates_dir, "merb.thor")
63
- file.destination = "merb.thor"
64
- end
65
-
66
- def class_name
67
- self.name.gsub("-", "_").camel_case
68
- end
67
+ add :very_flat, MerbVeryFlatGenerator
69
68
  end
70
-
71
- add_private :app_very_flat, MerbVeryFlatGenerator
72
69
  end
@@ -1,6 +1,11 @@
1
1
  module Merb::Generators
2
2
 
3
3
  class MerbPluginGenerator < NamedGenerator
4
+
5
+ def initialize(*args)
6
+ Merb.disable(:initfile)
7
+ super
8
+ end
4
9
 
5
10
  def self.source_root
6
11
  File.join(super, 'application', 'merb_plugin')
@@ -2,6 +2,7 @@ module Merb::Generators
2
2
 
3
3
  class ModelGenerator < NamespacedGenerator
4
4
 
5
+
5
6
  def self.source_root
6
7
  File.join(super, 'component', 'model')
7
8
  end
@@ -39,9 +40,11 @@ module Merb::Generators
39
40
  def attributes_for_accessor
40
41
  self.attributes.keys.map{|a| ":#{a}" }.compact.uniq.join(", ")
41
42
  end
42
-
43
+
44
+ def after_generation
45
+ STDOUT.puts "\n\nDon't forget to add model tests first."
46
+ end
43
47
  end
44
48
 
45
49
  add :model, ModelGenerator
46
-
47
50
  end
@@ -8,6 +8,9 @@ module Merb::Generators
8
8
 
9
9
  first_argument :name, :required => true, :desc => "resource name (singular)"
10
10
  second_argument :attributes, :as => :hash, :default => {}, :desc => "space separated resource model properties in form of name:type. Example: state:string"
11
+
12
+ option :testing_framework, :desc => 'Testing framework to use (one of: rspec, test_unit)'
13
+ option :orm, :desc => 'Object-Relation Mapper to use (one of: none, activerecord, datamapper, sequel)'
11
14
 
12
15
  invoke :model do |generator|
13
16
  generator.new(destination_root, options, model_name, attributes)
@@ -24,9 +27,11 @@ module Merb::Generators
24
27
  def model_name
25
28
  name
26
29
  end
27
-
30
+
31
+ def after_generation
32
+ STDOUT << message("Don't forget to set your resource route in config/router.rb for instance: resources :#{model_name.downcase}s ")
33
+ end
28
34
  end
29
35
 
30
36
  add :resource, ResourceGenerator
31
-
32
37
  end