merb-gen 0.9.3 → 0.9.4

Sign up to get free protection for your applications and to get access to all the features.
Files changed (164) hide show
  1. data/README +14 -2
  2. data/Rakefile +43 -27
  3. data/TODO +13 -0
  4. data/bin/merb-gen +5 -93
  5. data/lib/generators/controller.rb +44 -0
  6. data/lib/generators/freezer.rb +19 -0
  7. data/lib/generators/helper.rb +31 -0
  8. data/lib/generators/layout.rb +27 -0
  9. data/lib/generators/merb.rb +24 -0
  10. data/lib/generators/merb/merb_flat.rb +27 -0
  11. data/lib/generators/merb/merb_full.rb +35 -0
  12. data/lib/generators/merb/merb_very_flat.rb +29 -0
  13. data/lib/generators/merb_plugin.rb +29 -0
  14. data/lib/generators/migration.rb +54 -0
  15. data/lib/generators/model.rb +47 -0
  16. data/lib/generators/part_controller.rb +33 -0
  17. data/lib/generators/resource.rb +32 -0
  18. data/lib/generators/resource_controller.rb +78 -0
  19. data/lib/generators/session_migration.rb +34 -0
  20. data/lib/generators/templates/application/merb/Rakefile +75 -0
  21. data/{app_generators/merb/templates → lib/generators/templates/application/merb}/app/controllers/application.rb +0 -0
  22. data/{app_generators/merb/templates → lib/generators/templates/application/merb}/app/controllers/exceptions.rb +0 -0
  23. data/{app_generators/merb/templates → lib/generators/templates/application/merb}/app/helpers/global_helpers.rb +0 -0
  24. data/{app_generators/merb/templates → lib/generators/templates/application/merb}/app/views/exceptions/internal_server_error.html.erb +1 -1
  25. data/{app_generators/merb/templates → lib/generators/templates/application/merb}/app/views/exceptions/not_acceptable.html.erb +0 -0
  26. data/{app_generators/merb/templates → lib/generators/templates/application/merb}/app/views/exceptions/not_found.html.erb +0 -0
  27. data/{app_generators/merb/templates → lib/generators/templates/application/merb}/autotest/discover.rb +0 -0
  28. data/{app_generators/merb/templates → lib/generators/templates/application/merb}/autotest/merb.rb +2 -2
  29. data/lib/generators/templates/application/merb/autotest/merb_rspec.rb +166 -0
  30. data/{app_generators/merb/templates → lib/generators/templates/application/merb}/config/environments/development.rb +0 -0
  31. data/{app_generators/merb/templates → lib/generators/templates/application/merb}/config/environments/production.rb +0 -0
  32. data/{app_generators/merb/templates → lib/generators/templates/application/merb}/config/environments/rake.rb +0 -0
  33. data/{app_generators/merb/templates → lib/generators/templates/application/merb}/config/environments/test.rb +0 -0
  34. data/{app_generators/merb/templates → lib/generators/templates/application/merb}/config/init.rb +38 -27
  35. data/lib/generators/templates/application/merb/config/rack.rb +12 -0
  36. data/{app_generators/merb/templates → lib/generators/templates/application/merb}/config/router.rb +0 -0
  37. data/{app_generators/merb/templates → lib/generators/templates/application/merb}/public/images/merb.jpg +0 -0
  38. data/{app_generators/merb/templates → lib/generators/templates/application/merb}/public/merb.fcgi +0 -0
  39. data/{app_generators/merb/templates → lib/generators/templates/application/merb}/public/stylesheets/master.css +0 -0
  40. data/{app_generators/merb/templates → lib/generators/templates/application/merb}/spec/spec.opts +0 -0
  41. data/{app_generators/merb/templates → lib/generators/templates/application/merb}/spec/spec_helper.rb +3 -1
  42. data/{app_generators/merb/templates → lib/generators/templates/application/merb}/test/test_helper.rb +0 -0
  43. data/{app_generators/merb_flat/templates → lib/generators/templates/application/merb_flat}/README.txt +0 -0
  44. data/{app_generators/merb_flat/templates → lib/generators/templates/application/merb_flat}/application.rb +0 -0
  45. data/lib/generators/templates/application/merb_flat/config/framework.rb +7 -0
  46. data/{app_generators/merb_flat/templates → lib/generators/templates/application/merb_flat}/config/init.rb +0 -1
  47. data/{app_generators/merb_flat/templates → lib/generators/templates/application/merb_flat}/views/foo.html.erb +0 -0
  48. data/{app_generators/merb_plugin/templates → lib/generators/templates/application/merb_plugin}/LICENSE +0 -0
  49. data/{app_generators/merb_plugin/templates → lib/generators/templates/application/merb_plugin}/README +0 -0
  50. data/lib/generators/templates/application/merb_plugin/Rakefile +59 -0
  51. data/{app_generators/merb_plugin/templates → lib/generators/templates/application/merb_plugin}/TODO +0 -0
  52. data/{app_generators/merb_plugin/templates → lib/generators/templates/application/merb_plugin}/lib/%base_name%.rb +1 -1
  53. data/{app_generators/merb_plugin/templates → lib/generators/templates/application/merb_plugin}/lib/%base_name%/merbtasks.rb +1 -1
  54. data/{app_generators/merb_plugin/templates → lib/generators/templates/application/merb_plugin}/spec/%base_name%_spec.rb +0 -0
  55. data/{app_generators/merb_plugin/templates → lib/generators/templates/application/merb_plugin}/spec/spec_helper.rb +0 -0
  56. data/{app_generators/merb_plugin/templates → lib/generators/templates/application/merb_plugin}/test/%base_name%_test.rb +0 -0
  57. data/{app_generators/merb_plugin/templates → lib/generators/templates/application/merb_plugin}/test/test_helper.rb +0 -0
  58. data/lib/generators/templates/application/merb_very_flat/application.rbt +17 -0
  59. data/lib/generators/templates/component/controller/app/controllers/%file_name%.rb +11 -0
  60. data/lib/generators/templates/component/controller/app/views/%file_name%/index.html.erb +1 -0
  61. data/lib/generators/templates/component/controller/spec/controllers/%file_name%_spec.rb +7 -0
  62. data/lib/generators/templates/component/controller/test/controllers/%file_name%_test.rb +17 -0
  63. data/lib/generators/templates/component/freezer/script/frozen_merb +43 -0
  64. data/lib/generators/templates/component/helper/app/helpers/%file_name%_helper.rb +7 -0
  65. data/lib/generators/templates/component/helper/spec/helpers/%file_name%_helper_spec.rb +5 -0
  66. data/{app_generators/merb/templates/app/views/layout/application.html.erb → lib/generators/templates/component/layout/app/views/layout/%file_name%.html.erb} +0 -0
  67. data/lib/generators/templates/component/layout/spec/views/layout/%file_name%.html.erb_spec.rb +1 -0
  68. data/lib/generators/templates/component/model/app/models/%file_name%.rb +7 -0
  69. data/lib/generators/templates/component/model/spec/models/%file_name%_spec.rb +7 -0
  70. data/lib/generators/templates/component/model/test/models/%file_name%_test.rb +9 -0
  71. data/lib/generators/templates/component/part_controller/app/parts/%file_name%_part.rb +9 -0
  72. data/lib/generators/templates/component/part_controller/app/parts/views/%file_name%_part/index.html.erb +3 -0
  73. data/lib/generators/templates/component/resource_controller/app/controllers/%file_name%.rb +44 -0
  74. data/lib/generators/templates/component/resource_controller/app/views/%file_name%/edit.html.erb +3 -0
  75. data/lib/generators/templates/component/resource_controller/app/views/%file_name%/index.html.erb +3 -0
  76. data/lib/generators/templates/component/resource_controller/app/views/%file_name%/new.html.erb +3 -0
  77. data/lib/generators/templates/component/resource_controller/app/views/%file_name%/show.html.erb +3 -0
  78. data/lib/generators/templates/component/resource_controller/spec/controllers/%file_name%_spec.rb +7 -0
  79. data/lib/generators/templates/component/resource_controller/test/controllers/%file_name%_test.rb +17 -0
  80. data/lib/merb-gen.rb +34 -36
  81. data/lib/merb-gen/generator.rb +54 -0
  82. data/lib/merb-gen/named_generator.rb +33 -0
  83. data/lib/merb-gen/namespaced_generator.rb +47 -0
  84. data/lib/merb-gen/spec_helper.rb +65 -0
  85. data/spec/controller_spec.rb +106 -0
  86. data/spec/fixtures/results/no_modules.test +1 -0
  87. data/spec/fixtures/results/some_modules.test +5 -0
  88. data/spec/fixtures/templates/no_modules.test +3 -0
  89. data/spec/fixtures/templates/some_modules.test +3 -0
  90. data/spec/freezer_spec.rb +17 -0
  91. data/spec/generator_spec.rb +51 -0
  92. data/spec/helper_spec.rb +43 -0
  93. data/spec/layout_spec.rb +25 -0
  94. data/spec/merb_flat_spec.rb +21 -0
  95. data/spec/merb_full_spec.rb +31 -0
  96. data/spec/merb_plugin_spec.rb +21 -0
  97. data/spec/merb_spec.rb +20 -0
  98. data/spec/merb_very_flat_spec.rb +19 -0
  99. data/spec/migration_spec.rb +47 -0
  100. data/spec/model_spec.rb +66 -0
  101. data/spec/named_generator_spec.rb +11 -0
  102. data/spec/namespaced_generator_spec.rb +11 -0
  103. data/spec/part_controller_spec.rb +74 -0
  104. data/spec/resource_controller_spec.rb +102 -0
  105. data/spec/resource_spec.rb +18 -0
  106. data/spec/session_migration_spec.rb +15 -0
  107. data/spec/spec_helper.rb +271 -0
  108. metadata +246 -181
  109. data/app_generators/merb/USAGE +0 -0
  110. data/app_generators/merb/merb_generator.rb +0 -40
  111. data/app_generators/merb/templates/Rakefile +0 -34
  112. data/app_generators/merb/templates/autotest/merb_rspec.rb +0 -223
  113. data/app_generators/merb/templates/config/rack.rb +0 -1
  114. data/app_generators/merb_flat/merb_flat_generator.rb +0 -22
  115. data/app_generators/merb_flat/templates/config/framework.rb +0 -5
  116. data/app_generators/merb_plugin/merb_plugin_generator.rb +0 -22
  117. data/app_generators/merb_plugin/templates/Rakefile +0 -44
  118. data/app_generators/merb_very_flat/merb_very_flat_generator.rb +0 -37
  119. data/app_generators/merb_very_flat/templates/%app_file_name%.rb +0 -15
  120. data/app_generators/merb_very_flat/templates/README.txt +0 -9
  121. data/lib/merb-gen/base.rb +0 -66
  122. data/lib/merb-gen/helpers.rb +0 -108
  123. data/merb_default_generators/model/USAGE +0 -0
  124. data/merb_default_generators/model/model_generator.rb +0 -40
  125. data/merb_default_generators/model/templates/app/models/%model_file_name%.rb +0 -5
  126. data/merb_default_generators/resource_controller/USAGE +0 -0
  127. data/merb_default_generators/resource_controller/resource_controller_generator.rb +0 -74
  128. data/merb_default_generators/resource_controller/templates/app/controllers/%controller_file_name%.rb +0 -46
  129. data/merb_default_generators/resource_controller/templates/app/helpers/%controller_file_name%_helper.rb +0 -16
  130. data/merb_default_generators/resource_controller/templates/app/views/%controller_file_name%/delete.html.erb +0 -3
  131. data/merb_default_generators/resource_controller/templates/app/views/%controller_file_name%/edit.html.erb +0 -3
  132. data/merb_default_generators/resource_controller/templates/app/views/%controller_file_name%/index.html.erb +0 -3
  133. data/merb_default_generators/resource_controller/templates/app/views/%controller_file_name%/new.html.erb +0 -3
  134. data/merb_default_generators/resource_controller/templates/app/views/%controller_file_name%/show.html.erb +0 -3
  135. data/merb_generators/controller/USAGE +0 -0
  136. data/merb_generators/controller/controller_generator.rb +0 -59
  137. data/merb_generators/controller/templates/app/controllers/%controller_file_name%.rb +0 -18
  138. data/merb_generators/controller/templates/app/helpers/%controller_file_name%_helper.rb +0 -16
  139. data/merb_generators/controller/templates/app/views/%controller_file_name%/index.html.erb +0 -1
  140. data/merb_generators/part_controller/USAGE +0 -0
  141. data/merb_generators/part_controller/part_controller_generator.rb +0 -58
  142. data/merb_generators/part_controller/templates/app/helpers/%controller_file_name%_part_helper.rb +0 -16
  143. data/merb_generators/part_controller/templates/app/parts/%controller_file_name%_part.rb +0 -18
  144. data/merb_generators/part_controller/templates/app/parts/views/%controller_file_name%_part/index.html.erb +0 -3
  145. data/merb_generators/resource/USAGE +0 -0
  146. data/merb_generators/resource/resource_generator.rb +0 -48
  147. data/rspec_generators/merb_controller_test/merb_controller_test_generator.rb +0 -49
  148. data/rspec_generators/merb_controller_test/templates/spec/controllers/%controller_full_file_path%_spec.rb +0 -7
  149. data/rspec_generators/merb_controller_test/templates/spec/helpers/%controller_full_file_path%_helper_spec.rb +0 -5
  150. data/rspec_generators/merb_model_test/merb_model_test_generator.rb +0 -35
  151. data/rspec_generators/merb_model_test/templates/spec/models/%model_file_name%_spec.rb +0 -7
  152. data/rspec_generators/merb_resource_controller_test/merb_resource_controller_test_generator.rb +0 -49
  153. data/rspec_generators/merb_resource_controller_test/templates/spec/controllers/%controller_full_file_path%_spec.rb +0 -7
  154. data/rspec_generators/merb_resource_controller_test/templates/spec/helpers/%controller_full_file_path%_helpers.rb +0 -5
  155. data/rspec_generators/merb_resource_controller_test/templates/spec/views/%controller_full_file_path%/delete.html.erb_spec.rb +0 -1
  156. data/rspec_generators/merb_resource_controller_test/templates/spec/views/%controller_full_file_path%/edit.html.erb_spec.rb +0 -1
  157. data/rspec_generators/merb_resource_controller_test/templates/spec/views/%controller_full_file_path%/index.html.erb_spec.rb +0 -1
  158. data/rspec_generators/merb_resource_controller_test/templates/spec/views/%controller_full_file_path%/new.html.erb_spec.rb +0 -1
  159. data/rspec_generators/merb_resource_controller_test/templates/spec/views/%controller_full_file_path%/show.html.erb_spec.rb +0 -1
  160. data/test_unit_generators/merb_controller_test/merb_controller_test_generator.rb +0 -47
  161. data/test_unit_generators/merb_controller_test/templates/test/functional/%controller_full_file_path%_test.rb +0 -17
  162. data/test_unit_generators/merb_model_test/merb_model_test_generator.rb +0 -34
  163. data/test_unit_generators/merb_model_test/templates/test/unit/%model_file_name%_test.rb +0 -9
  164. data/test_unit_generators/merb_resource_controller_test/merb_resource_controller_test_generator.rb +0 -31
