You are here

function styleguide_page in Style Guide 7

Same name and namespace in other branches
  1. 6 styleguide.module \styleguide_page()

The styleguide page.

1 call to styleguide_page()
styleguide_block_view in ./styleguide.module
Implements hook_block_view().
1 string reference to 'styleguide_page'
styleguide_menu in ./styleguide.module
Implements hook_menu().

File

./styleguide.module, line 124

Code

function styleguide_page($theme = NULL) {

  // Get the path to the module for loading includes.
  $path = drupal_get_path('module', 'styleguide');

  // TODO: notice about the Overlay module?
  // Check the theme.
  if (is_null($theme)) {
    $theme = variable_get('theme_default', 'bartik');
  }

  // Get theme data.
  $themes = list_themes();
  $active = $themes[$theme];

  // Include modules for which we implement styleguides.
  $modules = module_list();
  foreach ($modules as $module) {
    if (file_exists($path . '/modules/' . $module . '.inc')) {
      include_once $path . '/modules/' . $module . '.inc';
    }
  }

  // Get visual testing elements.
  $items = module_invoke_all('styleguide');
  drupal_alter('styleguide', $items);

  // Get theme style information.
  $theme_info = $active->info;
  drupal_alter('styleguide_theme_info', $theme_info, $theme);
  $groups = array();
  foreach ($items as $key => $item) {
    if (!isset($item['group'])) {
      $item['group'] = t('Common');
    }
    else {
      $item['group'] = t('@group', array(
        '@group' => $item['group'],
      ));
    }
    $item['title'] = t('@title', array(
      '@title' => $item['title'],
    ));
    $groups[$item['group']][$key] = $item;
  }
  ksort($groups);

  // Create a navigation header.
  $header = array();
  $head = '';
  $content = '';

  // Process the elements, by group.
  foreach ($groups as $group => $elements) {
    foreach ($elements as $key => $item) {
      $display = '';

      // Output a standard theme item.
      if (isset($item['theme'])) {
        $display = theme($item['theme'], $item['variables']);
      }
      elseif (isset($item['tag']) && isset($item['content'])) {
        if (empty($item['attributes'])) {
          $display = '<' . $item['tag'] . '>' . $item['content'] . '</' . $item['tag'] . '>';
        }
        else {
          $display = '<' . $item['tag'] . ' ' . drupal_attributes($item['attributes']) . '>' . $item['content'] . '</' . $item['tag'] . '>';
        }
      }
      elseif (isset($item['content']) && is_array($item['content'])) {
        $display = drupal_render($item['content']);
      }
      elseif (isset($item['content'])) {
        $display = $item['content'];
      }

      // Add the content.
      $content .= theme('styleguide_item', array(
        'key' => $key,
        'item' => $item,
        'content' => $display,
      ));

      // Prepare the header link.
      $header[$group][] = l($item['title'], $_GET['q'], array(
        'fragment' => $key,
      ));
    }
    $head .= theme('item_list', array(
      'items' => $header[$group],
      'title' => $group,
    ));
  }

  // Return the page.
  $build = array();
  $build['header']['#markup'] = theme('styleguide_header', array(
    'theme_info' => $theme_info,
  ));
  $build['navigation']['#markup'] = theme('styleguide_links', array(
    'items' => $head,
  ));
  $build['content']['#markup'] = theme('styleguide_content', array(
    'content' => $content,
  ));
  $build['content']['#attached']['css'][] = $path . '/styleguide.css';
  return $build;
}