Sha256: dcde09da5886837de47d3ed195fa9e00780b28efd2ca58e11af564c16e1ff717

Contents?: true

Size: 1.47 KB

Versions: 21

Compression:

Stored size: 1.47 KB

Contents

require "fileutils"

module Neat
  class Generator
    def initialize(arguments)
      @subcommand = arguments.first
    end

    def run
      if @subcommand == "install"
       install
      elsif @subcommand == "update"
        update
      elsif @subcommand == "remove"
        remove
      end
    end

    def update
      if neat_files_already_exist?
        remove_neat_directory
        install_files
        puts "Neat files updated."
      else
        puts "No existing neat installation. Doing nothing."
      end
    end

    def install
      if neat_files_already_exist?
        puts "Neat files already installed, doing nothing."
      else
        install_files
        puts "Neat files installed to neat/"
      end
    end

    def remove
      if neat_files_already_exist?
        remove_neat_directory
        puts "Neat was successfully removed."
      else
        puts "No existing neat installation. Doing nothing."
      end
    end

    private

    def neat_files_already_exist?
      File.directory?("neat")
    end

    def install_files
      FileUtils.mkdir_p("neat")
      FileUtils.cp_r(all_stylesheets, "neat/")
    end

    def remove_neat_directory
      FileUtils.rm_rf("neat")
    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

21 entries across 21 versions & 1 rubygems

Version Path
neat-1.7.4 lib/neat/generator.rb
neat-1.7.3 lib/neat/generator.rb
neat-1.7.2 lib/neat/generator.rb
neat-1.7.1 lib/neat/generator.rb
neat-1.7.0 lib/neat/generator.rb
neat-1.7.0.rc lib/neat/generator.rb
neat-1.7.0.pre lib/neat/generator.rb
neat-1.5.1 lib/neat/generator.rb
neat-1.6.0 lib/neat/generator.rb
neat-1.6.0.pre2 lib/neat/generator.rb
neat-1.6.0.pre lib/neat/generator.rb
neat-1.5.0 lib/neat/generator.rb
neat-1.5.0.pre lib/neat/generator.rb
neat-1.4.0 lib/neat/generator.rb
neat-1.3.0 lib/neat/generator.rb
neat-1.2.1 lib/neat/generator.rb
neat-1.2.0 lib/neat/generator.rb
neat-1.1.0 lib/neat/generator.rb
neat-1.0.2 lib/neat/generator.rb
neat-1.0.1 lib/neat/generator.rb