lib/susanoo/generators/ng_module.rb in susanoo-0.7.4 vs lib/susanoo/generators/ng_module.rb in susanoo-0.8.0
- old
+ new
@@ -1,19 +1,53 @@
module Susanoo
module Generators
class NgModule < Thor::Group
include Thor::Actions
- desc "Create an AngularJS module."
+ desc 'Create an AngularJS module.'
- argument :name, :type => :string, :desc => "Name of AngularJS"
+ argument :name, type: :string, desc: 'Name of AngularJS'
+ class_option :deps, type: :string, default: '', desc: 'Dependencies of Angularjs module, comma separated'
- def self.is_global_generator?
+ def self.source_root
+ File.join(File.dirname(__FILE__),
+ '../templates/generators/ng_module')
+ end
+
+ def self.global_generator?
false
end
- def install_templates
- puts "Adasdasd> #{name}"
+ def setup_directories
+ empty_directory "src/views/#{directory_name}#{module_name}"
+
+ mpath = 'src/assets/javascripts/modules/'
+ empty_directory "#{mpath}#{directory_name}" unless directory_name.nil?
+ end
+
+ def install_js_module
+ template 'module.js.erb', "src/assets/javascripts/modules/#{directory_name}#{module_name}.js"
+ end
+
+ def install_view
+ template('index.html.erb',
+ "src/views/#{directory_name}#{module_name}/index.html")
+ end
+
+ private
+
+ def directory_name
+ dir_name = name.split('/')[0..-2].join('/')
+ return dir_name + '/' unless dir_name.empty?
+ nil
+ end
+
+ def module_name
+ name.split('/')[-1].underscore
+ end
+
+ def dependencies
+ options[:deps].split(',')
end
end
end
end