less.api.php 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175
  1. <?php
  2. /**
  3. * @file
  4. * Hooks provided by the Less module.
  5. */
  6. /**
  7. * @addtogroup hooks
  8. * @{
  9. */
  10. /**
  11. * Define LESS variables.
  12. *
  13. * Should return flat associative array, where key is variable name.
  14. *
  15. * Variables are lazy evaluated, so variables that depend on others do not have
  16. * to appear in order.
  17. *
  18. * Variables returned by this function are cached, therefore values returned
  19. * by this function should not change. If you need variables to change from page
  20. * to page, use hook_less_variables_alter().
  21. *
  22. * @return array
  23. *
  24. * @see hook_less_variables_alter()
  25. * @see hook_less_variables_SYSTEM_NAME_alter()
  26. */
  27. function hook_less_variables() {
  28. return array(
  29. '@variable_name_1' => '#ccc',
  30. '@variable_name_2' => 'darken(@variable_name_1, 30%)',
  31. );
  32. }
  33. /**
  34. * Alter LESS variables provided by other modules or themes.
  35. *
  36. * This is called before hook_less_variables_SYSTEM_NAME_alter().
  37. *
  38. * @param &string[] $less_variables
  39. * Flat associative array of variables, where key is variable name.
  40. * @param string $system_name
  41. * A string of the system_name of the module or theme that this applies to.
  42. *
  43. * @see hook_less_variables()
  44. * @see hook_less_variables_SYSTEM_NAME_alter()
  45. */
  46. function hook_less_variables_alter(array &$less_variables, $system_name) {
  47. if ($system_name === 'less_demo') {
  48. $less_variables['@variable_name_1'] = '#ddd';
  49. }
  50. }
  51. /**
  52. * Alter LESS variables provided by other modules or themes.
  53. *
  54. * This is called after hook_less_variables_alter().
  55. *
  56. * @param &string[] $less_variables
  57. * Flat associative array of variables, where key is variable name.
  58. *
  59. * @see hook_less_variables()
  60. * @see hook_less_variables_alter()
  61. */
  62. function hook_less_variables_SYSTEM_NAME_alter(array &$less_variables) {
  63. $less_variables['@variable_name_2'] = 'lighten(@variable_name_1, 20%)';
  64. }
  65. /**
  66. * Provide a list of lookup paths for @import statements in .less files.
  67. *
  68. * @return string[]
  69. */
  70. function hook_less_paths() {
  71. return array(
  72. drupal_get_path('module', 'less_demo') . '/libs',
  73. );
  74. }
  75. /**
  76. * Alter LESS include paths.
  77. *
  78. * @param &string[] $less_paths
  79. * @param string $system_name
  80. */
  81. function hook_less_paths_alter(array &$less_paths, $system_name) {
  82. if ($system_name === 'less_demo') {
  83. $less_paths[] = drupal_get_path('module', 'less_demo') . '/other_path';
  84. }
  85. }
  86. /**
  87. * Alter LESS include paths for specific module/theme.
  88. *
  89. * @param &string[] $less_paths
  90. */
  91. function hook_less_paths_SYSTEM_NAME_alter(array &$less_paths) {
  92. }
  93. /**
  94. * @deprecated
  95. *
  96. * Define LESS functions.
  97. *
  98. * @return array
  99. * An associative where keys are LESS functions and values are PHP function
  100. * names or anonymous functions. Anonymous functions require PHP >= 5.3.
  101. *
  102. * @see hook_less_functions_alter()
  103. * @see hook_less_functions_SYSTEM_NAME_alter()
  104. *
  105. * @link http://leafo.net/lessphp/docs/#custom_functions
  106. */
  107. function hook_less_functions() {
  108. return array(
  109. 'less_func_1' => 'php_func_1',
  110. 'less_func_2' => function ($arg) {
  111. list($type, $delimiter, $value) = $arg;
  112. return array($type, $delimiter, $value);
  113. },
  114. );
  115. }
  116. /**
  117. * @deprecated
  118. *
  119. * Alter LESS functions defined by modules/themes.
  120. *
  121. * @param string[] $less_functions
  122. * Flat associative array of functions, where key is LESS function name and
  123. * value is PHP function name or Anonymous function:
  124. * (http://php.net/manual/en/functions.anonymous.php)
  125. * @param string $system_name
  126. * A string of the system_name of the module or theme that this applies to.
  127. *
  128. * @see hook_less_functions()
  129. * @see hook_less_functions_SYSTEM_NAME_alter()
  130. *
  131. * @link http://leafo.net/lessphp/docs/#custom_functions
  132. */
  133. function hook_less_functions_alter(array &$less_functions, $system_name) {
  134. }
  135. /**
  136. * @deprecated
  137. *
  138. * Alter LESS functions provided by a specific module/theme.
  139. *
  140. * @param string[] $less_functions
  141. * Flat associative array of functions, where key is variable and value is
  142. * function name or Anonymous function:
  143. * (http://php.net/manual/en/functions.anonymous.php)
  144. *
  145. * @see hook_less_functions()
  146. * @see hook_less_functions_alter()
  147. *
  148. * @link http://leafo.net/lessphp/docs/#custom_functions
  149. */
  150. function hook_less_functions_SYSTEM_NAME_alter(array &$less_functions) {
  151. }
  152. /**
  153. * @} End of "addtogroup hooks".
  154. */