Skip to content
This repository
Fetching contributors…

Octocat-spinner-32-eaf2f5

Cannot retrieve contributors at this time

file 82 lines (66 sloc) 1.737 kb
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81
require "fileutils"

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

    def run
      if @subcommand == "generate"
        generate
      elsif @subcommand == "update"
        update
      end
    end

    def update
      if bourbon_files_already_exist?
        remove_bourbon_directory
        generate_files
        puts "Bourbon files updated."
      else
        puts "No existing bourbon installation. Doing nothing."
      end
    end

    def generate
      if bourbon_files_already_exist?
        puts "Bourbon files already generated, doing nothing."
      else
        generate_files
        puts "Bourbon files generated to bourbon/"
      end
    end

    private

    def bourbon_files_already_exist?
      Dir.exist?("bourbon")
    end

    def generate_files
      make_lib_directory
      copy_in_sass_extensions
      copy_in_scss_files
    end

    def remove_bourbon_directory
      FileUtils.rm_rf("bourbon")
    end

    def make_lib_directory
      FileUtils.mkdir_p("bourbon/lib")
    end

    def copy_in_sass_extensions
      FileUtils.cp(File.join(lib_directory, "sass_extensions.rb"), "bourbon/lib/")
      FileUtils.cp_r(File.join(lib_directory, "sass_extensions"), "bourbon/lib/")
    end

    def copy_in_scss_files
      FileUtils.cp_r(all_stylesheets, "bourbon/")
    end

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

    def stylesheets_directory
      File.join(top_level_directory, "app", "assets", "stylesheets")
    end

    def lib_directory
      File.join(top_level_directory, "lib", "bourbon")
    end

    def top_level_directory
      File.dirname(File.dirname(File.dirname(__FILE__)))
    end
  end
end
Something went wrong with that request. Please try again.