styleguide.api.php 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104
  1. <?php
  2. // $Id: styleguide.api.php,v 1.6 2010/10/23 20:58:17 agentken Exp $
  3. /**
  4. * Register a style guide element for display.
  5. *
  6. * hook_styleguide() defines an array of items to render for theme
  7. * testing. Each item is rendered as an element on the style guide page.
  8. *
  9. * Each item should be keyed with a unique identifier. This value will be
  10. * used to create a named anchor link on the Style Guide page.
  11. *
  12. * Options:
  13. * -- 'title' (required). A string indicating the element name.
  14. * -- 'description' (optional). A short description of the item.
  15. * -- 'theme' (optional). A string indicating the theme function to invoke.
  16. * If used, you must return a 'variables' array element. Otherwise, you
  17. * must return a 'content' string.
  18. * -- 'variables' (optional). An array of named vairables to pass to the
  19. * theme function. This structure is designed to let you test your theme
  20. * functions for syntax.
  21. * -- 'content' (optional). A string or renderable array of content to
  22. * present. May be used in conjunction with a 'tag' element, or used instead
  23. * of a theme callback.
  24. * -- 'tag' (optional). A string indicating a valid HTML tag (wihout <>).
  25. * This tag will be wrapped around the content. In Drupal 7, this element is
  26. * deprecated in favor of theme_html_tag().
  27. * -- 'attributes' (optional). An array of attributes to apply to a tag element.
  28. * -- 'group' (optional). A string indicating the context of this element.
  29. * Groups are organized within the preview interface. If no group is
  30. * provided, the item will be assigned to the 'Common' group.
  31. *
  32. * @return $items
  33. * An array of items to render.
  34. */
  35. function hook_styleguide() {
  36. $items['ul'] = array(
  37. 'title' => t('Unordered list'),
  38. 'theme' => 'item_list',
  39. 'variables' => array('items' => styleguide_list(), 'type' => 'ul'),
  40. 'group' => t('Common'),
  41. );
  42. $items['text'] => array(
  43. 'title' => t('Text block'),
  44. 'content' => styleguide_paragraph(3),
  45. 'group' => t('Text'),
  46. 'description' => t('A block of three paragraphs'),
  47. );
  48. $items['h1'] = array(
  49. 'title' => t('Text block'),
  50. 'tag' => 'h1',
  51. 'content' => styleguide_word(3),
  52. 'group' => t('Text'),
  53. );
  54. $items['div-format'] = array(
  55. 'title' => t('Div special'),
  56. 'description' => t('Add the "format" class to emphasize an entire section.'),
  57. 'tag' => 'div',
  58. 'attributes' => array('class' => 'format'),
  59. 'content' => styleguide_paragraph(1),
  60. );
  61. return $items;
  62. }
  63. /**
  64. * Alter styleguide elements.
  65. *
  66. * @param &$items
  67. * An array of items to be displayed.
  68. *
  69. * @return
  70. * No return value. Modify $items by reference.
  71. *
  72. * @see hook_styleguide()
  73. */
  74. function hook_styleguide_alter(&$items) {
  75. // Add a class to the text test.
  76. $items['text']['content'] = '<div class="mytestclass">' . $items['text']['content'] . '</div>';
  77. // Remove the headings tests.
  78. unset($items['headings']);
  79. }
  80. /**
  81. * Alter display information about a theme for Style Guide.
  82. *
  83. * This function accepts the 'info' property of a $theme object. Currently,
  84. * only the 'description' element of the $theme_info array is used by
  85. * Style Guide.
  86. *
  87. * Note that the 'description' element will be run through t() automatically.
  88. *
  89. * @param &$theme_info
  90. * Theme information array.
  91. * @param $theme
  92. * The machine name of this theme.
  93. *
  94. * @return
  95. * No return value. Modify $theme_info by reference.
  96. */
  97. function styleguide_styleguide_theme_info_alter(&$theme_info, $theme) {
  98. if ($theme == 'stark') {
  99. $theme_info['description'] = 'A basic theme for development.';
  100. }
  101. }