preprocessors.php 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  1. <?php
  2. /**
  3. * CSS preprocessor registration.
  4. *
  5. * To add a new preprocessor (or replace an existing one), hook into the
  6. * jetpack_custom_css_preprocessors filter and add an entry to the array
  7. * that is passed in.
  8. *
  9. * Format is:
  10. * $preprocessors[ UNIQUE_KEY ] => array( 'name' => 'Processor name', 'callback' => [processing function] );
  11. *
  12. * The callback function accepts a single string argument (non-CSS markup) and returns a string (CSS).
  13. *
  14. * @param array $preprocessors The list of preprocessors added thus far.
  15. * @return array
  16. */
  17. function jetpack_register_css_preprocessors( $preprocessors ) {
  18. $preprocessors['less'] = array(
  19. 'name' => 'LESS',
  20. 'callback' => 'jetpack_less_css_preprocess'
  21. );
  22. $preprocessors['sass'] = array(
  23. 'name' => 'Sass (SCSS Syntax)',
  24. 'callback' => 'jetpack_sass_css_preprocess'
  25. );
  26. return $preprocessors;
  27. }
  28. add_filter( 'jetpack_custom_css_preprocessors', 'jetpack_register_css_preprocessors' );
  29. function jetpack_less_css_preprocess( $less ) {
  30. require_once( dirname( __FILE__ ) . '/preprocessors/lessc.inc.php' );
  31. $compiler = new lessc();
  32. try {
  33. return $compiler->compile( $less );
  34. } catch ( Exception $e ) {
  35. return $less;
  36. }
  37. }
  38. function jetpack_sass_css_preprocess( $sass ) {
  39. require_once( dirname( __FILE__ ) . '/preprocessors/scss.inc.php' );
  40. $compiler = new scssc();
  41. $compiler->setFormatter( 'scss_formatter' );
  42. try {
  43. return $compiler->compile( $sass );
  44. } catch ( Exception $e ) {
  45. return $sass;
  46. }
  47. }