data/README CHANGED
@@ -17,5 +17,17 @@ To see what generators are available, run merb-gen generators.
17
17
 
18
18
  ==== Custom generators
19
19
 
20
- If you want to create your custom generators to use with Merb, and don't want to create a gem,
21
- you should put them in ~/.rubigen/merb_generators/.
20
+ There are two ways of adding generators, depending on how the generators are intended to be used. The first way is by adding adding the generator via Merb.add_generators, and specifying the location of any generators.
21
+
22
+ Merb.add_generators File.join(File.dirname(__FILES__), 'generators', 'my_generator.rb')
23
+
24
+ This method has some advantages:
25
+
26
+ - it allows you to load generators only when your plugin is required in the application
27
+ - it allows you to load generators from inside the application itself
28
+
29
+ However, it also has a disadvantage: it is impossible this way to add generators whether the plugin is loaded or not, just by virtue of the gem being installed. This is where the second way comes in: A 'Generators' file is added to the root of the project (like a Rakefile), it should look something like this:
30
+
31
+ scope "merb-gen" do
32
+ Merb.add_generators File.join(File.dirname(__FILES__), 'generators', 'my_generator.rb')
33
+ end
data/Rakefile CHANGED
@@ -1,49 +1,65 @@
1
1
  require 'rubygems'
