Module: SassC::Util

Defined in:
lib/sassc/embedded.rb

Constant Summary collapse

URI_PARSER =
URI::Parser.new({ RESERVED: ';/?:@&=+$,' })

Class Method Summary collapse

Class Method Details

.file_url_to_path(url) ⇒ Object



399
400
401
402
403
404
405
# File 'lib/sassc/embedded.rb', line 399

def file_url_to_path(url)
  return if url.nil?

  path = URI_PARSER.unescape(URI.parse(url).path)
  path = path[1..] if Gem.win_platform? && path[0].chr == '/' && path[1].chr =~ /[a-z]/i && path[2].chr == ':'
  path
end

.path_to_file_url(path) ⇒ Object



407
408
409
410
411
412
413
# File 'lib/sassc/embedded.rb', line 407

def path_to_file_url(path)
  return if path.nil?

  path = File.absolute_path(path)
  path = "/#{path}" unless path.start_with? '/'
  URI::File.build([nil, URI_PARSER.escape(path)]).to_s
end