Sha256: c2974f6cc2f15345e7019d0bbef5d2555b3851ac731d5c84342fd9321b6456ae

Contents?: true

Size: 1.62 KB

Versions: 6

Compression:

Stored size: 1.62 KB

Contents

require 'active_support/core_ext'
module NubisRailsBoilerplate
  class Templates
    def self.expand_skeleton(skeleton, basefile)
      skeleton_path = File.absolute_path(File.expand_path("../../skeletons/#{skeleton}", basefile))
      `cp -r #{skeleton_path} #{get_app_name}`
      patch_module_name(skeleton, get_app_name)
      run_setup_tasks(get_app_name)
      puts "All done! Your app is ready to start customizing."
    end
  
    def self.patch_module_name(skeleton, app_name)
      puts "Patching #{skeleton} files for #{app_name}"
      %w(Rakefile config/application.rb config/environment.rb config/environments/development.rb
      config/environments/test.rb config/environments/production.rb config/initializers/secret_token.rb
      config/deploy.rb config/database.yml config/initializers/session_store.rb config/routes.rb config.ru).each do |filename|
        full_path = File.expand_path(filename, app_name)
        new_contents = File.read(full_path)
          .gsub(skeleton.camelize, app_name.camelize)
          .gsub(skeleton, app_name)
        File.write(full_path, new_contents)
      end
    end
    
    def self.run_setup_tasks(app_name)
      puts "Installing gems and configuring databases"
      Dir.chdir(app_name) do 
        `bundle install; rake db:create; rake db:migrate; rake db:test:prepare`
      end
    end
    
    def self.get_app_name
      if ARGV.size != 1
        puts "Call it like this: #{$0} app_name"
        exit 1
      end

      unless ARGV[0] =~ /^[a-z_]*$/
        puts "The app_name can only be lowercase letters and underscores"
        exit 1
      end

      return ARGV[0]
    end
  end
end

Version data entries

6 entries across 6 versions & 1 rubygems

Version Path
nubis_rails_boilerplate-0.0.11 lib/templates.rb
nubis_rails_boilerplate-0.0.10 lib/templates.rb
nubis_rails_boilerplate-0.0.9 lib/templates.rb
nubis_rails_boilerplate-0.0.8 lib/templates.rb
nubis_rails_boilerplate-0.0.7 lib/templates.rb
nubis_rails_boilerplate-0.0.6 lib/templates.rb