-
Notifications
You must be signed in to change notification settings - Fork 128
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Option to overwrite the hard coded bower_components directory.
- Loading branch information
Jim Posen
committed
Dec 28, 2015
1 parent
c7fe07b
commit f1d6a31
Showing
6 changed files
with
26 additions
and
10 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -69,7 +69,7 @@ def perform_command(remove_components = true, &block) | |
|
||
# Load and merge root .bowerrc | ||
dot_bowerrc = JSON.parse(File.read(File.join(root_path, '.bowerrc'))) rescue {} | ||
dot_bowerrc["directory"] = "bower_components" | ||
dot_bowerrc["directory"] = components_directory | ||
|
||
if json.except('lib', 'vendor').empty? | ||
folders = json.keys | ||
|
@@ -91,7 +91,7 @@ def perform_command(remove_components = true, &block) | |
Dir.chdir(dir) do | ||
|
||
# Remove old components | ||
FileUtils.rm_rf("bower_components/*") if remove_components | ||
FileUtils.rm_rf("#{components_directory}/*") if remove_components | ||
|
||
# Create bower.json | ||
File.open("bower.json", "w") do |f| | ||
|
@@ -115,17 +115,17 @@ def perform_command(remove_components = true, &block) | |
end | ||
end | ||
|
||
def resolve_asset_paths | ||
def resolve_asset_paths(root_directory = components_directory) | ||
# Resolve relative paths in CSS | ||
Dir['bower_components/**/*.css'].each do |filename| | ||
Dir["#{components_directory}/**/*.css"].each do |filename| | ||
This comment has been minimized.
Sorry, something went wrong.
This comment has been minimized.
Sorry, something went wrong.
jimpo
Contributor
|
||
contents = File.read(filename) if FileTest.file?(filename) | ||
# http://www.w3.org/TR/CSS2/syndata.html#uri | ||
url_regex = /url\((?!\#)\s*['"]?(?![a-z]+:)([^'"\)]*)['"]?\s*\)/ | ||
|
||
# Resolve paths in CSS file if it contains a url | ||
if contents =~ url_regex | ||
directory_path = Pathname.new(File.dirname(filename)) | ||
.relative_path_from(Pathname.new('bower_components')) | ||
.relative_path_from(Pathname.new(root_directory)) | ||
|
||
# Replace relative paths in URLs with Rails asset_path helper | ||
new_contents = contents.gsub(url_regex) do |match| | ||
|
@@ -146,7 +146,7 @@ def resolve_asset_paths | |
def remove_extra_files | ||
puts "\nAttempting to remove all but main files as specified by bower\n" | ||
|
||
Dir['bower_components/*'].each do |component_dir| | ||
Dir["#{components_directory}/*"].each do |component_dir| | ||
component_name = component_dir.split('/').last | ||
next if clean_should_skip_component? component_name | ||
|
||
|
@@ -204,5 +204,9 @@ def clean_should_skip_component?(name) | |
BowerRails.exclude_from_clean.respond_to?(:include?) && | ||
BowerRails.exclude_from_clean.include?(name) | ||
end | ||
|
||
def components_directory | ||
BowerRails.bower_components_directory | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@jimpo I think it should be
root_directory
instead ofcomponents_directory
here, or am I missing something?