Sha256: d4a659d681d5773a466fe956864cac876d890c3a003637c1de197375794823fc

Contents?: true

Size: 1.99 KB

Versions: 4

Compression:

Stored size: 1.99 KB

Contents

require 'styler/version'
require "fileutils"
require 'thor'

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

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

    desc 'update', 'Update styler'
    method_options :path => :string
    def update
      if styler_files_already_exist?
        remove_styler_directory
        install_files
        puts "styler files updated."
      else
        puts "No existing styler installation. Doing nothing."
      end
    end

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


    desc 'remove', 'Remove styler version'
    def remove
      remove_styler_directory
    end


    private

    def styler_files_already_exist?
      install_path.exist?
    end

    def install_path
      @install_path ||= if options[:path]
          Pathname.new(File.join(options[:path], 'vendor/assets/stylesheets/styler'))
          #Pathname.new(File.join(options[:path], 'styler'))
        else
          Pathname.new('vendor/assets/stylesheets/styler')
          #Pathname.new('styler')
        end
    end

    def install_files
      make_install_directory
      copy_in_scss_files
    end

    def remove_styler_directory
      FileUtils.rm_rf("styler")
    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

4 entries across 4 versions & 1 rubygems

Version Path
styler-sass-0.1.8.alpha lib/styler/generator.rb
styler-sass-0.1.7 lib/styler/generator.rb
styler-sass-0.1.7.alpha lib/styler/generator.rb
styler-sass-0.1.5.alpha lib/styler/generator.rb