You are here

public function SassExtentionsCompassFunctionsUrls::image_url in Sassy 7

File

phamlp/sass/extensions/compass/functions/urls.php, line 52

Class

SassExtentionsCompassFunctionsUrls
Compass extension SassScript urls functions class. A collection of functions for use in SassSCript. @package PHamlP @subpackage Sass.extensions.compass.functions

Code

public function image_url($path, $only_path = null) {
  $path = $path->value;

  # get to the string value of the literal.
  if (preg_match('%^' . preg_quote(SassExtentionsCompassConfig::config('http_images_path'), '%') . '/(.*)%', $path, $matches)) {

    # Treat root relative urls (without a protocol) like normal if they start with

    # the images $path.
    $path = $matches[1];
  }
  elseif (self::is_absolute_path($path)) {

    # Short curcuit if they have provided an absolute url.
    return new SassString("url('{$path}')");
  }

  # Compute the $path to the image, either root relative or stylesheet relative

  # or nil if the http_images_path is not set in the configuration.
  if (SassExtentionsCompassConfig::config('relative_assets')) {
    $http_images_path = self::compute_relative_path(SassExtentionsCompassConfig::config('images_path'));
  }
  elseif (SassExtentionsCompassConfig::config('http_images_path')) {
    $http_images_path = SassExtentionsCompassConfig::config('http_images_path');
  }
  else {
    $http_images_path = SassExtentionsCompassConfig::config('images_dir');
  }

  # Compute the real $path to the image on the file stystem if the images_dir is set.
  if (SassExtentionsCompassConfig::config('images_dir')) {
    $real_path = SassExtentionsCompassConfig::config('project_path') . DIRECTORY_SEPARATOR . SassExtentionsCompassConfig::config('images_dir') . DIRECTORY_SEPARATOR . $path;
  }

  # prepend the $path to the image if there's one
  if ($http_images_path) {
    $http_images_path .= substr($http_images_path, -1) === '/' ? '' : '/';
    $path = $http_images_path . $path;
  }

  /*		# Compute the asset host unless in relative mode.
  		asset_host = if !(self::relative()) && Compass.configuration.asset_host
  			Compass.configuration.asset_host.call($path)
  		}

  		# Compute and append the cache buster if there is one.
  		if buster = compute_cache_buster($path, real_path)
  			$path += "?#{buster}"
  		}

  		# prepend the asset host if there is one.
  		$path = "#{asset_host}#{'/' unless $path[0..0] == "/"}#{$path}" if asset_host*/
  return new SassString(self::clean($path, $only_path));
}