Skip to content

Commit

Permalink
Add support for --path option to install
Browse files Browse the repository at this point in the history
  • Loading branch information
sikachu committed Oct 5, 2012
1 parent ac3b318 commit f0332ef
Show file tree
Hide file tree
Showing 4 changed files with 49 additions and 28 deletions.
18 changes: 14 additions & 4 deletions features/install.feature
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,26 @@
Feature: Install bourbon files

Scenario: Bourbon generates a new bourbon installation
When I install bourbon files
When I run `bundle exec bourbon install`
Then the sass directories should have been generated
And the following directories should exist:
| bourbon |
| bourbon/lib |
| bourbon |
| bourbon/lib |
And the master bourbon partial should have been generated
And the lib files should have been generated
And the output should contain "Bourbon files installed to bourbon/"

Scenario: Generating does not overwrite an existing bourbon directory
Given bourbon is already installed
When I install bourbon files
When I run `bundle exec bourbon install`
Then the output should contain "Bourbon files already installed, doing nothing."

Scenario: Install Bourbon into a custom path
When I run `bundle exec bourbon install --path=custom_path`
Then the sass directories with "custom_path" prefix should have been generated
And the following directories should exist:
| custom_path/bourbon |
| custom_path/bourbon/lib |
And the master bourbon partial should have been generated within "custom_path" directory
And the lib files should have been generated within "custom_path" directory
And the output should contain "Bourbon files installed to custom_path/bourbon/"
23 changes: 11 additions & 12 deletions features/step_definitions/bourbon_steps.rb
Original file line number Diff line number Diff line change
@@ -1,33 +1,32 @@
Given /^bourbon is already installed$/ do
set_up_bourbon_directory
install_bourbon
end

When /^I install bourbon files$/ do
set_up_bourbon_directory
install_bourbon
end

When /^I update bourbon files$/ do
update_bourbon
end

Then /^the sass directories should have been generated$/ do
sass_directories = ["bourbon/addons", "bourbon/css3", "bourbon/functions"]
Then /^the sass directories(?: with "([^"]+)" prefix)? should have been generated$/ do |prefix|
sass_directories = ["addons", "css3", "functions"]
sass_directories.map!{ |directory| bourbon_path(prefix, directory) }
check_directory_presence(sass_directories, true)
end

Then /^the master bourbon partial should have been generated$/ do
check_file_presence(["bourbon/_bourbon.scss"], true)
Then /^the master bourbon partial should have been generated(?: within "([^"]+)" directory)?$/ do |prefix|
check_file_presence([bourbon_path(prefix, '_bourbon.scss')], true)
end

Then /^the lib files should have been generated$/ do
check_file_presence(["bourbon/lib/bourbon.rb"], true)
check_directory_presence(["bourbon/lib/bourbon"], true)
check_file_presence(["bourbon/lib/bourbon/sass_extensions.rb"], true)
check_directory_presence(["bourbon/lib/bourbon/sass_extensions"], true)
Then /^the lib files should have been generated(?: within "([^"]+)" directory)?$/ do |prefix|
check_file_presence([bourbon_path(prefix, 'lib/bourbon.rb')], true)
check_directory_presence([bourbon_path(prefix, 'lib/bourbon')], true)
check_file_presence([bourbon_path(prefix, 'lib/bourbon/sass_extensions.rb')], true)
check_directory_presence([bourbon_path(prefix, 'lib/bourbon/sass_extensions')], true)
end

Then /^bourbon should not have been generated$/ do
check_directory_presence(["bourbon"], false)
check_directory_presence(['bourbon'], false)
end
13 changes: 8 additions & 5 deletions features/support/bourbon_support.rb
Original file line number Diff line number Diff line change
@@ -1,16 +1,19 @@
module BourbonSupport
def set_up_bourbon_directory
write_file("Gemfile", "gem 'bourbon', :path => '../../..'")
run_simple("bundle install")
end

def install_bourbon
run_simple("bundle exec bourbon install")
end

def update_bourbon
run_simple("bundle exec bourbon update")
end

def bourbon_path(prefix, path)
if prefix
File.join(prefix, 'bourbon', path)
else
File.join('bourbon', path)
end
end
end

World(BourbonSupport)
23 changes: 16 additions & 7 deletions lib/bourbon/generator.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,13 @@
module Bourbon
class Generator < Thor
desc 'install', 'Install Bourbon into your project'
method_options :path => :string
def install
if bourbon_files_already_exist?
puts "Bourbon files already installed, doing nothing."
else
install_files
puts "Bourbon files installed to bourbon/"
puts "Bourbon files installed to #{install_path}/"
end
end

Expand All @@ -27,7 +28,15 @@ def update
private

def bourbon_files_already_exist?
File.directory?("bourbon")
install_path.exist?
end

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

def install_files
Expand All @@ -41,17 +50,17 @@ def remove_bourbon_directory
end

def make_lib_directory
FileUtils.mkdir_p("bourbon/lib/bourbon")
FileUtils.mkdir_p(install_path.join('lib', 'bourbon'))
end

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

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

def all_stylesheets
Expand Down

0 comments on commit f0332ef

Please sign in to comment.