Sha256: e066408a98ac2d654cc47a6174c1c2393d813908bc939b1609c0e1865cb21f5f

Contents?: true

Size: 1.77 KB

Versions: 3

Compression:

Stored size: 1.77 KB

Contents

require 'modular/version'
require "fileutils"
require 'thor'

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

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

    desc 'update', 'Update Modular'
    method_options :path => :string
    def update
      if modular_files_already_exist?
        remove_modular_directory
        install_files
        puts "Modular files updated."
      else
        puts "No existing modular installation. Doing nothing."
      end
    end

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

    private

    def modular_files_already_exist?
      install_path.exist?
    end

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

    def install_files
      make_install_directory
      copy_in_scss_files
    end

    def remove_modular_directory
      FileUtils.rm_rf("modular")
    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

3 entries across 3 versions & 1 rubygems

Version Path
modular-grid-0.0.15 lib/modular/generator.rb
modular-grid-0.0.14 lib/modular/generator.rb
modular-grid-0.0.13 lib/modular/generator.rb