public
Description: A Ruby web application framework
Homepage: http://www.mackframework.com
Clone URL: git://github.com/markbates/mack.git
Click here to lend your support to: mack and make a donation at www.pledgie.com !
Feature: Added ControllerGenerator [#25 state:resolved]
markbates (author)
Mon Aug 04 14:22:41 -0700 2008
commit  6a2cbd8d9788fab58f4472e308b72a70c156e283
tree    8e97a36e3f0dac7803b1f51d5ca5ba08a8f9a147
parent  018bc6272c1d1d2f5a35b067e4f882ace36dab2c
...
1
2
 
 
3
4
5
...
1
2
3
4
5
6
7
0
@@ -1,5 +1,7 @@
0
 * [#73] Tests no longer use the functional/unit directories
0
 * [#69] Added ViewHelperGenerator and ControllerHelperGenerator
0
+* [#25] Added ControllerGenerator
0
+* gem: genosaurus 1.2.2
0
 
0
 ===0.6.1.1
0
 * [#72] Fixed serial data type in DataMapper doesn't work with SQLite3
...
11
12
13
 
 
14
15
16
 
 
 
 
17
18
19
 
 
 
 
 
 
 
20
21
...
11
12
13
14
15
16
17
 
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
0
@@ -11,10 +11,22 @@ class ControllerGenerator < Genosaurus
0
     @name_plural = param(:name).plural.underscore
0
     @name_singular_camel = @name_singular.camelcase
0
     @name_plural_camel = @name_plural.camelcase
0
+    @actions = []
0
+    @actions = param(:actions).split(",") unless param(:actions).blank?
0
   end
0
   
0
-  def after_generate
0
+  def after_generate # :nodoc:
0
+    @actions.each do |action|
0
+      template(action_template(action), File.join("app", "views", @name_plural, "#{action}.html.erb"))
0
+    end
0
     ControllerHelperGenerator.run(@options)
0
   end
0
   
0
+  def action_template(action) # :nodoc:
0
+    %{
0
+<h1>#{@name_plural_camel}Controller##{action}</h1>
0
+<p>You can find me in app/views/#{@name_plural}/#{action}.html.erb</p>
0
+    }.strip
0
+  end
0
+  
0
 end
0
\ No newline at end of file
...
2
3
4
 
 
 
5
6
7
...
2
3
4
5
6
7
8
9
10
0
@@ -2,6 +2,9 @@ controller_template:
0
   type: file
0
   template_path: <%= File.join(templates_directory_path, "app", "controllers", "controller.rb.template") %>
0
   output_path: <%= File.join("app", "controllers", "#{@name_plural}_controller.rb") %>
0
+views_migrations:
0
+  type: directory
0
+  output_path: <%= File.join("app", "views", @name_plural) %>
0
 <% if app_config.mack.testing_framework == "test_case" -%>
0
 test_template:
0
   type: file
...
1
2
3
 
 
 
 
4
...
1
2
 
3
4
5
6
7
0
@@ -1,4 +1,7 @@
0
 class <%= @name_plural_camel %>Controller
0
   include Mack::Controller
0
-  
0
+  <% @actions.each do |action| %>
0
+  def <%= action %>
0
+  end
0
+  <% end %>
0
 end
...
112
113
114
115
 
116
117
118
...
112
113
114
 
115
116
117
118
0
@@ -112,7 +112,7 @@ helper_test_spec_example:
0
 app_helper_test_spec_example:
0
   type: file
0
   template_path: <%= File.join(templates_directory_path, "test", "helpers", "views", "application_helper_spec.rb.template") %>
0
-  output_path: <%= File.join(app_name, "test", "helpers", "view", "application_helper_spec.rb") %>
0
+  output_path: <%= File.join(app_name, "test", "helpers", "views", "application_helper_spec.rb") %>
0
 test_spec_models:
0
   type: directory
0
   output_path: <%= File.join(app_name, "test", "models") %>
...
57
58
59
60
 
61
62
63
...
57
58
59
 
60
61
62
63
0
@@ -57,7 +57,7 @@ namespace :gem do
0
         s.add_dependency("crypt", "1.1.4")
0
         s.add_dependency("daemons", "1.0.10")
0
         s.add_dependency("erubis", "2.6.2")
0
-        s.add_dependency("genosaurus", "1.2.1")
0
+        s.add_dependency("genosaurus", "1.2.2")
0
         s.add_dependency("rcov", "0.8.1.2.0")
0
         s.add_dependency("rspec", "1.1.4")
0
         s.add_dependency("ruby-debug", "0.10.0")
...
4
5
6
7
 
 
8
9
10
 
11
12
13
...
23
24
25
26
 
 
 
 
 
 
 
 
 
 
 
 
27
28
29
...
31
32
33
 
34
35
36
...
4
5
6
 
7
8
9
 
 
10
11
12
13
...
23
24
25
 
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
...
42
43
44
45
46
47
48
0
@@ -4,10 +4,10 @@ require Pathname(__FILE__).dirname.expand_path.parent.parent + 'spec_helper'
0
 describe ControllerGenerator do
0
   
0
   def common_cleanup
0
-    FileUtils.rm_rf(File.join(Mack.root, "app", "controllers", "controllers", "zoos_controller.rb"))
0
+    FileUtils.rm_rf(File.join(Mack.root, "app", "controllers", "zoos_controller.rb"))
0
+    FileUtils.rm_rf(File.join(Mack.root, "app", "views", "zoos"))
0
     FileUtils.rm_rf(File.join(Mack.root, "app", "helpers", "controllers", "zoos_controller_helper.rb"))
0
-    FileUtils.rm_rf(File.join(Mack.root, "test", "helpers", "controllers", "zoos_controller_helper_test.rb"))
0
-    FileUtils.rm_rf(File.join(Mack.root, "test", "helpers", "controllers", "zoos_controller_helper_spec.rb"))
0
+    FileUtils.rm_rf(File.join(Mack.root, "test"))
0
   end
0
   
0
   before(:each) do
0
@@ -23,7 +23,18 @@ describe ControllerGenerator do
0
     ControllerGenerator.new("name" => "zoo").should be_instance_of(ControllerGenerator)
0
   end
0
   
0
-  it "should also take an optional 'actions' parameter"
0
+  it "should also take an optional 'actions' parameter" do
0
+    index = File.join(Mack.root, "app", "views", "zoos", "index.html.erb")
0
+    show = File.join(Mack.root, "app", "views", "zoos", "show.html.erb")
0
+    file = File.join(Mack.root, "app", "controllers", "zoos_controller.rb")
0
+    ControllerGenerator.run("name" => "zoo", "actions" => "index,show")
0
+    File.should be_exists(file)
0
+    File.read(file).should == fixture("zoos_controller_with_actions.rb")
0
+    File.should be_exists(index)
0
+    File.read(index).should match(/<h1>ZoosController#index<\/h1>/)
0
+    File.should be_exists(show)
0
+    File.read(show).should match(/<p>You can find me in app\/views\/zoos\/show.html.erb<\/p>/)
0
+  end
0
   
0
   it "should generate a controller" do
0
     file = File.join(Mack.root, "app", "controllers", "zoos_controller.rb")
0
@@ -31,6 +42,7 @@ describe ControllerGenerator do
0
     ControllerGenerator.run("name" => "zoo")
0
     File.should be_exists(file)
0
     File.read(file).should == fixture("zoos_controller.rb")
0
+    File.should be_exists(File.join(Mack.root, "app", "views", "zoos"))
0
   end
0
   
0
   it "should generate a controller helper" do
...
5
6
7
8
9
 
10
11
12
13
14
15
 
16
17
18
...
5
6
7
 
 
8
9
10
11
12
 
 
13
14
15
16
0
@@ -5,14 +5,12 @@ describe ControllerHelperGenerator do
0
   
0
   before(:each) do
0
     FileUtils.rm_rf(File.join(Mack.root, "app", "helpers", "controllers", "zoos_controller_helper.rb"))
0
-    FileUtils.rm_rf(File.join(Mack.root, "test", "helpers", "controllers", "zoos_controller_helper_test.rb"))
0
-    FileUtils.rm_rf(File.join(Mack.root, "test", "helpers", "controllers", "zoos_controller_helper_spec.rb"))
0
+    FileUtils.rm_rf(File.join(Mack.root, "test"))
0
   end
0
   
0
   after(:each) do
0
     FileUtils.rm_rf(File.join(Mack.root, "app", "helpers", "controllers", "zoos_controller_helper.rb"))
0
-    FileUtils.rm_rf(File.join(Mack.root, "test", "helpers", "controllers", "zoos_controller_helper_test.rb"))
0
-    FileUtils.rm_rf(File.join(Mack.root, "test", "helpers", "controllers", "zoos_controller_helper_spec.rb"))
0
+    FileUtils.rm_rf(File.join(Mack.root, "test"))
0
   end
0
   
0
   it "should require a name parameter" do
...
5
6
7
8
9
 
10
11
12
13
14
15
 
16
17
18
...
5
6
7
 
 
8
9
10
11
12
 
 
13
14
15
16
0
@@ -5,14 +5,12 @@ describe ViewHelperGenerator do
0
   
0
   before(:each) do
0
     FileUtils.rm_rf(File.join(Mack.root, "app", "helpers", "views", "zoo_helper.rb"))
0
-    FileUtils.rm_rf(File.join(Mack.root, "test", "helpers", "views", "zoo_helper_test.rb"))
0
-    FileUtils.rm_rf(File.join(Mack.root, "test", "helpers", "views", "zoo_helper_spec.rb"))
0
+    FileUtils.rm_rf(File.join(Mack.root, "test"))
0
   end
0
   
0
   after(:each) do
0
     FileUtils.rm_rf(File.join(Mack.root, "app", "helpers", "views", "zoo_helper.rb"))
0
-    FileUtils.rm_rf(File.join(Mack.root, "test", "helpers", "views", "zoo_helper_test.rb"))
0
-    FileUtils.rm_rf(File.join(Mack.root, "test", "helpers", "views", "zoo_helper_spec.rb"))
0
+    FileUtils.rm_rf(File.join(Mack.root, "test"))
0
   end
0
   
0
   it "should require a name parameter" do
...
16
17
18
 
 
19
20
21
...
16
17
18
19
20
21
22
23
0
@@ -16,6 +16,8 @@ describe "rake" do
0
 
0
 Available Generators:
0
 
0
+ControllerGenerator
0
+  rake generate:controller
0
 ControllerHelperGenerator
0
   rake generate:controller_helper
0
 MackApplicationGenerator

Comments