You are here

function sassy_parse in Sassy 7.2

Same name and namespace in other branches
  1. 7.3 sassy.module \sassy_parse()
  2. 7 sassy.module \sassy_parse()

Parse a SCSS string and transform it into CSS.

Parameters

$data: A SCSS string.

$file: The SASS or SCSS file that $data belongs to described by an array.

$syntax: The syntax (SASS or SCSS) of the file contents. This information is needed by the parser.

Return value

The transformed CSS as a string.

File

./sassy.module, line 33

Code

function sassy_parse($file, $local, $global) {
  $local += array(
    'style' => 'nested',
    'debug' => false,
    'watchdog' => false,
    'errors' => 'watchdog',
  );
  extract($local);
  $path = libraries_get_path('phpsass');
  if (!file_exists($path)) {
    $path = libraries_get_path('phamlp');
  }
  $library = $path . '/SassParser.php';
  if ($path && file_exists($library)) {
    try {
      require_once $library;
      $options = array(
        'style' => $style,
        'cache' => FALSE,
        'syntax' => $file['extension'],
        'debug' => FALSE,
        'debug_info' => $debug,
        'load_paths' => array(
          dirname($file['data']),
        ),
        'filename' => $file['data'],
        'load_path_functions' => array(
          'sassy_load_callback',
        ),
        'functions' => sassy_get_functions(),
        'callbacks' => array(
          'warn' => $watchdog ? 'sassy_watchdog_warn' : NULL,
          'debug' => $watchdog ? 'sassy_watchdog_debug' : NULL,
        ),
      );

      // Execute the compiler.
      $parser = new SassParser($options);
      $result = $parser
        ->toCss($file['contents'], false);
      return $result;
    } catch (Exception $e) {
      if ($errors == 'watchdog') {
        watchdog_exception('sassy', $e);
        if (user_access('administer site configuration')) {
          drupal_set_message(t('An error occured while processing !stylesheet. Please consult your !watchdog for a detailed error description.', array(
            '!stylesheet' => l(basename($file['data']), $file['data']),
            '!watchdog' => l('log messages', 'admin/reports/dblog'),
          )), 'error');
        }
      }
      else {
        if ($errors == 'output') {
          return theme_render_template(drupal_get_path('module', 'sassy') . '/sassy_error.tpl.php', array(
            'error' => $e,
          ));
        }
      }
    }
  }
}