Sha256: 74a3f921264d23098381f83aa4afe908a38b37b8653f8e4f95ee9f8d3d9b82cf

Contents?: true

Size: 1.81 KB

Versions: 1

Compression:

Stored size: 1.81 KB

Contents

require 'sammy/version'
require "fileutils"
require 'thor'

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

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

    desc 'update', 'Update Sammy'
    method_options :path => :string
    def update
      if sammy_files_already_exist?
        remove_sammy_directory
        install_files
        puts "Sammy files updated."
      else
        puts "No existing sammy installation. Doing nothing."
      end
    end

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

    private

    def sammy_files_already_exist?
      install_path.exist?
    end

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

    def install_files
      make_install_directory
      copy_in_scss_files
    end

    def remove_sammy_directory
      FileUtils.rm_rf("sammy")
    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

1 entries across 1 versions & 1 rubygems

Version Path
sammy-0.5.0 lib/sammy/generator.rb