Sha256: eb03356bab4915c0d8efb0c21b14520ecc873246ddfe30f303251a3008976468

Contents?: true

Size: 1.69 KB

Versions: 8

Compression:

Stored size: 1.69 KB

Contents

#          Copyright (c) 2006 Michael Fellinger m.fellinger@gmail.com
# All files in this distribution are subject to the terms of the Ruby license.

require 'fileutils'
require 'yaml'

module Ramaze
  module Tool

    # Create is a simple class used to create new projects based on the proto
    # directory.
    #
    # It is primarly used for this command:
    #
    #   ramaze --create project
    #
    # where project is the directory you want the content put into.

    class Create
      class << self

        # a method to create a new project by copying the contents of lib/proto
        # to the position you specify (project)
        #
        # It is just a nice wrapper showing you what files/directories are put
        # in place.

        def create project
          @basedir = ::Ramaze::BASEDIR / 'proto'
          @destdir = Dir.pwd / project

          puts "creating project: #{project}"

          FileUtils.mkdir_p(project)

          puts "copy proto to new project (#@destdir)..."

          directories, files =
            Dir[@basedir / '**' / '*'].partition{|f| File.directory?(f) }

          create_dirs(*directories)
          copy_files(*files)

        end

        # create the directories recursivly

        def create_dirs(*dirs)
          dirs.each do |dir|
            dest = dir.gsub(@basedir, @destdir)

            puts "create directory: '#{dest}'"
            FileUtils.mkdir_p(dest)
          end
        end

        # copy the files over

        def copy_files(*files)
          files.each do |file|
            dest = file.gsub(@basedir, @destdir)

            puts "copy file: '#{dest}'"
            FileUtils.cp(file, dest)
          end
        end
      end
    end
  end
end

Version data entries

8 entries across 8 versions & 1 rubygems

Version Path
ramaze-0.0.7 lib/ramaze/tool/create.rb
ramaze-0.0.9 lib/ramaze/tool/create.rb
ramaze-0.0.8 lib/ramaze/tool/create.rb
ramaze-0.0.6 lib/ramaze/tool/create.rb
ramaze-0.1.3 lib/ramaze/tool/create.rb
ramaze-0.1.0 lib/ramaze/tool/create.rb
ramaze-0.1.2 lib/ramaze/tool/create.rb
ramaze-0.1.1 lib/ramaze/tool/create.rb