-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathautomatically_add_theme.patch
More file actions
119 lines (118 loc) · 4.95 KB
/
automatically_add_theme.patch
File metadata and controls
119 lines (118 loc) · 4.95 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
diff --git a/bootstrap.drush.inc b/bootstrap.drush.inc
index 79b9685..22d1f0b 100644
--- a/bootstrap.drush.inc
+++ b/bootstrap.drush.inc
@@ -11,6 +11,7 @@ use Drupal\Component\Serialization\Yaml;
* Implements hook_drush_command().
*/
function bootstrap_drush_command() {
+ $items = array();
$items['bootstrap-generate-docs'] = [
'description' => dt('Generates markdown documentation for the Drupal based code.'),
'arguments' => [
@@ -18,6 +19,23 @@ function bootstrap_drush_command() {
],
'aliases' => ['bs-docs'],
];
+ $items['bootstrap-sub-theme'] = array(
+ 'description' => 'Create a Bootstrap foundation sub-theme',
+ 'aliases' => array('bsass'),
+ 'arguments' => array(
+ 'name' => 'Your sub-theme name.',
+ 'machine_name' => 'A machine-readable name for your theme, optional only [a-z, 0-9] ',
+ ),
+ 'options' => array(
+ 'description' => 'Your sub-theme description.',
+ 'machine-name' => '[a-z, 0-9] A machine-readable name for your theme.'
+ ),
+ 'examples' => array(
+ 'drush bsass "custom theme name"' => 'Create a sub-theme with the default options.',
+ 'drush bsass "foo bar" "foo_bar" --description="My supersweet awesome theme"' => 'Create a sub-theme with additional options.',
+ ),
+ );
+
return $items;
}
@@ -108,3 +126,81 @@ function _drush_bootstrap_generate_docs_settings(Theme $bootstrap) {
// Save the generated output to the appropriate file.
return file_put_contents(realpath($bootstrap->getPath() . '/docs/Theme-Settings.md'), implode("\n", $output)) !== FALSE;
}
+
+/**
+ * Create a Boostrap sub-theme.
+ */
+function drush_bootstrap_sub_theme($name = NULL, $machine_name = NULL, $description = NULL) {
+ if (empty($name)) {
+ drush_set_error(dt("Please provide a name for the sub-theme.\nUSAGE:\tdrush bsass [name] [machine_name !OPTIONAL] [description !OPTIONAL]\n"));
+ return;
+ }
+ //Filter everything but letters, numbers, underscores, and hyphens
+ $machine_name = !empty($machine_name) ? preg_replace('/[^a-z0-9_-]+/', '', strtolower($machine_name)) : preg_replace('/[^a-z0-9_-]+/', '', strtolower($name));
+ // Eliminate hyphens
+ $machine_name = str_replace('-', '_', $machine_name);
+
+ $bootstrap_path = drush_get_context('DRUSH_DRUPAL_ROOT') . '/' . drupal_get_path('theme', 'bootstrap');
+ $subtheme_path = explode('/', $bootstrap_path);
+ array_pop($subtheme_path);
+ $subtheme_path = implode('/', $subtheme_path) . '/' . $machine_name;
+
+ // Make a fresh copy of the subtheme.
+ $s = drush_copy_dir("$bootstrap_path/starterkits/sass", $subtheme_path);
+ if (empty($s)) {
+ return;
+ }
+
+ // Rename files and fill in the theme machine name
+ drush_op('rename', "$subtheme_path/THEMENAME.starterkit.yml", "$subtheme_path/$machine_name.info.yml");
+ drush_op('rename', "$subtheme_path/THEMENAME.libraries.yml", "$subtheme_path/$machine_name.libraries.yml");
+ drush_op('rename', "$subtheme_path/THEMENAME.theme", "$subtheme_path/$machine_name.theme");
+ drush_op('rename', "$subtheme_path/config/install/THEMENAME.settings.yml", "$subtheme_path/config/install/$machine_name.settings.yml");
+ drush_op('rename', "$subtheme_path/config/schema/THEMENAME.schema.yml", "$subtheme_path/config/schema/$machine_name.schema.yml");
+
+
+ // Change the name of the theme.
+ drush_op('bootstrap_file_str_replace', "$subtheme_path/$machine_name.info.yml", 'THEMETITLE', "$name");
+
+ // Change the name of the theme.
+ if (!empty($description)) {
+ drush_op('bootstrap_file_str_replace', "$subtheme_path/$machine_name.info.yml", 'Custom sub-theme, inherits from the Bootstrap base theme', $description);
+ }
+
+ // Replaces instances of THEMENAME in required files to name of the theme.
+ drush_op('bootstrap_file_str_replace', "$subtheme_path/$machine_name.info.yml", 'THEMENAME', "$machine_name");
+
+ // Replaces instances of THEMENAME in required files to name of the theme.
+ drush_op('bootstrap_file_str_replace', "$subtheme_path/config/install/$machine_name.settings.yml", 'THEMENAME.settings', "$machine_name" . "." . "settings");
+ drush_op('bootstrap_file_str_replace', "$subtheme_path/config/schema/$machine_name.schema.yml", 'THEMETITLE', "$name");
+
+ // Notify user of the newly created theme.
+ drush_print(dt("\n!name sub-theme was created in !path. \n",
+ array(
+ '!name' => $name,
+ '!path' => $subtheme_path,
+ )
+ ));
+ drush_pm_enable_validate($machine_name);
+ drush_pm_enable($machine_name);
+
+}
+
+/**
+ * Internal helper: Replace strings in a file.
+ */
+function bootstrap_file_str_replace($file_path, $find, $replace) {
+ $file_contents = file_get_contents($file_path);
+ $file_contents = str_replace($find, $replace, $file_contents);
+ file_put_contents($file_path, $file_contents);
+}
+
+/**
+ * Implements hook_drush_help().
+ */
+function bootstrap_drush_help($section) {
+ switch ($section) {
+ case 'drush:bootstrap-sub-theme':
+ return dt("Create a Boostrap custom sub-theme.");
+ }
+}
\ No newline at end of file