Sha256: b2790a31a82243d64e1a8169b9afeabc40eae9cdc897b9f6a4a5d6e6aaed52cb

Contents?: true

Size: 1.11 KB

Versions: 2

Compression:

Stored size: 1.11 KB

Contents

require 'support/generator'
require 'support/inflector'

module Rail
  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',
      'config/application.rb.erb',
      'config.ru.erb',
      'Gemfile',
      'public/favicon.png',
      'Rakefile.erb',
    ]

    def initialize(options)
      destination = options.fetch(:destination)
      source = File.expand_path('../templates', __FILE__)

      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 ArgumentError, 'The project name is invalid.' if class_name.empty?

      super(destination: destination, source: source)
    end

    def run
      if File.directory?(destination)
        raise ArgumentError, 'The directory already exists.'
      end
      process(FILES, @locals)
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
rail-0.1.1 lib/rail/generator.rb
rail-0.1.0 lib/rail/generator.rb