less.libraries.inc 5.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209
  1. <?php
  2. /**
  3. * @file
  4. * Contains Libraries API integration.
  5. */
  6. /**
  7. * Implements hook_libraries_info().
  8. */
  9. function less_libraries_info() {
  10. $libraries = array();
  11. /**
  12. * Legacy leafo/lessphp library.
  13. */
  14. $libraries['lessphp'] = array(
  15. 'name' => 'lessphp (Not recommended)',
  16. 'vendor url' => 'http://leafo.net/lessphp/',
  17. 'download url' => 'http://leafo.net/lessphp/',
  18. 'version arguments' => array(
  19. 'file' => 'lessc.inc.php',
  20. 'pattern' => '/VERSION\s*=\s*["\']v?([\d\.]+)/',
  21. 'lines' => 50,
  22. ),
  23. 'files' => array(
  24. 'php' => array(
  25. 'lessc.inc.php',
  26. ),
  27. ),
  28. );
  29. _less_lessphp_locate($libraries['lessphp']);
  30. /**
  31. * Newer oyejorge/less.php library. Closer to canonical spec from lesscss.org.
  32. */
  33. $libraries['less.php'] = array(
  34. 'name' => 'less.php',
  35. 'vendor url' => 'http://lessphp.gpeasy.com/',
  36. 'download url' => 'http://lessphp.gpeasy.com/#integration-with-other-projects',
  37. 'version arguments' => array(
  38. 'file' => 'Version.php',
  39. 'pattern' => '/version\s*=\s*["\']([\d\.]+)/',
  40. 'lines' => 20,
  41. ),
  42. 'files' => array(
  43. 'php' => array(
  44. 'Less.php',
  45. ),
  46. ),
  47. 'versions' => array(
  48. '1.7.0' => array(),
  49. ),
  50. );
  51. _less_less_php_locate($libraries['less.php']);
  52. /**
  53. * Canonical version of LESS language.
  54. */
  55. $libraries['less.js'] = array(
  56. 'name' => 'less.js',
  57. 'vendor url' => 'http://lesscss.org/',
  58. 'download url' => 'http://lesscss.org/usage/#using-less-environments',
  59. 'library path' => drupal_get_path('module', 'less') . '/classes',
  60. 'version callback' => array('Lessjs', 'version'),
  61. /**
  62. * Integer indexed 'version arguments' array causes 'version callback' to be
  63. * run through call_user_func_array().
  64. *
  65. * @see call_user_func_array()
  66. */
  67. 'version arguments' => array(
  68. 0 => 'not used',
  69. ),
  70. 'files' => array(
  71. 'php' => array(
  72. 'class.lessjs.inc',
  73. ),
  74. ),
  75. 'versions' => array(
  76. '1.5.0' => array(),
  77. ),
  78. );
  79. /**
  80. * Autoprefixer
  81. */
  82. $libraries['lessautoprefixer'] = array(
  83. 'name' => 'Autoprefixer',
  84. 'vendor url' => 'https://github.com/ai/autoprefixer',
  85. 'download url' => 'https://github.com/ai/autoprefixer/releases',
  86. 'library path' => drupal_get_path('module', 'less') . '/classes',
  87. 'version callback' => array('LessAutoprefixer', 'version'),
  88. /**
  89. * Integer indexed 'version arguments' array causes 'version callback' to be
  90. * run through call_user_func_array().
  91. *
  92. * @see call_user_func_array()
  93. */
  94. 'version arguments' => array(
  95. 0 => 'not used',
  96. ),
  97. 'files' => array(
  98. 'php' => array(
  99. 'class.lessautoprefixer.inc',
  100. ),
  101. ),
  102. 'versions' => array(
  103. '1.1' => array(),
  104. ),
  105. );
  106. return $libraries;
  107. }
  108. /**
  109. * Locates oyejorge/less.php in the many possible places it could be.
  110. *
  111. * @param array $library
  112. * Libraries definition array.
  113. */
  114. function _less_less_php_locate(&$library) {
  115. $locations = array();
  116. // Primary libraries location
  117. $locations[] = libraries_get_path('less.php');
  118. // lessphp drop-in replacement location
  119. $locations[] = libraries_get_path('lessphp');
  120. // Composer location
  121. $locations[] = drupal_get_path('module', 'less') . '/vendor/oyejorge/less.php';
  122. $version_files = array(
  123. 'lib/Less/Version.php' => 'lessc.inc.php', // Source code
  124. 'Version.php' => 'Less.php', // Compiled
  125. );
  126. _less_libraries_determine_location($library, $locations, $version_files);
  127. }
  128. /**
  129. * Locates leafo/lessphp in the many possible places it could be.
  130. *
  131. * @param array $library
  132. * Libraries definition array.
  133. */
  134. function _less_lessphp_locate(&$library) {
  135. $locations = array();
  136. // Primary libraries location
  137. $locations[] = libraries_get_path('lessphp');
  138. // Legacy bundled location
  139. $locations[] = drupal_get_path('module', 'less') . '/lessphp';
  140. // Composer location
  141. $locations[] = drupal_get_path('module', 'less') . '/vendor/leafo/lessphp';
  142. /*
  143. * oyejorge/less.php does not have the actual version number in lessc.inc.php,
  144. * so we don't have to worry about mistaken identity.
  145. */
  146. $version_files = array(
  147. 'lessc.inc.php' => 'lessc.inc.php',
  148. );
  149. _less_libraries_determine_location($library, $locations, $version_files);
  150. }
  151. /**
  152. * Helper function that checks locations for LESS libraries.
  153. *
  154. * @param array &$library
  155. * Library in question. Paths to found libraries will be added here.
  156. * @param array $locations
  157. * Array of paths of potential library installs relative to DRUPAL_ROOT.
  158. * @param array $version_files
  159. * Array of key => value pairs, where key is location library version number,
  160. * and value is the location of that file that to be included when this
  161. * library is loaded with libraries_load().
  162. */
  163. function _less_libraries_determine_location(array &$library, array $locations, array $version_files) {
  164. foreach (array_filter($locations) as $location) {
  165. foreach ($version_files as $version_file => $class_file) {
  166. if (file_exists($location . DIRECTORY_SEPARATOR . $version_file)) {
  167. $library['library path'] = $location;
  168. $library['files'] = array(
  169. 'php' => array(
  170. $class_file,
  171. ),
  172. );
  173. $library['version arguments']['file'] = $version_file;
  174. return; // File has been found, skip remaining $locations and $version_files
  175. }
  176. }
  177. }
  178. }