Sha256: 965ff29b9d71c7ff7a5d16dd4fcf7f4e0bbfe7a00a3416b5d37ea465116d06d6

Contents?: true

Size: 1.67 KB

Versions: 5

Compression:

Stored size: 1.67 KB

Contents

require 'fileutils'
require 'thor'

module Gumdrop::CLI
  class External < Thor
    include Thor::Actions

    def self.source_root
      File.expand_path('../../../..', __FILE__)
    end

    desc 'new [NAME]', 'Create new gumdrop project'
    method_option :template, aliases:'-t', desc:'Template to start from', required:true, default:'default'
    def new(name)
      template= options[:template] || 'default'

      if File.directory? gem_template_path(template)
        say "New site from template: #{template} (gem)"
        directory(gem_template_path(template), name)

      elsif File.directory? home_template_path(template)
        say "New site from template:  #{template} (local)"
        directory(home_template_path(template), name)

      else
        say "Unknown template!!\n"
        say "Please select from one of the following:\n\n"
        self.templates
        return
      end
      # path= File.expand_path(name)
      # puts `cd #{path} && bundle install`
    end

    desc 'templates', 'List templates'
    def templates
      say  "Gem templates:"
      Dir[ gem_template_path ].each do |name|
        say " - #{File.basename name}" if File.directory?(name)
      end
      say  "Local templates:"
      Dir[ home_template_path ].each do |name|
        say " - #{File.basename name}" if File.directory?(name)
      end
    end

    desc "version", "Displays Gumdrop version"
    def version
      say "Gumdrop v#{ Gumdrop::VERSION }"
    end

  private

    def gem_template_path(template='*')
      self.class.source_root / 'templates' / template
    end

    def home_template_path(template='*')
      File.expand_path "~" / '.gumdrop' / 'templates' / template
    end

  end
end

Version data entries

5 entries across 5 versions & 1 rubygems

Version Path
gumdrop-1.1.3 lib/gumdrop/cli/external.rb
gumdrop-1.1.2 lib/gumdrop/cli/external.rb
gumdrop-1.1.1 lib/gumdrop/cli/external.rb
gumdrop-1.1.0 lib/gumdrop/cli/external.rb
gumdrop-1.0.3 lib/gumdrop/cli/external.rb