You are here

function sassy_load_stylesheet in Sassy 7

Loads a stylesheet and writes the base path to all url declarations.

Parameters

$file: A filepath or an array representing a stylesheet.

Return value

A string that represents the processed contents of the stylesheet.

1 call to sassy_load_stylesheet()
sassy_pre_render in ./sassy.module
Builds the SASS cache. Should only be invoked by drupal_render().
1 string reference to 'sassy_load_stylesheet'
sassy_pre_render in ./sassy.module
Builds the SASS cache. Should only be invoked by drupal_render().

File

./sassy.module, line 155
Handles compiling of .sass / .scss files.

Code

function sassy_load_stylesheet($file) {
  $file = is_array($file) ? $file['data'] : $file;
  $data = drupal_load_stylesheet($file);

  // Build the base URL of this CSS file. Start with the full URL.
  $base = file_create_url($file);

  // Move to the parent.
  $base = substr($base, 0, strrpos($base, '/'));

  // Simplify to a relative URL if the stylesheet URL starts with the base URL
  // of the website.
  if (substr($base, 0, strlen($GLOBALS['base_root'])) == $GLOBALS['base_root']) {
    $base = substr($base, strlen($GLOBALS['base_root']));
  }
  _drupal_build_css_path(NULL, $base . '/');

  // Anchor all paths in the CSS with its base URL, ignoring external and
  // absolute paths.
  $data = preg_replace_callback('/url\\(\\s*[\'"]?(?![a-z]+:|\\/+)([^\'")]+)[\'"]?\\s*\\)/i', '_drupal_build_css_path', $data);
  $data = preg_replace("/url\\(([^'\")]+)\\)/i", "url('\$1')", $data);
  return $data;
}