Permalink
Browse files

the generators now use hooks, as [calas] taught me.

  • Loading branch information...
1 parent 3f564ee commit 44fe3a3467867dee275d71f9ea0b214a9eeb6ccc @apotonick committed Feb 5, 2011
@@ -1,19 +1,16 @@
-require 'generators/cells/cell_generator'
+require 'generators/cells/base'
module Apotomo
module Generators
- class WidgetGenerator < Cells::Generators::CellGenerator
- source_root File.expand_path(File.join(File.dirname(__FILE__), 'templates'))
+ class WidgetGenerator < ::Cells::Generators::Base
+ source_root File.expand_path(File.join(File.dirname(__FILE__), '../templates'))
def create_cell_file
- puts "creating #{file_name}.rb"
template 'widget.rb', File.join('app/cells', class_path, "#{file_name}.rb")
end
- def create_test
- @states = actions
- template 'widget_test.rb', File.join('test/widgets/', "#{file_name}_test.rb")
- end
+ hook_for(:template_engine)
+ hook_for(:test_framework) # TODO: implement rspec-apotomo.
end
end
end
@@ -0,0 +1,17 @@
+require 'generators/cells/base'
+
+module Erb
+ module Generators
+ class WidgetGenerator < ::Cells::Generators::Base
+ source_root File.expand_path('../../templates', __FILE__)
+
+ def create_views
+ for state in actions do
+ @state = state
+ @path = File.join('app/cells', file_name, "#{state}.html.erb")
+ template "view.erb", @path
+ end
+ end
+ end
+ end
+end
@@ -0,0 +1,20 @@
+require 'generators/cells/base'
+
+module Haml
+ module Generators
+ class WidgetGenerator < ::Cells::Generators::Base
+ source_root File.expand_path('../../templates', __FILE__)
+
+ def create_views
+ for state in actions do
+ @state = state
+ @path = File.join('app/cells', file_name, "#{state}.html.haml")
+
+ template "view.haml", @path
+ end
+ end
+ end
+ end
+end
+
+
@@ -0,0 +1,14 @@
+require 'generators/cells/base'
+
+module TestUnit
+ module Generators
+ class WidgetGenerator < ::Cells::Generators::Base
+ source_root File.expand_path('../../templates', __FILE__)
+
+ def create_test
+ @states = actions
+ template 'widget_test.rb', File.join('test/widgets/', "#{file_name}_test.rb")
+ end
+ end
+ end
+end
@@ -10,7 +10,7 @@ class WidgetGeneratorTest < Rails::Generators::TestCase
context "Mouse squeak snuggle" do
should "create the standard assets" do
- run_generator %w(MouseWidget squeak snuggle)
+ run_generator %w(MouseWidget squeak snuggle -t test_unit)
assert_file "app/cells/mouse_widget.rb", /class MouseWidget < Apotomo::Widget/
assert_file "app/cells/mouse_widget.rb", /def snuggle/
@@ -23,20 +23,8 @@ class WidgetGeneratorTest < Rails::Generators::TestCase
assert_file "test/widgets/mouse_widget_test.rb", %r(widget\(:mouse_widget, 'me'\))
end
- should "create haml assets with --haml" do
- run_generator %w(MouseWidget squeak snuggle --haml)
-
- assert_file "app/cells/mouse_widget.rb", /class MouseWidget < Apotomo::Widget/
- assert_file "app/cells/mouse_widget.rb", /def snuggle/
- assert_file "app/cells/mouse_widget.rb", /def squeak/
- assert_file "app/cells/mouse_widget/snuggle.html.haml", %r(app/cells/mouse_widget/snuggle\.html\.haml)
- assert_file "app/cells/mouse_widget/snuggle.html.haml", %r(%p)
- assert_file "app/cells/mouse_widget/squeak.html.haml", %r(app/cells/mouse_widget/squeak\.html\.haml)
- assert_file "test/widgets/mouse_widget_test.rb"
- end
-
- should "create haml assets with -t haml" do
- run_generator %w(MouseWidget snuggle squeak -t haml)
+ should "create haml assets with -e haml" do
+ run_generator %w(MouseWidget squeak snuggle -e haml -t test_unit)
assert_file "app/cells/mouse_widget.rb", /class MouseWidget < Apotomo::Widget/
assert_file "app/cells/mouse_widget.rb", /def snuggle/

0 comments on commit 44fe3a3

Please sign in to comment.