lib/rail/generator.rb in rail-0.0.7 vs lib/rail/generator.rb in rail-0.0.8

- old
+ new

@@ -1,11 +1,10 @@ -require 'generator' +require 'support/generator' +require 'support/inflector' module Rail - class Generator < ::Generator - Error = Class.new(StandardError) - + class Generator < Support::Generator FILES = [ 'app/assets/javascripts/application.js.coffee', 'app/assets/stylesheets/application.css.scss', 'app/helpers/application_helper.rb', 'app/views/layouts/application.html.haml.erb', @@ -15,33 +14,27 @@ 'public/favicon.png', 'Rakefile.erb' ] def initialize(options) - root_dir = options.fetch(:root_dir) - template_dir = File.expand_path('../templates', __FILE__) + destination = options.fetch(:destination) + source = File.expand_path('../templates', __FILE__) - project_name = (root_dir.split('/').last || '') - .gsub(/^[^a-zA-Z]*/, '') - .gsub(/[^\w]/, '') - .gsub(/^\w|_\w/, &:upcase) - .gsub(/_+/, ' ') - + directory = destination.split('/').last || '' + project_name = Support::Inflector.titelize(directory) class_name = project_name.gsub(' ', '') @locals = { class_name: class_name, project_name: project_name } - raise Error, 'The project name is invalid.' if class_name.empty? + raise ArgumentError, 'The project name is invalid.' if class_name.empty? - super(root_dir: root_dir, template_dir: template_dir) + super(destination: destination, source: source) end def run - raise Error, 'The directory already exists.' if File.directory?(root_dir) - super(FILES, @locals) - end - - def report(message) - puts "Creating '#{ message }'..." + if File.directory?(destination) + raise ArgumentError, 'The directory already exists.' + end + process(FILES, @locals) end end end