Sha256: 14097a4c13bccb8f1785fa2bdd28941f5c6f140c87819d9837ea49140b31920b

Contents?: true

Size: 1.77 KB

Versions: 42

Compression:

Stored size: 1.77 KB

Contents

require 'bourbon/version'
require "fileutils"
require 'thor'

module Bourbon
  class Generator < Thor
    map ['-v', '--version'] => :version

    desc 'install', 'Install Bourbon into your project'
    method_options :path => :string, :force => :boolean
    def install
      if bourbon_files_already_exist? && !options[:force]
        puts "Bourbon files already installed, doing nothing."
      else
        install_files
        puts "Bourbon files installed to #{install_path}/"
      end
    end

    desc 'update', 'Update Bourbon'
    method_options :path => :string
    def update
      if bourbon_files_already_exist?
        remove_bourbon_directory
        install_files
        puts "Bourbon files updated."
      else
        puts "No existing bourbon installation. Doing nothing."
      end
    end

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

    private

    def bourbon_files_already_exist?
      install_path.exist?
    end

    def install_path
      @install_path ||= if options[:path]
          Pathname.new(File.join(options[:path], 'bourbon'))
        else
          Pathname.new('bourbon')
        end
    end

    def install_files
      make_install_directory
      copy_in_scss_files
    end

    def remove_bourbon_directory
      FileUtils.rm_rf("bourbon")
    end

    def make_install_directory
      FileUtils.mkdir_p(install_path)
    end

    def copy_in_scss_files
      FileUtils.cp_r(all_stylesheets, install_path)
    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

42 entries across 42 versions & 2 rubygems

Version Path
bourbon-4.3.4 lib/bourbon/generator.rb
bourbon-4.3.3 lib/bourbon/generator.rb
bourbon-4.3.2 lib/bourbon/generator.rb
bourbon-4.3.1 lib/bourbon/generator.rb
bourbon-4.3.0 lib/bourbon/generator.rb
bourbon-4.2.7 lib/bourbon/generator.rb
bourbon-4.2.6 lib/bourbon/generator.rb
bourbon-4.2.5 lib/bourbon/generator.rb
bourbon-4.2.4 lib/bourbon/generator.rb
solidus_backend-1.0.0.pre3 vendor/bundle/gems/bourbon-4.2.3/lib/bourbon/generator.rb
solidus_backend-1.0.0.pre2 vendor/bundle/gems/bourbon-4.2.3/lib/bourbon/generator.rb
bourbon-4.2.3 lib/bourbon/generator.rb
bourbon-4.2.2 lib/bourbon/generator.rb
bourbon-4.2.1 lib/bourbon/generator.rb
bourbon-4.2.0 lib/bourbon/generator.rb
bourbon-4.2.0.beta lib/bourbon/generator.rb
bourbon-4.2.0.pre lib/bourbon/generator.rb
bourbon-3.2.4 lib/bourbon/generator.rb
bourbon-4.1.1 lib/bourbon/generator.rb
bourbon-4.1.0 lib/bourbon/generator.rb