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
@@ -2,7 +2,7 @@
2
2
  if defined?(Merb::Plugins)
3
3
 
4
4
  # Merb gives you a Merb::Plugins.config hash...feel free to put your stuff in your piece of it
5
- Merb::Plugins.config[:<%= base_name %>] = {
5
+ Merb::Plugins.config[:<%= symbol_name %>] = {
6
6
  :chickens => false
7
7
  }
8
8
 
@@ -1,4 +1,4 @@
1
- namespace :<%= base_name %> do
1
+ namespace :<%= symbol_name %> do
2
2
  desc "Do something for <%= base_name %>"
3
3
  task :default do
4
4
  puts "<%= base_name %> doesn't do anything"
@@ -0,0 +1,17 @@
1
+ # run very flat apps with merb -I <app file>.
2
+
3
+ Merb::Config.use { |c|
4
+ c[:framework] = { :public => [Merb.root / "public", nil] },
5
+ c[:session_store] = 'none',
6
+ c[:exception_details] = true
7
+ }
8
+
9
+ Merb::Router.prepare do |r|
10
+ r.match('/').to(:controller => '<%= base_name %>', :action =>'index')
11
+ end
12
+
13
+ class <%= class_name %> < Merb::Controller
14
+ def index
15
+ "hi"
16
+ end
17
+ end
@@ -0,0 +1,11 @@
1
+ <% with_modules(modules) do -%>
2
+ class <%= class_name %> < Application
3
+
4
+ # ...and remember, everything returned from an action
5
+ # goes to the client...
6
+ def index
7
+ render
8
+ end
9
+
10
+ end
11
+ <% end -%>
@@ -0,0 +1 @@
1
+ You're in index of the <%= class_name %> controller.
@@ -0,0 +1,7 @@
1
+ require File.join(File.dirname(__FILE__), <%= go_up(modules.size + 1) %>, 'spec_helper.rb')
2
+
3
+ describe <%= full_class_name %>, "index action" do
4
+ before(:each) do
5
+ dispatch_to(<%= full_class_name %>, :index)
6
+ end
7
+ end
@@ -0,0 +1,17 @@
1
+ require File.join(File.dirname(__FILE__), <%= go_up(modules.size + 1) %>, "test_helper")
2
+
3
+ # Re-raise errors caught by the controller.
4
+ class <%= full_class_name %>; def rescue_action(e) raise e end; end
5
+
6
+ class <%= full_class_name %>Test < Test::Unit::TestCase
7
+
8
+ def setup
9
+ @controller = <%= full_class_name %>.build(fake_request)
10
+ @controller.dispatch('index')
11
+ end
12
+
13
+ # Replace this with your real tests.
14
+ def test_should_be_setup
15
+ assert false
16
+ end
17
+ end
@@ -0,0 +1,43 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ __DIR__ = File.join(File.dirname(__FILE__),"..")
4
+
5
+ framework = File.join(__DIR__,"framework")
6
+
7
+ if File.directory?(framework)
8
+ puts "Running from frozen framework"
9
+ core = File.join(framework,"merb-core")
10
+ if File.directory?(core)
11
+ $:.push File.join(core,"lib")
12
+ end
13
+ more = File.join(framework,"merb-more")
14
+ if File.directory?(more)
15
+ Dir.new(more).select {|d| d =~ /merb-/}.each do |d|
16
+ $:.push File.join(more,d,'lib')
17
+ end
18
+ end
19
+ plugins = File.join(framework,"merb-plugins")
20
+ if File.directory?(plugins)
21
+ Dir.new(plugins).select {|d| d =~ /merb_/}.each do |d|
22
+ $:.push File.join(plugins,d,'lib')
23
+ end
24
+ end
25
+ require "merb-core/core_ext/kernel"
26
+ require "merb-core/core_ext/rubygems"
27
+ else
28
+ gem = Dir.glob(__DIR__ + "/gems/gems/merb-core-*").last
29
+ raise "Can't run frozen without framework/ or local gem" unless gem
30
+ require gem + "/lib/merb-core/core_ext/kernel"
31
+ require gem + "/lib/merb-core/core_ext/rubygems"
32
+
33
+ Gem.clear_paths
34
+ Gem.path.unshift(__DIR__+"/gems")
35
+ end
36
+
37
+ require 'merb-core'
38
+ unless %w[-a --adapter -i --irb-console -r --script-runner].any? { |o| ARGV.index(o) }
39
+ ARGV.push *%w[-a mongrel]
40
+ end
41
+
42
+ Merb.frozen!
43
+ Merb.start
@@ -0,0 +1,7 @@
1
+ module Merb
2
+ <% with_modules(modules, :indent => 1) do -%>
3
+ module <%= class_name %>Helper
4
+
5
+ end
6
+ <% end -%>
7
+ end # Merb
@@ -0,0 +1,5 @@
1
+ require File.join(File.dirname(__FILE__), <%= go_up(modules.size + 1) %>, 'spec_helper.rb')
2
+
3
+ describe Merb::<%= full_class_name %>Helper do
4
+
5
+ end
@@ -0,0 +1 @@
1
+ # TODO: Add a view spec stub here.
@@ -0,0 +1,7 @@
1
+ <% with_modules(modules) do -%>
2
+ class <%= class_name %>
3
+ <% if attributes? -%>
4
+ attr_accessor <%= attributes_for_accessor %>
5
+ <% end -%>
6
+ end
7
+ <% end -%>
@@ -0,0 +1,7 @@
1
+ require File.join( File.dirname(__FILE__), <%= go_up(modules.size + 1) %>, "spec_helper" )
2
+
3
+ describe <%= class_name %> do
4
+
5
+ it "should have specs"
6
+
7
+ end
@@ -0,0 +1,9 @@
1
+ require File.join(File.dirname(__FILE__), <%= go_up(modules.size + 1) %>, 'test_helper' )
2
+
3
+ class <%= test_class_name %> < Test::Unit::TestCase
4
+
5
+ def test_should_be_tested
6
+ assert false
7
+ end
8
+
9
+ end
@@ -0,0 +1,9 @@
1
+ <% with_modules(modules) do -%>
2
+ class <%= class_name %>Part < Merb::PartController
3
+
4
+ def index
5
+ render
6
+ end
7
+
8
+ end
9
+ <% end -%>
@@ -0,0 +1,3 @@
1
+ <h1><%= full_class_name %>Part controller, index action</h1>
2
+
3
+ <p>Edit this file in <tt>app/parts/views/<%= file_name %>_part/index.html.erb</tt></p>
@@ -0,0 +1,44 @@
1
+ <% with_modules(modules) do -%>
2
+ class <%= class_name %> < Application
3
+
4
+ # GET /<%= symbol_name %>
5
+ def index
6
+ render
7
+ end
8
+
9
+ # GET /<%= symbol_name %>/:id
10
+ def show
11
+ render
12
+ end
13
+
14
+ # GET /<%= symbol_name %>/new
15
+ def new
16
+ render
17
+ end
18
+
19
+ # GET /<%= symbol_name %>/:id/edit
20
+ def edit
21
+ render
22
+ end
23
+
24
+ # GET /<%= symbol_name %>/:id/delete
25
+ def delete
26
+ render
27
+ end
28
+
29
+ # POST /<%= symbol_name %>
30
+ def create
31
+ render
32
+ end
33
+
34
+ # PUT /<%= symbol_name %>/:id
35
+ def update
36
+ render
37
+ end
38
+
39
+ # DELETE /<%= symbol_name %>/:id
40
+ def destroy
41
+ render
42
+ end
43
+ end
44
+ <% end -%>
@@ -0,0 +1,3 @@
1
+ <h1><%= class_name %> controller, edit action</h1>
2
+
3
+ <p>Edit this file in <tt>app/views/<%= file_name %>/edit.html.erb</tt></p>
@@ -0,0 +1,3 @@
1
+ <h1><%= class_name %> controller, index action</h1>
2
+
3
+ <p>Edit this file in <tt>app/views/<%= file_name %>/index.html.erb</tt></p>
@@ -0,0 +1,3 @@
1
+ <h1><%= class_name %> controller, new action</h1>
2
+
3
+ <p>Edit this file in <tt>app/views/<%= file_name %>/new.html.erb</tt></p>
@@ -0,0 +1,3 @@
1
+ <h1><%= class_name %> controller, show action</h1>
2
+
3
+ <p>Edit this file in <tt>app/views/<%= file_name %>/show.html.erb</tt></p>
@@ -0,0 +1,7 @@
1
+ require File.join(File.dirname(__FILE__), <%= go_up(modules.size + 1) %>, 'spec_helper.rb')
2
+
3
+ describe <%= full_class_name %>, "index action" do
4
+ before(:each) do
5
+ dispatch_to(<%= full_class_name %>, :index)
6
+ end
7
+ end
@@ -0,0 +1,17 @@
1
+ require File.join(File.dirname(__FILE__), <%= go_up(modules.size + 1) %>, "test_helper")
2
+
3
+ # Re-raise errors caught by the controller.
4
+ class <%= full_class_name %>; def rescue_action(e) raise e end; end
5
+
6
+ class <%= full_class_name %>Test < Test::Unit::TestCase
7
+
8
+ def setup
9
+ @controller = <%= full_class_name %>.build(fake_request)
10
+ @controller.dispatch('index')
11
+ end
12
+
13
+ # Replace this with your real tests.
14
+ def test_should_be_setup
15
+ assert false
16
+ end
17
+ end
data/lib/merb-gen.rb CHANGED
@@ -1,38 +1,36 @@
1
- require 'rubigen'
2
- module Merb
3
- require File.join(File.dirname(__FILE__), "merb-gen", "base")
4
-
5
- class ApplicationGenerator
6
- def self.run(path, argv, generator, command)
7
- if command == "destroy"
8
- puts "destroying app"
9
- FileUtils.rm_rf(File.expand_path(path))
10
- puts "done"
11
- exit
12
- end
13
-
14
- source = RubiGen::PathSource.new(:application,
15
- File.join(File.dirname(__FILE__), "..", "app_generators"))
16
- RubiGen::Base.reset_sources
17
- RubiGen::Base.append_sources source
18
- puts RubiGen::Scripts.const_get(command.capitalize).inspect
19
- RubiGen::Scripts.const_get(command.capitalize).new.run([File.expand_path(path), *argv], :generator => generator, :backtrace => true)
20
- end
21
- end
22
-
23
- class ComponentGenerator
24
- def self.run(name, argv, generator, command)
25
- app_root = Dir.pwd
26
-
27
- # Merb.start :environment => 'development'
28
-
29
- Gem.clear_paths
30
- Gem.path.unshift(app_root / "gems")
31
-
32
- require "rubigen/scripts/#{command}"
33
-
34
- RubiGen::Base.use_component_sources! Merb.generator_scope
35
- RubiGen::Scripts.const_get(command.capitalize).new.run(argv, :generator => generator, :destination => app_root)
36
- end
1
+ require 'rubygems'
2
+ require 'merb-core'
3
+ require 'sha1'
4
+ gem 'templater', '>= 0.1.4'
5
+ require 'templater'
6
+
7
+ path = File.join(File.dirname(__FILE__))
8
+
9
+ require path / "merb-gen" / "generator"
10
+ require path / "merb-gen" / "named_generator"
11
+ require path / "merb-gen" / "namespaced_generator"
12
+ require path / "merb-gen" / "spec_helper"
13
+ require path / "generators" / "merb"
14
+ require path / "generators" / "merb" / "merb_full"
15
+ require path / "generators" / "merb" / "merb_flat"
16
+ require path / "generators" / "merb" / "merb_very_flat"
17
+ require path / "generators" / "merb_plugin"
18
+ require path / "generators" / "controller"
19
+ require path / "generators" / "helper"
20
+ require path / "generators" / "part_controller"
21
+ require path / "generators" / "migration"
22
+ require path / "generators" / "session_migration"
23
+ require path / "generators" / "model"
24
+ require path / "generators" / "resource_controller"
25
+ require path / "generators" / "resource"
26
+ require path / "generators" / "freezer"
27
+ require path / "generators" / "layout"
28
+
29
+ Templater::Discovery.discover!("merb-gen")
30
+
31
+ # Require all generators that plugins have added to merb, after the app has loaded.
32
+ Merb::BootLoader.after_app_loads do
33
+ Merb.generators.each do |file|
34
+ require file
37
35
  end
38
36
  end
@@ -0,0 +1,54 @@
1
+ module Merb
2
+
3
+ module Generators
4
+
5
+ extend Templater::Manifold
6
+
7
+ desc <<-DESC
8
+ Generate components for your application or entirely new applications.
9
+ DESC
10
+
11
+ class Generator < Templater::Generator
12
+
13
+ def initialize(*args)
14
+ super
15
+ options[:orm] ||= Merb.orm_generator_scope
16
+ options[:testing_framework] ||= Merb.test_framework_generator_scope
17
+
18
+ options[:orm] = :none if options[:orm] == :merb_default # FIXME: temporary until this is fixed in merb-core
19
+ end
20
+
21
+ # Inside a template, wraps a block of code properly in modules, keeping the indentation correct
22
+ #
23
+ # @param modules<Array[#to_s]> an array of modules to use for nesting
24
+ # @option indent<Integer> number of integers to indent the modules by
25
+ def with_modules(modules, options={}, &block)
26
+ indent = options[:indent] || 0
27
+ text = capture(&block)
28
+ modules.each_with_index do |mod, i|
29
+ concat((" " * (indent + i)) + "module #{mod}\n", block.binding)
30
+ end
31
+ text = text.to_a.map{ |line| (" " * modules.size) + line }.join
32
+ concat(text, block.binding)
33
+ modules.reverse.each_with_index do |mod, i|
34
+ concat((" " * (indent + modules.size - i - 1)) + "end # #{mod}\n", block.binding)
35
+ end
36
+ end
37
+
38
+ # Returns a string of num times '..', useful for example in tests for namespaced generators
39
+ # to find the spec_helper higher up in the directory structure.
40
+ #
41
+ # @param num<Integer> number of directories up
42
+ # @return <String> concatenated string
43
+ def go_up(num)
44
+ (["'..'"] * num).join(', ')
45
+ end
46
+
47
+ def self.source_root
48
+ File.join(File.dirname(__FILE__), '..', 'generators', 'templates')
49
+ end
50
+ end
51
+
52
+ end
53
+
54
+ end
@@ -0,0 +1,33 @@
1
+ module Merb
2
+ module Generators
3
+
4
+ class NamedGenerator < Generator
5
+
6
+ # NOTE: Currently this is not inherited, it will have to be declared in each generator
7
+ # that inherits from this.
8
+ first_argument :name, :required => true
9
+
10
+ def class_name
11
+ name.gsub('-', '_').camel_case
12
+ end
13
+
14
+ alias_method :module_name, :class_name
15
+
16
+ def test_class_name
17
+ class_name + "Test"
18
+ end
19
+
20
+ def file_name
21
+ name.snake_case
22
+ end
23
+
24
+ alias_method :base_name, :file_name
25
+
26
+ def symbol_name
27
+ file_name.gsub('-', '_')
28
+ end
29
+
30
+ end
31
+
32
+ end
33
+ end