You are here

function _less_attach_src in Less CSS Preprocessor 7.3

Same name and namespace in other branches
  1. 8 less.module \_less_attach_src()
  2. 7.4 less.module \_less_attach_src()

Add original .less file path as 'src' attribute to <link />.

1 string reference to '_less_attach_src'
less_element_info_alter in ./less.module
Implements hook_element_info_alter().

File

./less.module, line 80
Handles compiling of .less files.

Code

function _less_attach_src($styles) {
  foreach (element_children($styles) as $key) {

    // If its a <link />, then most likely its a compiled .less file.
    if ($styles[$key]['#tag'] == 'link') {

      // Hashes are generated based on the URL without the query portion.
      $file_url_parts = drupal_parse_url($styles[$key]['#attributes']['href']);

      // If we have a match, it means it is a compiled .less file.
      if ($cache = cache_get('less:watch:' . drupal_hash_base64($file_url_parts['path']))) {

        // Some inspectors allow 'src' attribute to open from a click.
        $styles[$key]['#attributes']['src'] = url($cache->data['data']);
      }
    }
  }
  return $styles;
}