omega_tools.drush.inc 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115
  1. <?php
  2. /**
  3. * Implements hook_drush_command().
  4. */
  5. function omega_tools_drush_command() {
  6. $items = array();
  7. $items['omega-subtheme'] = array(
  8. 'description' => 'Create a Omega subtheme.',
  9. 'arguments' => array(
  10. 'name' => 'The name of your subtheme.',
  11. ),
  12. 'options' => array(
  13. 'destination' => 'The destination of your subtheme. Defaults to "all" (sites/all/themes).',
  14. 'machine_name' => 'The machine-readable name of your subtheme. This will be auto-generated from the human-readable name if ommited.',
  15. 'base' => 'The base theme that you want to build on. Defaults to "Omega" or the base theme of the starterkit (if provided).',
  16. 'starterkit' => 'The starterkit that your subtheme should use. It must have the same base theme as your subtheme. Defaults to "starterkit_omega_html5" if "--base" is not set either.',
  17. 'enable' => 'Automatically enable the subtheme after creation.',
  18. 'set-default' => 'Automatically enable the subtheme after creation and make it the default theme.',
  19. ),
  20. 'examples' => array(
  21. 'drush omega-subtheme "My Theme"' => 'Creates a Omega subtheme called "My Theme".',
  22. 'drush omega-subtheme "My Theme" --destination=example.com' => 'Creates a Omega subtheme called "My Theme" in sites/example.com/themes.',
  23. 'drush omega-subtheme "My Theme" --starterkit=starterkit_omega_html5' => 'Uses the HTML5 starterkit to create a Omega subtheme called "My Theme" in sites/all/themes (default).',
  24. 'drush omega-subtheme "My Theme" --base=alpha' => 'Creates a Alpha subtheme called "My Theme" without using a starterkit.',
  25. ),
  26. );
  27. return $items;
  28. }
  29. /**
  30. * Implements of hook_drush_help().
  31. */
  32. function omega_tools_drush_help($section) {
  33. switch ($section) {
  34. case 'drush:omega-subtheme':
  35. return dt('This command will create a Omega subtheme.');
  36. }
  37. }
  38. /**
  39. * Implements of drush_hook_COMMAND_validate().
  40. */
  41. function drush_omega_tools_omega_subtheme_validate($name) {
  42. system_rebuild_theme_data();
  43. $themes = list_themes();
  44. $destination = drush_get_option('destination', 'all');
  45. $machine_name = drush_get_option('machine_name', _omega_tools_transform_theme_name($name));
  46. $base = drush_get_option('base');
  47. $starterkit = drush_get_option('starterkit');
  48. drush_set_option('machine_name', $machine_name);
  49. if (!_omega_tools_theme_exists('alpha') || !_omega_tools_theme_exists('omega')) {
  50. return drush_set_error('OMEGA_TOOLS_THEME_ERROR', dt('Where is the Omega base theme? I has not found it. :('));
  51. }
  52. if (!$machine_name || !preg_match('/^[a-z][a-z0-9_]*$/', $machine_name)) {
  53. return drush_set_error('OMEGA_TOOLS_THEME_ERROR', dt('The machine name is invalid or could not be generated properly. It may only contain lowercase numbers, letters and underscores and must start with a letter. Please provide a proper machine name by using "--machine_name".'));
  54. }
  55. if (_omega_tools_theme_exists($machine_name)) {
  56. return drush_set_error('OMEGA_TOOLS_THEME_ERROR', dt('A theme with that name already exists. The machine-readable name must be unique.'));
  57. }
  58. if (!in_array($destination, omega_tools_sites())) {
  59. return drush_set_error('OMEGA_TOOLS_THEME_ERROR', dt('The destination is invalid.'));
  60. }
  61. if ($starterkit && (!_omega_tools_theme_exists($starterkit) || !_omega_tools_is_starterkit($starterkit))) {
  62. return drush_set_error('OMEGA_TOOLS_THEME_ERROR', dt('There is no valid starterkit with the name !starterkit.', array('!starterkit' => $starterkit)));
  63. }
  64. if (!$base && $starterkit) {
  65. $base = $themes[$starterkit]->info['base theme'];
  66. drush_set_option('base', $base);
  67. }
  68. if ($base && !array_key_exists($base, omega_tools_base_themes())) {
  69. return drush_set_error('OMEGA_TOOLS_THEME_ERROR', dt('There is no base theme with the name !base.', array('!base' => $base)));
  70. }
  71. if ($starterkit && $themes[$starterkit]->info['base theme'] != $base) {
  72. return drush_set_error('OMEGA_TOOLS_THEME_ERROR', dt('The base theme of the selected starterkit does not match the selected base theme.'));
  73. }
  74. if (!$base && !$starterkit) {
  75. drush_set_option('base', 'omega');
  76. drush_set_option('starterkit', 'starterkit_omega_html5');
  77. }
  78. else if (!$base) {
  79. drush_set_option('base', 'omega');
  80. }
  81. }
  82. /**
  83. * Implements of drush_hook_COMMAND().
  84. */
  85. function drush_omega_tools_omega_subtheme($name) {
  86. $subtheme = new stdClass();
  87. $subtheme->new = TRUE;
  88. $subtheme->name = $name;
  89. $subtheme->machine_name = drush_get_option('machine_name');
  90. $subtheme->starterkit = drush_get_option('starterkit');
  91. $subtheme->path = 'sites/' . drush_get_option('destination', 'all') . '/themes/' . $subtheme->machine_name;
  92. $subtheme->base = drush_get_option('base');
  93. $subtheme->default = drush_get_option('set-default') !== NULL;
  94. $subtheme->status = $subtheme->default || drush_get_option('enable') !== NULL;
  95. omega_tools_subtheme_create($subtheme);
  96. omega_tools_subtheme_process($subtheme);
  97. }