Sha256: a27850392fb01bda9861195a02a2d431349fce38946047ceef111920f962f4d2

Contents?: true

Size: 1.88 KB

Versions: 4

Compression:

Stored size: 1.88 KB

Contents

require 'yamlcss/version'
require 'fileutils'
require 'thor'

# YAML gemerator with install methods.
module YamlCss
  # Use Thor for own generator.
  class Generator < Thor
    map %w(-v --version) => :version

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

    desc 'update', 'Update Bourbon'
    method_options path: :string
    def update
      if yaml_files_already_exist?
        remove_yaml_directory
        install_files
        puts 'YAML files updated.'
      else
        puts 'No existing YAML installation. Doing nothing.'
      end
    end

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

    private

    def yaml_files_already_exist?
      install_path.exist?
    end

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

    def install_files
      make_install_directory
      copy_in_scss_files
    end

    def remove_yaml_directory
      FileUtils.rm_rf('yaml')
    end

    def make_install_directory
      FileUtils.mkdir_p(install_path)
    end

    def copy_in_scss_files
      FileUtils.cp_r(Generator.all_stylesheets, install_path)
    end

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

    def self.stylesheets_directory
      File.join(Generator.top_level_directory, 'yaml')
    end

    def self.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
yamlcss-1.0.3 ./lib/yamlcss/generator.rb
yamlcss-1.0.2 ./lib/yamlcss/generator.rb
yamlcss-1.0.1 ./lib/yamlcss/generator.rb
yamlcss-1.0.0 ./lib/yamlcss/generator.rb