Skip to content
This repository has been archived by the owner on Jun 10, 2018. It is now read-only.

Commit

Permalink
Extract Environment#absolute? into Sprockets.absolute? and make it wo…
Browse files Browse the repository at this point in the history
…rk right on Windows.
  • Loading branch information
sstephenson committed Feb 16, 2009
1 parent 377cdd0 commit 0761a04
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 7 deletions.
28 changes: 28 additions & 0 deletions lib/sprockets.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,33 @@
require "yaml"
require "fileutils"

module Sprockets
class << self
def running_on_windows?
RUBY_PLATFORM =~ /(win|w)32$/
end

def absolute?(location)
same_when_expanded?(location) || platform_absolute_path?(location)
end

protected
def same_when_expanded?(location)
location[0, 1] == File.expand_path(location)[0, 1]
end

def platform_absolute_path?(location)
false
end

if Sprockets.running_on_windows?
def platform_absolute_path?(location)
location[0, 1] == File::SEPARATOR && File.expand_path(location) =~ /[A-Za-z]:[\/\\]/
end
end
end
end

require "sprockets/version"
require "sprockets/error"
require "sprockets/environment"
Expand All @@ -12,3 +39,4 @@
require "sprockets/concatenation"
require "sprockets/preprocessor"
require "sprockets/secretary"

8 changes: 2 additions & 6 deletions lib/sprockets/environment.rb
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ def register_load_location(location)
end

def find(location)
if absolute?(location) && File.exists?(location)
if Sprockets.absolute?(location) && File.exists?(location)
pathname_from(location)
else
find_all(location).first
Expand All @@ -39,13 +39,9 @@ def constants(reload = false)
end

protected
def absolute?(location)
location[0, 1] == File::SEPARATOR
end

def absolute_location_from(location)
location = location.to_s
location = File.join(root.absolute_location, location) unless absolute?(location)
location = File.join(root.absolute_location, location) unless Sprockets.absolute?(location)
File.expand_path(location)
end

Expand Down
2 changes: 1 addition & 1 deletion lib/sprockets/secretary.rb
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ def expand_paths(paths, options = {})
end

def from_root(path)
if path[0, 1] == File::SEPARATOR
if Sprockets.absolute?(path)
path
else
File.join(@options[:root], path)
Expand Down

0 comments on commit 0761a04

Please sign in to comment.