urls.php in Sassy 7
File
phamlp/sass/extensions/compass/functions/urls.php
View source
<?php
class SassExtentionsCompassFunctionsUrls {
public function stylesheet_url($path, $only_path = null) {
$path = $path->value;
if (SassExtentionsCompassConfig::config('relative_assets')) {
$http_css_path = self::compute_relative_path(SassExtentionsCompassConfig::config('css_path'));
}
elseif (SassExtentionsCompassConfig::config('http_css_path')) {
$http_css_path = SassExtentionsCompassConfig::config('http_css_path');
}
else {
$http_css_path = SassExtentionsCompassConfig::config('css_dir');
}
return new SassString(self::clean("{$http_css_path}/{$path}", $only_path));
}
public function font_url($path, $only_path = null) {
$path = $path->value;
if (self::is_absolute_path($path)) {
return new SassString("url('{$path}')");
}
if (SassExtentionsCompassConfig::config('relative_assets')) {
$http_fonts_path = self::compute_relative_path(SassExtentionsCompassConfig::config('fonts_path'));
}
else {
$http_fonts_path = SassExtentionsCompassConfig::config('http_fonts_path');
}
return new SassString(self::clean("{$http_fonts_path}/{$path}", $only_path));
}
public function image_url($path, $only_path = null) {
$path = $path->value;
if (preg_match('%^' . preg_quote(SassExtentionsCompassConfig::config('http_images_path'), '%') . '/(.*)%', $path, $matches)) {
$path = $matches[1];
}
elseif (self::is_absolute_path($path)) {
return new SassString("url('{$path}')");
}
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');
}
if (SassExtentionsCompassConfig::config('images_dir')) {
$real_path = SassExtentionsCompassConfig::config('project_path') . DIRECTORY_SEPARATOR . SassExtentionsCompassConfig::config('images_dir') . DIRECTORY_SEPARATOR . $path;
}
if ($http_images_path) {
$http_images_path .= substr($http_images_path, -1) === '/' ? '' : '/';
$path = $http_images_path . $path;
}
return new SassString(self::clean($path, $only_path));
}
private function clean($url, $only_path) {
if (!$only_path instanceof SassBoolean) {
$only_path = new SassBoolean('false');
}
$url = substr($url, 0, 2) === './' ? substr($url, 2) : $url;
return $only_path
->toBoolean() ? $url : "url('{$url}')";
}
private function is_absolute_path($path) {
return $path[0] === '/' || substr($path, 0, 4) === 'http';
}
private function compute_relative_path($path) {
return $path;
}
}
Classes
Name |
Description |
SassExtentionsCompassFunctionsUrls |
Compass extension SassScript urls functions class.
A collection of functions for use in SassSCript.
@package PHamlP
@subpackage Sass.extensions.compass.functions |