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
@@ -1,9 +0,0 @@
1
- Merb Very Flat
2
- ==============
3
-
4
- An example of a single file Merb application.
5
-
6
- Start with
7
-
8
- merb -I <%= app_file_name %>.rb
9
-
data/lib/merb-gen/base.rb DELETED
@@ -1,66 +0,0 @@
1
- require File.join(File.dirname(__FILE__), "helpers")
2
-
3
- class Merb::GeneratorBase < RubiGen::Base
4
- include Merb::GeneratorHelpers
5
- attr_reader :name, :base, :choices, :assigns, :m
6
-
7
- DEFAULT_SHEBANG = File.join(Config::CONFIG['bindir'],
8
- Config::CONFIG['ruby_install_name']) unless defined?(DEFAULT_SHEBANG)
9
-
10
- default_options :shebang => DEFAULT_SHEBANG
11
-
12
- def initialize(args, runtime_options = {})
13
- super
14
- usage if args.empty?
15
- self.class.use_component_sources! Merb.generator_scope
16
- @destination_root = Dir.pwd
17
- @choices ||= []
18
- end
19
-
20
- def manifest
21
- record do |m|
22
- @m = m
23
-
24
- options["spec"] = true unless options["test"]
25
-
26
- # Set directories that should be optional based on command-line args
27
- @choices = %w(test spec)
28
-
29
- # Set the assigns that should be used for path-interpolation and building templates
30
- @assigns = {:base_name => File.basename(@name), :test_type => options["spec"] ? "rspec" : "test_unit"}
31
-
32
- FileUtils.mkdir_p @name
33
- create_dirs
34
- copy_dirs
35
- copy_files
36
-
37
- display_framework_selections
38
- end
39
- end
40
-
41
- protected
42
- def banner
43
- <<-EOS.split("\n").map{|x| x.strip}.join("\n")
44
- Creates a Merb plugin stub.
45
-
46
- USAGE: #{spec.name} --generate-plugin path"
47
- EOS
48
- end
49
-
50
- def add_options!(opts)
51
- opts.on("-S", "--[no-]spec", "Generate with RSpec") {|s| @options["spec"] = true}
52
- opts.on("-T", "--[no-]test", "Generate with Test::Unit") {|t| @options["test"] = true}
53
- end
54
-
55
- def display_framework_selections
56
- puts
57
- puts "Your app will use the #{@assigns[:test_type]} test framework."
58
- if Gem.cache.search("merb_#{@assigns[:test_type]}").size == 0
59
- puts "You need to install the merb_#{@assigns[:test_type]} gem." unless @assigns[:test_type] == 'rspec'
60
- end
61
- puts
62
- end
63
-
64
- def create_dirs
65
- end
66
- end
@@ -1,108 +0,0 @@
1
- MAIN_BINDING = binding unless defined?(MAIN_BINDING)
2
-
3
- module Merb::GeneratorHelpers
4
-
5
- # Remove "template/" from a file name
6
- #
7
- # ==== Parameters
8
- # +path+<String>:: the path to relative-ize
9
- # +dir+<String>:: a prefix directory to add into the relative-ized path
10
- #
11
- # ==== Returns
12
- # String:: a relative-ized path
13
- def relative(path, dir = nil)
14
- path.gsub(/^#{base}\/templates(\/#{dir ? dir + "/" : ""})?/, "")
15
- end
16
-
17
- def interpolate_path(path)
18
- path.gsub(/%([^\}]*)%/) {|x| assigns[$1.to_sym]}
19
- end
20
-
21
- # Establishes the directories of the template layout
22
- def copy_dirs
23
- select_template_directories.map { |x| relative(x) }.each do |path|
24
- m.directory interpolate_path(path)
25
- end
26
- end
27
-
28
- # Copies all files within each directory of the template layout
29
- def copy_files
30
- select_template_directories(true).each do |file|
31
- # Remove "template/" from the glob filename
32
- dir = relative(file)
33
-
34
- # Get all the files under the directory that are not directories or in
35
- # the list of excluded templates above.
36
- files = Dir["#{file.empty? ? "." : file}/*"].reject { |f| File.directory?(f) }
37
-
38
- next if files.empty?
39
-
40
- # We want to templatize any files that contain <% %> characters
41
- #--
42
- # This is old code, should we need it:
43
- # templates, to_copy = files.partition {|file| !(file =~ /\.erb$/) && File.read(file) =~ /<%.*%>/}
44
- templates, to_copy = files.partition { |file| File.read(file) =~ /<%.*%>/ }
45
-
46
- # Make the paths relative to the directory we're inspecting
47
- [to_copy, templates].each do |paths|
48
- paths.map! { |f| relative(f, dir) }
49
- end
50
-
51
- # Copy the files over
52
- to_copy.each do |filename|
53
- m.file(
54
- file_name(dir, filename),
55
- file_name(interpolate_path(dir), filename)
56
- )
57
- end
58
-
59
- # Copy the templates over
60
- templates.each do |filename|
61
- m.template(
62
- file_name(dir, filename),
63
- file_name(interpolate_path(dir), interpolate_path(filename))
64
- )
65
- end
66
- end
67
- end
68
-
69
- private
70
-
71
- # Selects all *directories* in the 'templates' folder. This accounts for
72
- # +choices+ and +options+.
73
- #
74
- # ==== Arguments
75
- # +with_root+<true,false>:: whether or not to include the base/templates
76
- # directory
77
- #
78
- # ==== Returns
79
- # Array:: all directories found in the 'templates' folder.
80
- def select_template_directories(with_root=false)
81
- selected = Dir["#{base}/templates/**/*"].compact.select do |f|
82
- File.directory?(f) &&
83
- (!choices.include?(relative(f)) || options[relative(f)])
84
- end
85
- selected += ["#{base}/templates"] if with_root
86
- return selected
87
- end
88
-
89
- # This was extracted from +copy_files+. It appears to do the same thing as
90
- # File.join, but it doesn't account for the OS.
91
- #
92
- # ==== Arguments
93
- # +dir+<String>:: the directory to place the file in
94
- # +name+<String>:: the name of said file
95
- #
96
- # ==== Returns
97
- # String:: a string representing the path for some file
98
- #
99
- # ==== Examples
100
- # > file_name("folder", "some_file.txt")
101
- # => "folder/some_file.txt"
102
- # > file_name("", "some_file.txt")
103
- # => "some_file.txt"
104
- def file_name(dir, name)
105
- "#{dir}#{"/" unless dir.empty?}#{name}"
106
- end
107
-
108
- end
File without changes
@@ -1,40 +0,0 @@
1
- class ModelGenerator < Merb::GeneratorBase
2
- attr_reader :model_attributes, :model_class_name, :model_file_name
3
-
4
- def initialize(args, runtime_args = {})
5
- @base = File.dirname(__FILE__)
6
- super
7
- @model_file_name = args.shift.snake_case
8
- @model_class_name = @model_file_name.to_const_string
9
- @model_attributes = Hash[*(args.map{|a| a.split(":") }.flatten)]
10
- end
11
-
12
- def manifest
13
- record do |m|
14
-
15
- @m = m
16
-
17
- @assigns = {
18
- :model_file_name => model_file_name,
19
- :model_attributes => model_attributes,
20
- :model_class_name => model_class_name
21
- }
22
-
23
- copy_dirs
24
- copy_files
25
-
26
- m.dependency "merb_model_test", [model_file_name], @assigns
27
-
28
- end
29
- end
30
-
31
- protected
32
- def banner
33
- <<-EOS.split("\n").map{|x| x.strip}.join("\n")
34
- Creates a basic Merb model stub.
35
-
36
- USAGE: #{spec.name} my_model property1:type property1:type
37
- EOS
38
- end
39
-
40
- end
@@ -1,5 +0,0 @@
1
- class <%= model_class_name %>
2
- <% unless model_attributes.empty? -%>
3
- attr_accessor <%= model_attributes.map{|a| ":#{a.first}" }.compact.uniq.join(", ") %>
4
- <% end -%>
5
- end
File without changes
@@ -1,74 +0,0 @@
1
- class ResourceControllerGenerator < Merb::GeneratorBase
2
-
3
- attr_reader :controller_class_name,
4
- :controller_file_name,
5
- :controller_base_path,
6
- :controller_modules,
7
- :model_class_name,
8
- :full_controller_const,
9
- :singular_model,
10
- :plural_model
11
-
12
- def initialize(args, runtime_args = {})
13
- @base = File.dirname(__FILE__)
14
-
15
- super
16
- name = args.shift
17
- nfp = name.snake_case.gsub("::", "/")
18
- nfp = nfp.split("/")
19
- @model_class_name = nfp.pop.singularize.to_const_string
20
- @model_class_name = runtime_args[:model_class_name] if runtime_args[:model_class_name]
21
- @singular_model = @model_class_name.snake_case
22
- @plural_model = @singular_model.pluralize
23
-
24
- nfp << @plural_model
25
-
26
- @controller_file_name = nfp.join("/")
27
-
28
- # Need to setup the directories
29
- unless @controller_file_name == File.basename(@controller_file_name)
30
- @controller_base_path = controller_file_name.split("/")[0..-2].join("/")
31
- end
32
-
33
- @controller_modules = @controller_file_name.to_const_string.split("::")[0..-2]
34
- @controller_class_name = @controller_file_name.to_const_string.split("::").last
35
-
36
- @full_controller_const = ((@controller_modules.dup || []) << @controller_class_name).join("::")
37
- end
38
-
39
- def manifest
40
- record do |m|
41
- @m = m
42
-
43
- # Create the controller directory
44
- m.directory File.join("app/controllers", controller_base_path) if controller_base_path
45
-
46
- # Create the helpers directory
47
- m.directory File.join("app/helpers", controller_base_path) if controller_base_path
48
-
49
- @assigns = {
50
- :controller_modules => controller_modules,
51
- :controller_class_name => controller_class_name,
52
- :controller_file_name => controller_file_name,
53
- :controller_base_path => controller_base_path,
54
- :full_controller_const => full_controller_const,
55
- :model_class_name => model_class_name,
56
- :singular_model => singular_model,
57
- :plural_model => plural_model
58
- }
59
- copy_dirs
60
- copy_files
61
-
62
- m.dependency "merb_resource_controller_test", [@controller_class_name], @assigns
63
- end
64
- end
65
-
66
- protected
67
- def banner
68
- <<-EOS.split("\n").map{|x| x.strip}.join("\n")
69
- Creates a basic Merb resource controller.
70
-
71
- USAGE: #{spec.name} my_resource
72
- EOS
73
- end
74
- end
@@ -1,46 +0,0 @@
1
- <% counter = 0 -%>
2
- <% controller_modules.each_with_index do |mod, i| -%>
3
- <%= " " * i %>module <%= mod %>
4
- <% counter = i -%>
5
- <% end -%>
6
- <% counter = counter == 0 ? 0 : (counter + 1) -%>
7
- <%= " " * counter %>class <%= controller_class_name %> < Application
8
-
9
- <%= " " * counter %> def index
10
- <%= " " * counter %> render
11
- <%= " " * counter %> end
12
-
13
- <%= " " * counter %> def show
14
- <%= " " * counter %> render
15
- <%= " " * counter %> end
16
-
17
- <%= " " * counter %> def new
18
- <%= " " * counter %> render
19
- <%= " " * counter %> end
20
-
21
- <%= " " * counter %> def edit
22
- <%= " " * counter %> render
23
- <%= " " * counter %> end
24
-
25
- <%= " " * counter %> def delete
26
- <%= " " * counter %> render
27
- <%= " " * counter %> end
28
-
29
- <%= " " * counter %> def create
30
- <%= " " * counter %> render
31
- <%= " " * counter %> end
32
-
33
- <%= " " * counter %> def update
34
- <%= " " * counter %> render
35
- <%= " " * counter %> end
36
-
37
- <%= " " * counter %> def destroy
38
- <%= " " * counter %> render
39
- <%= " " * counter %> end
40
-
41
- <%= " " * counter %>end
42
- <% counter = counter == 0 ? 0 : (counter - 1) -%>
43
- <% controller_modules.reverse.each_with_index do |mod, i| -%>
44
- <%= " " * counter %>end # <%= mod %>
45
- <% counter = counter - 1 -%>
46
- <% end -%>
@@ -1,16 +0,0 @@
1
- <% counter = 1 -%>
2
- module Merb
3
- <% controller_modules.each_with_index do |mod, i| -%>
4
- <%= " " * i %>module <%= mod %>
5
- <% counter = i -%>
6
- <% end -%>
7
- <% counter = counter == 0 ? 0 : (counter + 1) -%>
8
- <%= " " * counter %>module <%= controller_class_name %>Helper
9
-
10
- <%= " " * counter %>end
11
- <% counter = counter == 0 ? 0 : (counter - 1) -%>
12
- <% controller_modules.reverse.each_with_index do |mod, i| -%>
13
- <%= " " * counter %>end # <%= mod %>
14
- <% counter = counter - 1 -%>
15
- <% end -%>
16
- end
@@ -1,3 +0,0 @@
1
- <h1><%= full_controller_const %> controller, delete action</h1>
2
-
3
- <p>Edit this file in <tt>app/views/<%= controller_file_name %>/delete.html.erb</tt></p>
@@ -1,3 +0,0 @@
1
- <h1><%= full_controller_const %> controller, edit action</h1>
2
-
3
- <p>Edit this file in <tt>app/views/<%= controller_file_name %>/edit.html.erb</tt></p>
@@ -1,3 +0,0 @@
1
- <h1><%= full_controller_const %> controller, index action</h1>
2
-
3
- <p>Edit this file in <tt>app/views/<%= controller_file_name %>/index.html.erb</tt></p>
@@ -1,3 +0,0 @@
1
- <h1><%= full_controller_const %> controller, new action</h1>
2
-
3
- <p>Edit this file in <tt>app/views/<%= controller_file_name %>/new.html.erb</tt></p>
@@ -1,3 +0,0 @@
1
- <h1><%= full_controller_const %> controller, show action</h1>
2
-
3
- <p>Edit this file in <tt>app/views/<%= controller_file_name %>/show.html.erb</tt></p>
File without changes
@@ -1,59 +0,0 @@
1
- class ControllerGenerator < Merb::GeneratorBase
2
-
3
- attr_reader :controller_class_name,
4
- :controller_file_name,
5
- :controller_base_path,
6
- :controller_modules,
7
- :full_controller_const
8
-
9
- def initialize(args, runtime_args = {})
10
- @base = File.dirname(__FILE__)
11
- super
12
- name = args.shift
13
- @controller_file_name = name.snake_case.gsub("::", "/")
14
-
15
- # Need to setup the directories
16
- unless @controller_file_name == File.basename(@controller_file_name)
17
- @controller_base_path = controller_file_name.split("/")[0..-2].join("/")
18
- end
19
-
20
- @controller_modules = @controller_file_name.to_const_string.split("::")[0..-2]
21
- @controller_class_name = @controller_file_name.to_const_string.split("::").last
22
-
23
- @full_controller_const = ((@controller_modules.dup || []) << @controller_class_name).join("::")
24
- end
25
-
26
- def manifest
27
- record do |m|
28
- @m = m
29
-
30
- # Create the controller directory
31
- m.directory File.join("app/controllers", controller_base_path) if controller_base_path
32
-
33
- # Create the helpers directory
34
- m.directory File.join("app/helpers", controller_base_path) if controller_base_path
35
-
36
- @assigns = {
37
- :controller_modules => controller_modules,
38
- :controller_class_name => controller_class_name,
39
- :controller_file_name => controller_file_name,
40
- :controller_base_path => controller_base_path,
41
- :full_controller_const => full_controller_const
42
- }
43
-
44
- copy_dirs
45
- copy_files
46
-
47
- m.dependency "merb_controller_test", [@controller_class_name], @assigns
48
- end
49
- end
50
-
51
- protected
52
- def banner
53
- <<-EOS.split("\n").map{|x| x.strip}.join("\n")
54
- Creates a basic Merb controller.
55
-
56
- USAGE: #{spec.name} my_controller
57
- EOS
58
- end
59
- end