You are here

function styleguide_page in Style Guide 6

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

The styleguide page.

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

File

./styleguide.module, line 85

Code

function styleguide_page($theme = NULL) {
  drupal_add_css(drupal_get_path('module', 'styleguide') . '/styleguide.css');
  module_load_include('inc', 'styleguide', 'styleguide.styleguide');

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

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

  // 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 HTML tag. In Drupal 7, the preference
      // is to pass theme('html_tag') instead. This is kept for API
      // compatibility with Drupal 6.
      if (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'] . '>';
        }
      }
      else {
        if (isset($item['content']) && is_array($item['content'])) {
          $display = drupal_render($item['content']);
        }
        else {
          if (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', $header[$group], $group);
  }
  $output = theme('styleguide_header', array(
    'theme_info' => $theme_info,
  ));
  $output .= theme('styleguide_links', array(
    'items' => $head,
  ));
  $output .= theme('styleguide_content', array(
    'content' => $content,
  ));

  // Return the page.
  return $output;
}