Sha256: 12936f20025441d4cd1172aef23039dbab5309c8c8372be1d0df342c7b2d3615

Contents?: true

Size: 1.84 KB

Versions: 12

Compression:

Stored size: 1.84 KB

Contents

require 'ethosstyles/version'
require "fileutils"
require 'thor'

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

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

    desc 'update', 'Update Ethosstyles'
    method_options :path => :string
    def update
      if ethosstyles_files_already_exist?
        remove_ethosstyles_directory
        install_files
        puts "Ethosstyles files updated."
      else
        puts "No existing ethosstyles installation. Doing nothing."
      end
    end

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

    private

    def ethosstyles_files_already_exist?
      install_path.exist?
    end

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

    def install_files
      make_install_directory
      copy_in_scss_files
    end

    def remove_ethosstyles_directory
      FileUtils.rm_rf("ethosstyles")
    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

12 entries across 12 versions & 1 rubygems

Version Path
ethosstyles-0.1.17 lib/ethosstyles/generator.rb
ethosstyles-0.1.16 lib/ethosstyles/generator.rb
ethosstyles-0.1.15 lib/ethosstyles/generator.rb
ethosstyles-0.1.9 lib/ethosstyles/generator.rb
ethosstyles-0.1.8 lib/ethosstyles/generator.rb
ethosstyles-0.1.7 lib/ethosstyles/generator.rb
ethosstyles-0.1.6 lib/ethosstyles/generator.rb
ethosstyles-0.1.5 lib/ethosstyles/generator.rb
ethosstyles-0.1.4 lib/ethosstyles/generator.rb
ethosstyles-0.1.3 lib/ethosstyles/generator.rb
ethosstyles-0.1.2 lib/ethosstyles/generator.rb
ethosstyles-0.1.0 lib/ethosstyles/generator.rb