dt('Generates markdown documentation for the Drupal based code.'), 'arguments' => [ 'type' => 'The specific type of documentation to generate, defaults to "all". Can be: "all", "settings".', ], 'aliases' => ['bs-docs'], ]; return $items; } /** * Generates markdown documentation. * * @param string $type * The type of documentation. */ function drush_bootstrap_generate_docs($type = 'all') { $types = $type === 'all' ? ['settings'] : [$type]; foreach ($types as $type) { $function = "_drush_bootstrap_generate_docs_$type"; if (function_exists($function)) { $ret = $function(Bootstrap::getTheme('bootstrap')); if ($ret) { drush_log('Successfully generated documentation for: ' . $type, 'success'); } else { drush_log('Unable to generate documentation for: ' . $type, 'error'); } } else { drush_log('Invalid documentation type: ' . $type, 'error'); } } } /** * Generates settings documentation. * * @param \Drupal\bootstrap\Theme $bootstrap * The theme instance of the Drupal Bootstrap base theme. */ function _drush_bootstrap_generate_docs_settings(Theme $bootstrap) { $output[] = ''; $output[] = ''; $output[] = ''; $output[] = '# Theme Settings'; $output[] = ''; $output[] = 'To override a setting, open `./config/install/THEMENAME.settings.yml` and add the following:'; $output[] = ''; $output[] = '```yaml'; $output[] = '# Settings'; $output[] = ''; $output[] = 'settings:'; $output[] = ' SETTING_NAME: SETTING_VALUE'; $output[] = '```'; // Determine the groups. $groups = []; foreach ($bootstrap->getSettingPlugin() as $setting) { // Only get the first two groups (we don't need 3rd, or more, levels). $_groups = array_slice($setting->getGroups(), 0, 2, FALSE); if (!$_groups) { continue; } $groups[implode(' > ', $_groups)][] = $setting->getPluginDefinition(); } // Generate a table of each group's settings. foreach ($groups as $group => $settings) { $output[] = ''; $output[] = '---'; $output[] = ''; $output[] = "### $group"; $output[] = ''; $output[] = ''; $output[] = ' '; $output[] = ' '; $output[] = ' '; $output[] = ' '; $output[] = ' '; $output[] = ' '; $output[] = ' '; foreach ($settings as $definition) { $output[] = ' '; $output[] = ' '; $output[] = ' '; $output[] = ' '; } $output[] = ' '; $output[] = '
Setting nameDescription and default value
'; $output[] = $definition['id']; $output[] = ' '; $output[] = '
'; $output[] = str_replace('"e;', '"', wordwrap($definition['description'])); $output[] = '
'; $output[] = '
';
      $output[] = wordwrap(Yaml::encode([$definition['id'] => $definition['defaultValue']]));
      $output[] = '
'; $output[] = '
'; } // Ensure we have link references at the bottom. $output[] = ''; $output[] = '[Drupal Bootstrap]: https://www.drupal.org/project/bootstrap'; $output[] = '[Bootstrap Framework]: https://getbootstrap.com/docs/3.3/'; // Save the generated output to the appropriate file. return file_put_contents(realpath($bootstrap->getPath() . '/docs/Theme-Settings.md'), implode("\n", $output)) !== FALSE; }