lib/action_widget/extensions/rails/generators.rb in action_widget-0.3.0 vs lib/action_widget/extensions/rails/generators.rb in action_widget-0.3.1
- old
+ new
@@ -9,23 +9,21 @@
super.sub(/extensions:rails:/, '')
end
end
- class Create < Base
+ class Widget < Base
source_root File.expand_path('../../../../../support/templates', __FILE__)
argument :widget_name, :type => :string
class_option :rspec, :type => :boolean, :default => true, :description => "Generates rspec file"
def generate_widget_implementation_file
- empty_directory 'app/widgets'
template('widget.rb.erb', "app/widgets/#{widget_implementation_filename}")
end
def generate_widget_spec_file
if defined?(::RSpec) && options.rspec?
- empty_directory 'spec/widgets'
template('widget_spec.rb.erb', "spec/widgets/#{widget_spec_filename}")
end
end
private
@@ -37,10 +35,16 @@
def widget_implementation_filename
"#{widget_helper_name}.rb"
end
def widget_class_name
- /[Ww]idget$/.match(widget_name) ? widget_name.classify : "#{widget_name.classify}Widget"
+ name = /[Ww]idget$/.match(widget_name) ? widget_name : "#{widget_name}Widget"
+
+ name = name.titleize
+ name = name.gsub(" ", '')
+ name = name.gsub("/", '::')
+
+ name
end
def widget_helper_name
widget_class_name.underscore
end
\ No newline at end of file