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