Sha256: c409f16ab2603b58f84413f2d5b10d9e9ffb4a53aa0d85f261fa0cffb2c9f6d7

Contents?: true

Size: 1.66 KB

Versions: 6

Compression:

Stored size: 1.66 KB

Contents

require 'bitters/version'
require 'fileutils'
require 'thor'

module Bitters
  class Generator < Thor
    map ['-v', '--version'] => :version
    map ['scaffold'] => :install
    map ['delete'] => :remove

    desc 'install', 'Install Bitters into your project'
    def install
      if bitters_files_already_exist?
        puts "Bitters files already installed, doing nothing."
      else
        install_files
        puts "Bitters files installed to /bitters"
      end
    end

    desc 'reset', 'Reset Bitters'
    def update
      if bitters_files_already_exist?
        remove_bitters_directory
        install_files
        puts "Bitters files updated."
      else
        puts "No existing Bitters installation. Doing nothing."
      end
    end

    desc 'remove', 'Remove Bitters'
    def remove
      if bitters_files_already_exist?
        remove_bitters_directory
        puts "Bitters was successfully removed."
      else
        puts "No existing Bitters installation. Doing nothing."
      end
    end

    desc 'version', 'Show Bitters version'
    def version
      say "Bitters #{Bitters::VERSION}"
    end

    private

    def bitters_files_already_exist?
      File.directory?("bitters")
    end

    def install_files
      FileUtils.mkdir_p("bitters")
      FileUtils.cp_r(all_stylesheets, "bitters/")
    end

    def remove_bitters_directory
      FileUtils.rm_rf("bitters")
    end

    def all_stylesheets
      Dir["#{stylesheets_directory}/*"]
    end

    def stylesheets_directory
      File.join(top_level_directory, "app", "assets", "stylesheets")
    end

    def top_level_directory
      File.dirname(File.dirname(File.dirname(__FILE__)))
    end
  end
end

Version data entries

6 entries across 6 versions & 1 rubygems

Version Path
bitters-0.9.3 lib/bitters/generator.rb
bitters-0.9.2 lib/bitters/generator.rb
bitters-0.9.1 lib/bitters/generator.rb
bitters-0.9.0.beta.2 lib/bitters/generator.rb
bitters-0.9.0 lib/bitters/generator.rb
bitters-0.9.0.beta.1 lib/bitters/generator.rb