You are here

function sassy_parse in Sassy 7.3

Same name and namespace in other branches
  1. 7 sassy.module \sassy_parse()
  2. 7.2 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.

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

File

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

Code

function sassy_parse($file, $syntax, $debug = FALSE) {
  if (module_load_include('php', 'sassy', 'phpsass/SassParser')) {
    try {
      $options = array(
        'style' => 'nested',
        'cache' => FALSE,
        'syntax' => $syntax,
        'debug' => $debug,
        'load_path_functions' => array(
          'sassy_load_callback',
        ),
        'functions' => sassy_get_functions(),
      );

      // Execute the compiler.
      $parser = new SassParser($options);
      return $parser
        ->toCss($file);
    } catch (Exception $e) {
      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), $file),
          '!watchdog' => l('log messages', 'admin/reports/dblog'),
        )), 'error');
      }
    }
  }
}