2
2
  require 'rake/gempackagetask'
3
+ require "extlib"
4
+ require 'merb-core/tasks/merb_rake_helper'
5
+ require "spec/rake/spectask"
3
6
 
4
- GEM = "merb-gen"
5
- VERSION = "0.9.3"
6
- AUTHOR = "Yehuda Katz"
7
- EMAIL = "wycats@gmail.com"
8
- HOMEPAGE = "http://www.merbivore.com"
9
- SUMMARY = "Merb More: Merb's Application and Plugin Generators"
7
+ ##############################################################################
8
+ # Package && release
9
+ ##############################################################################
10
+ RUBY_FORGE_PROJECT = "merb"
11
+ PROJECT_URL = "http://merbivore.com"
12
+ PROJECT_SUMMARY = "Generators suite for Merb."
13
+ PROJECT_DESCRIPTION = PROJECT_SUMMARY
14
+
15
+ GEM_AUTHOR = "Jonas Nicklas"
16
+ GEM_EMAIL = "jonas.nicklas@gmail.com"
17
+
18
+ GEM_NAME = "merb-gen"
19
+ PKG_BUILD = ENV['PKG_BUILD'] ? '.' + ENV['PKG_BUILD'] : ''
20
+ GEM_VERSION = (Merb::MORE_VERSION rescue "0.9.4") + PKG_BUILD
21
+
22
+ RELEASE_NAME = "REL #{GEM_VERSION}"
23
+
24
+ require "extlib/tasks/release"
10
25
 
