diff --git a/STARTERKIT/README.txt b/STARTERKIT/README.txt new file mode 100644 index 0000000..5859a6b --- /dev/null +++ b/STARTERKIT/README.txt @@ -0,0 +1,19 @@ +CONTENTS OF THIS FILE +--------------------- + + * Introduction + + +INTRODUCTION +------------ + +The UIkit theme is a lightweight frontend framework with a comprehensive +collection of HTML, CSS, and JS components. It is a great alternative to other +frontend frameworks, plus is very lightweight and provides a lot of useful tools +for customizing with very little requirements. + + * For a full description of the theme, visit the project page: + https://drupal.org/project/uikit + + * To submit bug reports and feature suggestions, or to track changes: + https://drupal.org/project/issues/uikit diff --git a/STARTERKIT/STARTERKIT.info b/STARTERKIT/STARTERKIT.info new file mode 100644 index 0000000..5f93f76 --- /dev/null +++ b/STARTERKIT/STARTERKIT.info @@ -0,0 +1,16 @@ +name: STARTERKIT +type: theme +description: 'UIkit Sub-theme' +core: 8.x +base theme: uikit + +regions: + navbar: 'Navigation Bar' + offcanvas: 'Offcanvas Navigation' + content: Content + sidebar_first: 'Left Sidebar' + sidebar_second: 'Right Sidebar' + footer: 'Footer' + +libraries: + - STARTERKIT/global-styling diff --git a/STARTERKIT/STARTERKIT.libraries.yml b/STARTERKIT/STARTERKIT.libraries.yml new file mode 100644 index 0000000..0e67d91 --- /dev/null +++ b/STARTERKIT/STARTERKIT.libraries.yml @@ -0,0 +1,13 @@ +global-style: + version: VERSION + css: + base: + css/STARTERKIT.base.css: {} + layout: + css/STARTERKIT.layout.css: {} + component: + css/STARTERKIT.component.css: {} + theme: + css/STARTERKIT.theme.css: {} + js: + js/STARTERKIT.theme.js: {} diff --git a/STARTERKIT/STARTERKIT.theme b/STARTERKIT/STARTERKIT.theme new file mode 100644 index 0000000..2c934e8 --- /dev/null +++ b/STARTERKIT/STARTERKIT.theme @@ -0,0 +1,14 @@ + + + + + + + + image/svg+xml + + + + + + + + + diff --git a/STARTERKIT/screenshot.png b/STARTERKIT/screenshot.png new file mode 100644 index 0000000..c65e1e4 Binary files /dev/null and b/STARTERKIT/screenshot.png differ diff --git a/STARTERKIT/theme-settings.php b/STARTERKIT/theme-settings.php new file mode 100644 index 0000000..640344e --- /dev/null +++ b/STARTERKIT/theme-settings.php @@ -0,0 +1,19 @@ + 'Create a UIkit sub-theme.', + 'arguments' => [ + 'machine_name' => '[optional] A machine-readable name for your theme.', + 'name' => 'A name for your theme.', + ], + 'aliases' => array('uikit-sk'), + 'options' => [ + 'name' => 'A name for your theme.', + 'machine-name' => '[a-z, 0-9, _] A machine-readable name for your theme.', + 'path' => 'The path where your theme will be created. Defaults to: themes', + 'description' => 'A description of your theme.', + ], + 'examples' => [ + 'drush uikit-sk "Amazing name"' => 'Create a sub-theme, using the default options.', + 'drush uikit-sk zomg_amazing "Amazing name"' => 'Create a sub-theme with a specific machine name.', + 'drush uikit-sk "Amazing name" --path=sites/default/themes --description="So amazing."' => 'Create a sub-theme in the specified directory with a custom description.', + ], + ]; + + return $commands; +} + +/** + * Create a UIkit sub-theme using the starter kit. + */ +function drush_uikit_starterkit($machine_name = NULL, $name = NULL) { + // Determine the theme name and machine name. + if (!isset($name)) { + // If only given one argument, it is the $name. + if (isset($machine_name)) { + $name = $machine_name; + unset($machine_name); + } + else { + $name = drush_get_option('name'); + } + + if (!isset($machine_name)) { + $machine_name = drush_get_option('machine-name'); + } + } + + if (!$name) { + if ($machine_name) { + $name = $machine_name; + } + else { + if (FALSE) { + // Allow localize.drupal.org to pick up the string to translate. + t('The name of the theme was not specified.'); + } + return drush_set_error('UIKIT_SUBTHEME_NAME_NOT_SPECIFIED', dt('The name of the theme was not specified.')); + } + } + + if (!$machine_name) { + $machine_name = $name; + } + + // Clean up the machine name. + $machine_name = str_replace(' ', '_', strtolower($machine_name)); + $search = array( + '/[^a-z0-9_]/', // Remove characters not valid in function names. + '/^[^a-z]+/', // Functions must begin with an alpha character. + ); + $machine_name = preg_replace($search, '', $machine_name); + + // Determine the path to the new sub-theme. + $subtheme_path = 'themes'; + if ($path = drush_get_option('path')) { + $subtheme_path = drush_trim_path($path); + } + $subtheme_path = drush_normalize_path(drush_get_context('DRUSH_DRUPAL_ROOT') . '/' . $subtheme_path . '/' . $machine_name); + + // Ensure the destination directory exists. + if (!is_dir(dirname($subtheme_path))) { + if (FALSE) { + // Allow localize.drupal.org to pick up the string to translate. + t('The directory "!directory" was not found.', array('!directory' => dirname($subtheme_path))); + } + return drush_set_error('UIKIT_DESTINATION_NOT_FOUND', dt('The directory "!directory" was not found.', array('!directory' => dirname($subtheme_path)))); + } + + // Ensure the STARTERKIT directory exists. + $starterkit_path = drush_normalize_path(drush_get_context('DRUSH_DRUPAL_ROOT') . '/' . drupal_get_path('theme', 'uikit') . '/STARTERKIT'); + if (!is_dir($starterkit_path)) { + if (FALSE) { + // Allow localize.drupal.org to pick up the string to translate. + t('The STARTERKIT directory was not found in "!directory"', array('!directory' => dirname($starterkit_path))); + } + return drush_set_error('UIKIT_STARTERKIT_NOT_FOUND', dt('The STARTERKIT directory was not found in "!directory"', array('!directory' => dirname($starterkit_path)))); + } + + // Make a fresh copy of the original starter kit. + drush_op('drush_copy_dir', $starterkit_path, $subtheme_path); + + // Rename the STARTERKIT files. + $subtheme_info_file = $subtheme_path . '/' . $machine_name . '.info.yml'; + $subtheme_libraries_file = $subtheme_path . '/' . $machine_name . '.libraries.yml'; + $subtheme_theme_file = $subtheme_path . '/' . $machine_name . '.theme'; + $subtheme_css_base_file = $subtheme_path . '/css/' . $machine_name . '.base.css'; + $subtheme_css_component_file = $subtheme_path . '/css/' . $machine_name . '.component.css'; + $subtheme_css_layout_file = $subtheme_path . '/css/' . $machine_name . '.layout.css'; + $subtheme_css_theme_file = $subtheme_path . '/css/' . $machine_name . '.theme.css'; + $subtheme_js_theme_file = $subtheme_path . '/js/' . $machine_name . '.theme.js'; + drush_op('rename', drush_normalize_path($subtheme_path . '/STARTERKIT.info'), drush_normalize_path($subtheme_info_file)); + drush_op('rename', drush_normalize_path($subtheme_path . '/STARTERKIT.libraries.yml'), drush_normalize_path($subtheme_libraries_file)); + drush_op('rename', drush_normalize_path($subtheme_path . '/STARTERKIT.theme'), drush_normalize_path($subtheme_theme_file)); + drush_op('rename', drush_normalize_path($subtheme_path . '/css/STARTERKIT.base.css'), drush_normalize_path($subtheme_css_base_file)); + drush_op('rename', drush_normalize_path($subtheme_path . '/css/STARTERKIT.component.css'), drush_normalize_path($subtheme_css_component_file)); + drush_op('rename', drush_normalize_path($subtheme_path . '/css/STARTERKIT.layout.css'), drush_normalize_path($subtheme_css_layout_file)); + drush_op('rename', drush_normalize_path($subtheme_path . '/css/STARTERKIT.theme.css'), drush_normalize_path($subtheme_css_theme_file)); + drush_op('rename', drush_normalize_path($subtheme_path . '/js/STARTERKIT.theme.js'), drush_normalize_path($subtheme_js_theme_file)); + + // Alter the contents of the .info file based on the command options. + $alterations = array( + 'name: STARTERKIT' => 'name: ' . $name, + 'STARTERKIT/global-styling' => $machine_name . '/global-styling', + ); + if ($description = drush_get_option('description')) { + $alterations['UIkit Sub-theme'] = $description; + } + drush_op('uikit_file_str_replace', $subtheme_info_file, array_keys($alterations), $alterations); + + // Replace all occurrences of 'STARTERKIT' with the machine name of our sub theme. + drush_op('uikit_file_str_replace', $subtheme_path . '/theme-settings.php', 'STARTERKIT', $machine_name); + drush_op('uikit_file_str_replace', $subtheme_path . '/' . $machine_name . '.libraries.yml', 'STARTERKIT', $machine_name); + drush_op('uikit_file_str_replace', $subtheme_path . '/' . $machine_name . '.theme', 'STARTERKIT', $machine_name); + drush_op('uikit_file_str_replace', $subtheme_path . '/includes/alter.inc', 'STARTERKIT', $machine_name); + drush_op('uikit_file_str_replace', $subtheme_path . '/includes/preprocess.inc', 'STARTERKIT', $machine_name); + drush_op('uikit_file_str_replace', $subtheme_path . '/includes/theme.inc', 'STARTERKIT', $machine_name); + drush_op('uikit_file_str_replace', $subtheme_path . '/js/' . $machine_name . '.theme.js', 'Drupal.behaviors.STARTERKIT', str_replace(' ', '', 'Drupal.behaviors.' . $name)); + drush_op('uikit_file_str_replace', $subtheme_path . '/js/' . $machine_name . '.theme.js', 'STARTERKIT', $machine_name); + + // Notify user of the newly created theme. + if (FALSE) { + // Allow localize.drupal.org to pick up the string to translate. + t('Starter kit for "!name" created in: !path', array('!name' => $name, '!path' => $subtheme_path)); + } + drush_print(dt('Starter kit for "!name" created in: !path', array( + '!name' => $name, + '!path' => $subtheme_path, + ))); +} + +/** + * Replace strings in a file. + */ +function uikit_file_str_replace($file_path, $find, $replace) { + $file_path = drush_normalize_path($file_path); + $file_contents = file_get_contents($file_path); + $file_contents = str_replace($find, $replace, $file_contents); + file_put_contents($file_path, $file_contents); +}