Sha256: 7fb2a9ce0795b2d6687d9f7ede39dc3a89edf393f0d39f190ffe1aaa60f1c71a

Contents?: true

Size: 1.67 KB

Versions: 1

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

1 entries across 1 versions & 1 rubygems

Version Path
gumdrop-1.0.2 lib/gumdrop/cli/external.rb