11
26
  spec = Gem::Specification.new do |s|
12
- s.name = GEM
13
- s.version = VERSION
27
+ s.rubyforge_project = RUBY_FORGE_PROJECT
28
+ s.name = GEM_NAME
29
+ s.version = GEM_VERSION
14
30
  s.platform = Gem::Platform::RUBY
15
31
  s.has_rdoc = true
16
32
  s.extra_rdoc_files = ["README", "LICENSE", 'TODO']
17
- s.summary = SUMMARY
18
- s.description = s.summary
19
- s.author = AUTHOR
20
- s.email = EMAIL
21
- s.homepage = HOMEPAGE
33
+ s.summary = PROJECT_SUMMARY
34
+ s.description = PROJECT_DESCRIPTION
35
+ s.author = GEM_AUTHOR
36
+ s.email = GEM_EMAIL
37
+ s.homepage = PROJECT_URL
22
38
  s.bindir = "bin"
23
39
  s.executables = %w( merb-gen )
24
-
25
- # Uncomment this to add a dependency
26
- s.add_dependency "merb-core", ">= 0.9.3"
27
- s.add_dependency "rubigen", ">= 1.2.4"
28
-
40
+
41
+ s.add_dependency "merb-core", ">= 0.9.4"
42
+ s.add_dependency "templater", ">= 0.1.4"
43
+
29
44
  s.require_path = 'lib'
