Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

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

  • Loading branch information...
commit 44fe3a3467867dee275d71f9ea0b214a9eeb6ccc 1 parent 3f564ee
@apotonick authored
View
13 lib/generators/apotomo/widget_generator.rb
@@ -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
View
17 lib/generators/erb/widget_generator.rb
@@ -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
View
20 lib/generators/haml/widget_generator.rb
@@ -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
+
+
View
0  lib/generators/apotomo/templates/view.erb → lib/generators/templates/view.erb
File renamed without changes
View
0  lib/generators/apotomo/templates/view.haml → lib/generators/templates/view.haml
File renamed without changes
View
0  lib/generators/apotomo/templates/widget.rb → lib/generators/templates/widget.rb
File renamed without changes
View
0  ...nerators/apotomo/templates/widget_test.rb → lib/generators/templates/widget_test.rb
File renamed without changes
View
14 lib/generators/test_unit/widget_generator.rb
@@ -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
View
18 test/rails/widget_generator_test.rb
@@ -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/
Please sign in to comment.
Something went wrong with that request. Please try again.