30
- s.autorequire = GEM
31
- s.files = %w(LICENSE README Rakefile TODO) +
32
- Dir.glob("{lib,bin,spec,app_generators,merb_default_generators,merb_generators,rspec_generators,test_unit_generators}/**/*")
45
+ s.autorequire = GEM_NAME
46
+ s.files = %w(LICENSE README Rakefile TODO) + Dir.glob("{lib,bin,spec}/**/*")
33
47
  end
34
48
 
35
49
  Rake::GemPackageTask.new(spec) do |pkg|
36
50
  pkg.gem_spec = spec
37
51
  end
38
52
 
39
- install_home = ENV['GEM_HOME'] ? "-i #{ENV['GEM_HOME']}" : ""
53
+ desc "Install the gem"
54
+ task :install => [:package] do
55
+ sh %{#{sudo} gem install #{install_home} pkg/#{GEM_NAME}-#{GEM_VERSION} --no-update-sources}
56
+ end
40
57
 
41
58
  namespace :jruby do
42
- task :install do
43
- sh %{sudo jruby -S gem install #{install_home} pkg/#{GEM}-#{VERSION} --no-update-sources}
59
+
60
+ desc "Run :package and install the resulting .gem with jruby"
61
+ task :install => :package do
62
+ sh %{#{sudo} jruby -S gem install #{install_home} pkg/#{GEM_NAME}-#{GEM_VERSION}.gem --no-rdoc --no-ri}
44
63
  end
45
- end
46
64
 
47
- task :install => [:package] do
48
- sh %{sudo gem install #{install_home} pkg/#{GEM}-#{VERSION} --no-update-sources}
49
65
  end
data/TODO CHANGED
@@ -0,0 +1,13 @@
1
+ Merb-gen is now ported to templater, instead of rubigen. Some things are left to do, including:
2
+
3
+ * Integrate with Merb::Config[:framework], so that stuff gets placed in the correct directories
4
+ * Allow some system for plugins to add their own generators.
5
+ * Move ORM specific templates/code into respective plugin (this requires a change in templater so that absolute paths can be specified for templates)
6
+ * Move test_unit stuff into merb-test-unit
7
+ * Move part controller generator into merb-parts
8
+ * Automatically infer ORM and testing framework (this should be easy, really)
9
+ * Add migration generators
10
+ * Add generators for session migrations
11
+ * Change ActiveRecord migrations to use new datestamp format
12
+
13
+ * Fix remaining stuff in templater (see separate TODO)
data/bin/merb-gen CHANGED
@@ -1,98 +1,10 @@
1
1
  #!/usr/bin/env ruby
2
2
 
3
- at_exit { exit }
3
+ require 'rubygems'
4
+ require 'merb-gen'
4
5
 
5
- command = ARGV.shift if %w(generate destroy update).include?(ARGV[0])
6
-
7
- %w(rubygems merb-core).each do |file|
8
- require file
9
- end
10
-
11
- # start merb
12
- Merb.start :environment => 'development', :log_level => 'error'
13
-
14
- # remove dependency
15
- module Kernel
16
- undef dependency if defined?(Kernel.dependency)
6
+ Merb::BootLoader.after_app_loads do
7
+ Merb::Generators.run_cli(Dir.pwd, 'merb-gen', Merb::VERSION, ARGV)
17
8
  end
18
9
 
19
- %w(rubigen rubigen/scripts/generate rubigen/scripts/destroy
20
- rubigen/scripts/update fileutils find merb-gen).each do |file|
21
- require file
22
- end
23
-
24
- app_help = <<-EOF
25
- Application Generators:
26
- To generate an application use one of the following
27
- merb-gen app app_name (for a standard application)
28
- merb-gen app app_name --flat (for a flattened application)
29
- merb-gen app app_name --very-flat (for a single file application)
30
- merb-gen plugin plugin_name (creates a plugin gem skeleton)
31
-
32
- Other Generators:
33
- merb-gen generators
34
- with no args will display all availble generators for the current configuration.
35
- EOF
36
-
37
- # merb-gen || merb-gen help || merb-gen help app || merb-gen app
38
- if ARGV.empty? || (ARGV[0] == "help" && ARGV.length == 1) ||
39
- (ARGV[0] == "help" && ARGV[1] == "app") || (ARGV[0] == "app" && ARGV.length == 1)
40
- puts app_help
41
-
42
- # merb-gen generators
43
- elsif ARGV[0] == "generators"
44
- # List all the Available Generators
45
- RubiGen::Base.use_component_sources! Merb.generator_scope
46
- RubiGen::Scripts::Generate.new.run([])
47
-
48
- # merb-gen help foo
49
- elsif ARGV[0] && ARGV[0] == "help"
50
- begin
51
- RubiGen::Base.use_component_sources! Merb.generator_scope
52
- RubiGen::Base.lookup(ARGV[1])
53
- Merb::ComponentGenerator.run ARGV[1], ARGV[2..-1], ARGV[1], command || "generate"
54
- rescue RubiGen::GeneratorError
55
- # List all the Available Generators
56
- RubiGen::Base.use_component_sources! Merb.generator_scope
57
- RubiGen::Scripts::Generate.new.run([])
58
- rescue => e
59
- puts e.message
60
- end
61
-
62
- # merb-gen app myapp
63
- elsif ARGV[0] && ARGV[0] == "app" && ARGV[1] && ARGV[1] !~ /^-/
64
- app_type = case ARGV[2]
65
- when "--flat"
66
- "merb_flat"
67
- when "--very-flat"
68
- "merb_very_flat"
69
- else
70
- "merb"
71
- end
72
- Merb::ApplicationGenerator.run ARGV[1], ARGV[3..-1], app_type, command || "generate"
73
-
74
- # merb-gen plugin foo
75
- elsif ARGV[0] && ARGV[0] == "plugin"
76
- Merb::ApplicationGenerator.run ARGV[1], ARGV[2..-1], "merb_plugin", command || "generate"
77
-
78
- # merb-gen controller foo
79
- # merb-gen resource foo --test
80
- elsif ARGV[1] && ARGV[1] !~ /^-/
81
- Merb::ComponentGenerator.run ARGV[1], ARGV[1..-1], ARGV.first, command || "generate"
82
-
83
- # catch all merb-gen -??? and display help instead of creating application in -???
84
- elsif ARGV[0] && ARGV[0] =~ /^-/
85
- puts app_help
86
-
87
- else
88
- begin
89
- # May be a generator that takes no arguments.
90
- RubiGen::Base.use_component_sources! Merb.generator_scope
91
- RubiGen::Base.lookup(ARGV[0])
92
- Merb::ComponentGenerator.run ARGV[0], ARGV[1..-1], ARGV.first, command || "generate"
93
- rescue RubiGen::GeneratorError
94
- puts app_help
95
- rescue => e
96
- puts e.message
97
- end
98
- end
10
+ Merb.start :environment => 'development', :log_level => 'error'
@@ -0,0 +1,44 @@
1
+ module Merb::Generators
2
+
3
+ class ControllerGenerator < NamespacedGenerator
4
+
5
+ def self.source_root
6
+ File.join(super, 'component', 'controller')
7
+ end
8
+
9
+ desc <<-DESC
10
+ Generates a new controller.
11
+ DESC
12
+
13
+ option :testing_framework, :desc => 'Testing framework to use (one of: spec, test_unit)'
14
+ option :template_engine, :default => :erb, :desc => 'Template engine to use (one of: erb, haml, markaby, etc...)'
15
+
16
+ first_argument :name, :required => true, :desc => "controller name"
17
+
18
+ invoke :helper
19
+
20
+ template :controller do
21
+ source('app/controllers/%file_name%.rb')
22
+ destination("app/controllers", base_path, "#{file_name}.rb")
23
+ end
24
+
25
+ template :index_erb, :template_engine => :erb do
26
+ source('app/views/%file_name%/index.html.erb')
27
+ destination("app/views", base_path, "#{file_name}/index.html.erb")
28
+ end
29
+
30
+ template :controller_spec, :testing_framework => :rspec do
31
+ source('spec/controllers/%file_name%_spec.rb')
32
+ destination("spec/controllers", base_path, "#{file_name}_spec.rb")
33
+ end
34
+
35
+ template :controller_test_unit, :testing_framework => :test_unit do
36
+ source('test/controllers/%file_name%_test.rb')
37
+ destination("test/controllers", base_path, "#{file_name}_test.rb")
38
+ end
39
+
40
+ end
41
+
42
+ add :controller, ControllerGenerator
43
+
44
+ end
@@ -0,0 +1,19 @@
1
+ module Merb::Generators
2
+
3
+ class FreezerGenerator < Generator
4
+
5
+ def self.source_root
6
+ File.join(super, 'component', 'freezer')
7
+ end
8
+
9
+ desc <<-DESC
10
+ Generates Merb freezer scripts.
11
+ DESC
12
+
13
+ template :freezer, 'script/frozen_merb', 'script/frozen_merb'
14
+
15
+ end
16
+
17
+ add :freezer, FreezerGenerator
18
+
19
+ end
@@ -0,0 +1,31 @@
1
+ module Merb::Generators
2
+
3
+ class HelperGenerator < NamespacedGenerator
4
+
5
+ def self.source_root
6
+ File.join(super, 'component', 'helper')
7
+ end
8
+
9
+ desc <<-DESC
10
+ Generates a new helper.
11
+ DESC
12
+
13
+ option :testing_framework, :desc => 'Testing framework to use (one of: spec, test_unit)'
14
+
15
+ first_argument :name, :required => true, :desc => "helper name"
16
+
17
+ template :helper do
18
+ source('app/helpers/%file_name%_helper.rb')
19
+ destination("app/helpers", base_path, "#{file_name}_helper.rb")
20
+ end
21
+
22
+ template :helper_spec, :testing_framework => :rspec do
23
+ source('spec/helpers/%file_name%_helper_spec.rb')
24
+ destination("spec/helpers", base_path, "#{file_name}_helper_spec.rb")
25
+ end
26
+
27
+ end
28
+
29
+ add :helper, HelperGenerator
30
+
31
+ end
@@ -0,0 +1,27 @@
1
+ module Merb::Generators
2
+
3
+ class LayoutGenerator < NamedGenerator
4
+
5
+ def self.source_root
6
+ File.join(super, 'component', 'layout')
7
+ end
8
+
9
+ desc <<-DESC
10
+ Generates a layout
11
+ DESC
12
+
13
+ #option :testing_framework, :desc => 'Testing framework to use (one of: rspec, test_unit)'
14
+ option :template_engine, :default => :erb, :desc => 'Specify what template engine should be used (one of: erb, haml...)'
15
+
16
+ first_argument :name, :required => true, :desc => "layout name"
17
+
18
+ template :layout_erb, :template_engine => :erb do
19
+ source('app/views/layout/%file_name%.html.erb')
20
+ destination("app/views/layout/#{file_name}.html.erb")
21
+ end
22
+
23
+ end
24
+
25
+ add :layout, LayoutGenerator
26
+
27
+ end
@@ -0,0 +1,24 @@
1
+ module Merb::Generators
2
+
3
+ class MerbGenerator < Generator
4
+
5
+ option :testing_framework, :default => :rspec, :desc => 'Testing framework to use (one of: spec, test_unit)'
6
+ option :orm, :default => :none, :desc => 'Object-Relation Mapper to use (one of: none, activerecord, datamapper, sequel)'
7
+ option :flat, :as => :boolean, :desc => "Generate a flat application: one file + configs + templates directory."
8
+ option :very_flat, :as => :boolean, :desc => "Generate a very flat, Sinatra-like one file application."
9
+
10
+ desc <<-DESC
11
+ Generates a merb application.
12
+ DESC
13
+
14
+ first_argument :name, :required => true, :desc => "Application name"
15
+
16
+ invoke :app_full, :flat => nil, :very_flat => nil
17
+ invoke :app_flat, :flat => true
18
+ invoke :app_very_flat, :very_flat => true
19
+
20
+ end
21
+
22
+ add :app, MerbGenerator
23
+
24
+ end
@@ -0,0 +1,27 @@
1
+ module Merb::Generators
2
+
3
+ class MerbFlatGenerator < NamedGenerator
4
+
5
+ def self.source_root
6
+ File.join(super, 'application', 'merb_flat')
7
+ end
8
+
9
+ desc <<-DESC
10
+ This generates a flat merb application: all code but config files and
11
+ templates fits in one application. This is something in between Sinatra
12
+ and "regular" Merb application.
13
+ DESC
14
+
15
+ first_argument :name, :required => true, :desc => "Application name"
16
+
17
+ glob!
18
+
19
+ def destination_root
20
+ File.join(@destination_root, base_name)
21
+ end
22
+
23
+ end
24
+
25
+ add_private :app_flat, MerbFlatGenerator
26
+
27
+ end
@@ -0,0 +1,35 @@
1
+ module Merb::Generators
2
+
3
+ class MerbFullGenerator < NamedGenerator
4
+
5
+ def self.source_root
6
+ File.join(super, 'application', 'merb')
7
+ end
8
+
9
+ option :testing_framework, :default => :rspec,
10
+ :desc => 'Testing framework to use (one of: spec, test_unit).'
11
+ option :orm, :default => :none,
12
+ :desc => 'Object-Relation Mapper to use (one of: none, activerecord, datamapper, sequel).'
13
+
14
+ desc <<-DESC
15
+ This generates a Merb application with Ruby on Rails like structure.
16
+ Generator lets you configure your ORM and testing framework of choice.
17
+ DESC
18
+
19
+ glob!
20
+
21
+ first_argument :name, :required => true, :desc => "Application name"
22
+
23
+ invoke :layout do |generator|
24
+ generator.new(destination_root, options, 'application')
25
+ end
26
+
27
+ def destination_root
28
+ File.join(@destination_root, base_name)
29
+ end
30
+
31
+ end
32
+
33
+ add_private :app_full, MerbFullGenerator
34
+
35
+ end