first import

This commit is contained in:
Bachir Soussi Chiadmi
2015-04-08 11:40:19 +02:00
commit 1bc61b12ad
8435 changed files with 1582817 additions and 0 deletions

View File

@ -0,0 +1,39 @@
// $Id: CHANGELOG.txt,v 1.8 2010/10/23 23:28:43 agentken Exp $
CHANGELOG file for Style Guide.
23-OCT-2010
-- Uses proper theming for page display.
-- Adds styleguide.theme.inc.
-- Documents preferred use of theme_html_tag().
-- Fixes default page callback.
22-OCT-2010
-- #949758. Use t() normally.
-- #949764. Suppert attributes for tags.
21-OCT-2010
-- Patch #948886 by Dave Reid. General code cleaup and renderable arrays.
20-OCT-2010
-- Adds bottom baseline to element displays.
-- Adds more hook documentation.
-- Adds optional element descriptions.
-- Adds theme descriptions.
-- Adds hook_styleguide_theme_info_alter().
-- Adds basic tests for images within paragraphs.
-- Splits forms into smaller chunks.
19-OCT-2010
-- README added (inadarei) and proofread (agentrickard).
-- Adds group options to the API, cleaning the interface.
-- Updates API documentation.
-- Adds RTL css support.
-- Fixes RTL file. Adds more padding on items.
06-OCT-2010
-- Adds hook_system_theme_page_alter().
-- Adds new test items.
05-OCT-2010
-- Initial commit.

View File

@ -0,0 +1,274 @@
GNU GENERAL PUBLIC LICENSE
Version 2, June 1991
Copyright (C) 1989, 1991 Free Software Foundation, Inc. 675 Mass Ave,
Cambridge, MA 02139, USA. Everyone is permitted to copy and distribute
verbatim copies of this license document, but changing it is not allowed.
Preamble
The licenses for most software are designed to take away your freedom to
share and change it. By contrast, the GNU General Public License is
intended to guarantee your freedom to share and change free software--to
make sure the software is free for all its users. This General Public License
applies to most of the Free Software Foundation's software and to any other
program whose authors commit to using it. (Some other Free Software
Foundation software is covered by the GNU Library General Public License
instead.) You can apply it to your programs, too.
When we speak of free software, we are referring to freedom, not price. Our
General Public Licenses are designed to make sure that you have the
freedom to distribute copies of free software (and charge for this service if
you wish), that you receive source code or can get it if you want it, that you
can change the software or use pieces of it in new free programs; and that
you know you can do these things.
To protect your rights, we need to make restrictions that forbid anyone to
deny you these rights or to ask you to surrender the rights. These restrictions
translate to certain responsibilities for you if you distribute copies of the
software, or if you modify it.
For example, if you distribute copies of such a program, whether gratis or for
a fee, you must give the recipients all the rights that you have. You must make
sure that they, too, receive or can get the source code. And you must show
them these terms so they know their rights.
We protect your rights with two steps: (1) copyright the software, and (2)
offer you this license which gives you legal permission to copy, distribute
and/or modify the software.
Also, for each author's protection and ours, we want to make certain that
everyone understands that there is no warranty for this free software. If the
software is modified by someone else and passed on, we want its recipients
to know that what they have is not the original, so that any problems
introduced by others will not reflect on the original authors' reputations.
Finally, any free program is threatened constantly by software patents. We
wish to avoid the danger that redistributors of a free program will individually
obtain patent licenses, in effect making the program proprietary. To prevent
this, we have made it clear that any patent must be licensed for everyone's
free use or not licensed at all.
The precise terms and conditions for copying, distribution and modification
follow.
GNU GENERAL PUBLIC LICENSE
TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND
MODIFICATION
0. This License applies to any program or other work which contains a notice
placed by the copyright holder saying it may be distributed under the terms
of this General Public License. The "Program", below, refers to any such
program or work, and a "work based on the Program" means either the
Program or any derivative work under copyright law: that is to say, a work
containing the Program or a portion of it, either verbatim or with
modifications and/or translated into another language. (Hereinafter, translation
is included without limitation in the term "modification".) Each licensee is
addressed as "you".
Activities other than copying, distribution and modification are not covered
by this License; they are outside its scope. The act of running the Program is
not restricted, and the output from the Program is covered only if its contents
constitute a work based on the Program (independent of having been made
by running the Program). Whether that is true depends on what the Program
does.
1. You may copy and distribute verbatim copies of the Program's source
code as you receive it, in any medium, provided that you conspicuously and
appropriately publish on each copy an appropriate copyright notice and
disclaimer of warranty; keep intact all the notices that refer to this License
and to the absence of any warranty; and give any other recipients of the
Program a copy of this License along with the Program.
You may charge a fee for the physical act of transferring a copy, and you
may at your option offer warranty protection in exchange for a fee.
2. You may modify your copy or copies of the Program or any portion of it,
thus forming a work based on the Program, and copy and distribute such
modifications or work under the terms of Section 1 above, provided that you
also meet all of these conditions:
a) You must cause the modified files to carry prominent notices stating that
you changed the files and the date of any change.
b) You must cause any work that you distribute or publish, that in whole or in
part contains or is derived from the Program or any part thereof, to be
licensed as a whole at no charge to all third parties under the terms of this
License.
c) If the modified program normally reads commands interactively when run,
you must cause it, when started running for such interactive use in the most
ordinary way, to print or display an announcement including an appropriate
copyright notice and a notice that there is no warranty (or else, saying that
you provide a warranty) and that users may redistribute the program under
these conditions, and telling the user how to view a copy of this License.
(Exception: if the Program itself is interactive but does not normally print such
an announcement, your work based on the Program is not required to print
an announcement.)
These requirements apply to the modified work as a whole. If identifiable
sections of that work are not derived from the Program, and can be
reasonably considered independent and separate works in themselves, then
this License, and its terms, do not apply to those sections when you distribute
them as separate works. But when you distribute the same sections as part
of a whole which is a work based on the Program, the distribution of the
whole must be on the terms of this License, whose permissions for other
licensees extend to the entire whole, and thus to each and every part
regardless of who wrote it.
Thus, it is not the intent of this section to claim rights or contest your rights to
work written entirely by you; rather, the intent is to exercise the right to
control the distribution of derivative or collective works based on the
Program.
In addition, mere aggregation of another work not based on the Program
with the Program (or with a work based on the Program) on a volume of a
storage or distribution medium does not bring the other work under the scope
of this License.
3. You may copy and distribute the Program (or a work based on it, under
Section 2) in object code or executable form under the terms of Sections 1
and 2 above provided that you also do one of the following:
a) Accompany it with the complete corresponding machine-readable source
code, which must be distributed under the terms of Sections 1 and 2 above
on a medium customarily used for software interchange; or,
b) Accompany it with a written offer, valid for at least three years, to give
any third party, for a charge no more than your cost of physically performing
source distribution, a complete machine-readable copy of the corresponding
source code, to be distributed under the terms of Sections 1 and 2 above on
a medium customarily used for software interchange; or,
c) Accompany it with the information you received as to the offer to distribute
corresponding source code. (This alternative is allowed only for
noncommercial distribution and only if you received the program in object
code or executable form with such an offer, in accord with Subsection b
above.)
The source code for a work means the preferred form of the work for
making modifications to it. For an executable work, complete source code
means all the source code for all modules it contains, plus any associated
interface definition files, plus the scripts used to control compilation and
installation of the executable. However, as a special exception, the source
code distributed need not include anything that is normally distributed (in
either source or binary form) with the major components (compiler, kernel,
and so on) of the operating system on which the executable runs, unless that
component itself accompanies the executable.
If distribution of executable or object code is made by offering access to
copy from a designated place, then offering equivalent access to copy the
source code from the same place counts as distribution of the source code,
even though third parties are not compelled to copy the source along with the
object code.
4. You may not copy, modify, sublicense, or distribute the Program except as
expressly provided under this License. Any attempt otherwise to copy,
modify, sublicense or distribute the Program is void, and will automatically
terminate your rights under this License. However, parties who have received
copies, or rights, from you under this License will not have their licenses
terminated so long as such parties remain in full compliance.
5. You are not required to accept this License, since you have not signed it.
However, nothing else grants you permission to modify or distribute the
Program or its derivative works. These actions are prohibited by law if you
do not accept this License. Therefore, by modifying or distributing the
Program (or any work based on the Program), you indicate your acceptance
of this License to do so, and all its terms and conditions for copying,
distributing or modifying the Program or works based on it.
6. Each time you redistribute the Program (or any work based on the
Program), the recipient automatically receives a license from the original
licensor to copy, distribute or modify the Program subject to these terms and
conditions. You may not impose any further restrictions on the recipients'
exercise of the rights granted herein. You are not responsible for enforcing
compliance by third parties to this License.
7. If, as a consequence of a court judgment or allegation of patent
infringement or for any other reason (not limited to patent issues), conditions
are imposed on you (whether by court order, agreement or otherwise) that
contradict the conditions of this License, they do not excuse you from the
conditions of this License. If you cannot distribute so as to satisfy
simultaneously your obligations under this License and any other pertinent
obligations, then as a consequence you may not distribute the Program at all.
For example, if a patent license would not permit royalty-free redistribution
of the Program by all those who receive copies directly or indirectly through
you, then the only way you could satisfy both it and this License would be to
refrain entirely from distribution of the Program.
If any portion of this section is held invalid or unenforceable under any
particular circumstance, the balance of the section is intended to apply and
the section as a whole is intended to apply in other circumstances.
It is not the purpose of this section to induce you to infringe any patents or
other property right claims or to contest validity of any such claims; this
section has the sole purpose of protecting the integrity of the free software
distribution system, which is implemented by public license practices. Many
people have made generous contributions to the wide range of software
distributed through that system in reliance on consistent application of that
system; it is up to the author/donor to decide if he or she is willing to
distribute software through any other system and a licensee cannot impose
that choice.
This section is intended to make thoroughly clear what is believed to be a
consequence of the rest of this License.
8. If the distribution and/or use of the Program is restricted in certain
countries either by patents or by copyrighted interfaces, the original copyright
holder who places the Program under this License may add an explicit
geographical distribution limitation excluding those countries, so that
distribution is permitted only in or among countries not thus excluded. In such
case, this License incorporates the limitation as if written in the body of this
License.
9. The Free Software Foundation may publish revised and/or new versions
of the General Public License from time to time. Such new versions will be
similar in spirit to the present version, but may differ in detail to address new
problems or concerns.
Each version is given a distinguishing version number. If the Program specifies
a version number of this License which applies to it and "any later version",
you have the option of following the terms and conditions either of that
version or of any later version published by the Free Software Foundation. If
the Program does not specify a version number of this License, you may
choose any version ever published by the Free Software Foundation.
10. If you wish to incorporate parts of the Program into other free programs
whose distribution conditions are different, write to the author to ask for
permission. For software which is copyrighted by the Free Software
Foundation, write to the Free Software Foundation; we sometimes make
exceptions for this. Our decision will be guided by the two goals of
preserving the free status of all derivatives of our free software and of
promoting the sharing and reuse of software generally.
NO WARRANTY
11. BECAUSE THE PROGRAM IS LICENSED FREE OF CHARGE,
THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT
PERMITTED BY APPLICABLE LAW. EXCEPT WHEN OTHERWISE
STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR
OTHER PARTIES PROVIDE THE PROGRAM "AS IS" WITHOUT
WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED,
INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND
PERFORMANCE OF THE PROGRAM IS WITH YOU. SHOULD THE
PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF ALL
NECESSARY SERVICING, REPAIR OR CORRECTION.
12. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR
AGREED TO IN WRITING WILL ANY COPYRIGHT HOLDER, OR
ANY OTHER PARTY WHO MAY MODIFY AND/OR
REDISTRIBUTE THE PROGRAM AS PERMITTED ABOVE, BE
LIABLE TO YOU FOR DAMAGES, INCLUDING ANY GENERAL,
SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES
ARISING OUT OF THE USE OR INABILITY TO USE THE
PROGRAM (INCLUDING BUT NOT LIMITED TO LOSS OF DATA
OR DATA BEING RENDERED INACCURATE OR LOSSES
SUSTAINED BY YOU OR THIRD PARTIES OR A FAILURE OF THE
PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS), EVEN
IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF
THE POSSIBILITY OF SUCH DAMAGES.
END OF TERMS AND CONDITIONS

View File

@ -0,0 +1,29 @@
// $Id: README.markdown,v 1.2 2010/10/19 15:01:29 agentken Exp $
# Style Guide Drupal Module [http://drupal.org/project/styleguide](http://drupal.org/project/styleguide)
The Style Guide module creates an API and preview page for displaying common
theme elements. Use it to preview items such as tables, menus, and lists in your
custom themes.
## Installing Style Guide:
* Place the entirety of this directory on a Drupal module path, under a
location like: sites/all/modules/ or sites/all/modules/contrib
* Navigate to the modules administration page and enable the module.
## Using Style Guide
* You must be logged in as a global admin user (uid=1), or the user you are
logged in with must have a "View theme style guides" permission.
* Navigate to: http://yourdomain.com/admin/appearance/styleguide and you will
see a style guide for the current default theme.
* Using the tabs at the top of the page, you can switch to viewing the style
guide in any other, available theme.
## Extending Style Guide
To change the list of items displayed by Style Guide, third-party modules
can implement following hooks:
* hook_styleguide()
* hook_styleguide_alter(&$items)

Binary file not shown.

After

Width:  |  Height:  |  Size: 33 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 20 KiB

View File

@ -0,0 +1,8 @@
/* $Id*/
#styleguide-header .item-list {
float: right;
margin: 0 0 1em 2em;
width: 20%;
font-family: helvetica, arial, sans-serif;
}

View File

@ -0,0 +1,104 @@
<?php
// $Id: styleguide.api.php,v 1.6 2010/10/23 20:58:17 agentken Exp $
/**
* 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' => styleguide_list(), 'type' => 'ul'),
'group' => t('Common'),
);
$items['text'] => array(
'title' => t('Text block'),
'content' => styleguide_paragraph(3),
'group' => t('Text'),
'description' => t('A block of three paragraphs'),
);
$items['h1'] = array(
'title' => t('Text block'),
'tag' => 'h1',
'content' => styleguide_word(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' => styleguide_paragraph(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.';
}
}

View File

@ -0,0 +1,50 @@
/* $Id: styleguide.css,v 1.5 2010/10/21 03:34:36 agentken Exp $ */
h2.styleguide {
font-family: helvetica, arial, sans-serif;
font-weight: bold;
font-size: 16px;
text-transform: uppercase;
color: #ccc;
margin: 2em 0 0.25em 0;
padding: 0;
}
div.styleguide {
border-top: 1px solid #ccc;
border-bottom: 1px solid #ccc;
padding: 0;
}
#styleguide-header {
border: 1px solid #ccc;
padding 0.25em;
background-color: #fafafa;
}
#styleguide-header .item-list {
float: left;
margin: 0 2em 1em 0;
width: 20%;
font-family: helvetica, arial, sans-serif;
}
#styleguide-header h3 {
font-family: helvetica, arial, sans-serif;
font-weight: bold;
font-size: 16px;
text-transform: uppercase;
color: #ccc;
}
#styleguide-header .break {
margin-bottom: 1em;
clear: both;
}
.styleguide-description {
font-family: helvetica, arial, sans-serif;
font-size: 12px;
color: #aaa;
margin: 0;
}

View File

@ -0,0 +1,14 @@
; $Id: styleguide.info,v 1.1 2010/10/05 22:40:02 agentken Exp $
name = Style guide
description = Generates a theme style guide for proofing common elements.
core = 7.x
files[] = styleguide.module
files[] = styleguide.styleguide.inc
; Information added by drupal.org packaging script on 2010-11-04
version = "7.x-1.0"
core = "7.x"
project = "styleguide"
datestamp = "1288894295"

View File

@ -0,0 +1,537 @@
<?php
// $Id: styleguide.module,v 1.12 2010/10/23 23:28:43 agentken Exp $
/**
* Implements hook_menu().
*/
function styleguide_menu() {
$default = variable_get('theme_default', 'bartik');
$items['admin/appearance/styleguide'] = array(
'title' => 'Style guide',
'page callback' => 'styleguide_page',
'weight' => 40,
'access arguments' => array('view style guides'),
'theme callback' => '_styleguide_page_theme',
'theme arguments' => array($default),
);
foreach (list_themes() as $theme) {
$is_default = $theme->name == $default;
$items['admin/appearance/styleguide/' . $theme->name] = array(
'title' => $theme->info['name'],
'page callback' => 'styleguide_page',
'page arguments' => array($theme->name),
'type' => $is_default ? MENU_DEFAULT_LOCAL_TASK : MENU_LOCAL_TASK,
'access callback' => 'styleguide_access_check',
'access arguments' => array($theme),
'weight' => $is_default ? -10 : 0,
'theme callback' => '_styleguide_page_theme',
'theme arguments' => array($theme->name),
);
}
return $items;
}
/**
* Theme callback for the styleguide pages.
*/
function _styleguide_page_theme($theme) {
return $theme;
}
/**
* Implements hook_theme().
*/
function styleguide_theme($existing, $type, $theme, $path) {
$themes = array(
'styleguide_header' => array(
'variables' => array('theme_info' => array()),
),
'styleguide_links' => array(
'variables' => array('items' => array()),
),
'styleguide_item' => array(
'variables' => array('key' => NULL, 'item' => array(), 'content' => NULL),
),
'styleguide_content' => array(
'variables' => array('content' => NULL),
),
);
foreach ($themes as $theme => $data) {
$themes[$theme]['file'] = 'styleguide.theme.inc';
}
return $themes;
}
/**
* Implements hook_permission().
*/
function styleguide_permission() {
$permissions = array(
'view style guides' => array(
'title' => t('View theme style guides'),
)
);
return $permissions;
}
/**
* Menu access callback.
*/
function styleguide_access_check($theme) {
if (!user_access('view style guides')) {
return FALSE;
}
if (drupal_theme_access($theme)) {
return TRUE;
}
return FALSE;
}
/**
* The styleguide page.
*/
function styleguide_page($theme = NULL) {
drupal_add_css(drupal_get_path('module', 'styleguide') . '/styleguide.css');
// 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];
// 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']);
}
// 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.
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'] . '>';
}
}
// Support a renderable array for content.
elseif (isset($item['content']) && is_array($item['content'])) {
$display = drupal_render($item['content']);
}
// Just print the provided 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));
}
$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;
}
/**
* Implements hook_hook_info().
*/
function styleguide_hook_info() {
$hooks['styleguide'] = array(
'group' => 'styleguide',
);
return $hooks;
}
/**
* Return a simple array of words.
*
* @param $size
* The size of the list to return.
* @return
* An array of words.
*/
function styleguide_list($size = 5) {
$items = array();
for ($i = 0; $i < $size; $i++) {
$items[] = styleguide_word();
}
return $items;
}
/**
* Return a random word.
*/
function styleguide_word($size = 1) {
return styleguide_lorem(1, $size, 'lower', FALSE, FALSE);
}
/**
* Return a random table header array.
*
* @param $size
* The size of the list to return.
* @return
* An array of header elements.
*/
function styleguide_header($size = 5) {
$header = styleguide_list($size);
return $header;
}
/**
* Return a random table row array.
*
* @param $size
* The size of the list to return.
* @return
* An array of row elements.
*/
function styleguide_rows($size = 5) {
$rows = array();
for ($i = 0; $i < $size; $i++) {
$rows[] = styleguide_list($size);
}
return $rows;
}
/**
* Lorum ipsum text, used to generate words and phrases.
*
* @param $size
* The size of the list to return.
* @param $words
* The number of words to return. Pass 0 for a whole paragraph.
* @param $case
* The case of the text. Options are 'mixed', 'upper' and 'lower'.
* @param $returns
* Indicates whether line returns should not be stripped out of the result.
* @param $punctuation
* Indicates whether punctuation should not be stripped out of the result.
* @param $array
* Indicates that the return value should be an array instead of a string.
* @return
* A string or array of content.
*/
function styleguide_lorem($size = 5, $words = 0, $case = 'mixed', $returns = TRUE, $punctuation = TRUE, $array = FALSE) {
$text = <<<EOT
Lorem ipsum dolor sit amet, consectetur adipiscing elit. Aliquam iaculis, velit gravida convallis tincidunt, felis enim venenatis lorem, nec lobortis nisl urna et mi. Pellentesque ac dictum ante. Fusce dignissim tempor elementum. Ut dignissim convallis eros, viverra luctus lacus consequat ac. Sed feugiat velit sed magna aliquam accumsan. Nam vitae porta tortor. Nam auctor dui a neque iaculis in aliquam erat viverra. Duis orci nunc, lacinia in malesuada et, euismod id turpis. Cras mattis vulputate erat, eget tempor magna egestas eu. Vestibulum sit amet massa est.
Vivamus pretium placerat lorem, in tempor massa convallis sit amet. Aliquam sed quam eget ligula luctus aliquam sed vitae nulla. Aliquam dui dolor, ullamcorper eget rutrum ut, hendrerit ac lorem. Donec magna est, sollicitudin vel ultrices vel, mattis ut odio. Integer vel felis laoreet purus sollicitudin varius sed id ipsum. Suspendisse potenti. Praesent ut justo vitae metus luctus vehicula a et purus. Suspendisse potenti. Sed viverra, quam non hendrerit laoreet, massa odio blandit arcu, ac molestie metus diam eu tortor. Donec erat arcu, ultrices sit amet placerat non, feugiat in arcu. Mauris eros quam, varius eget volutpat vel, tristique sed est. In faucibus feugiat urna sit amet elementum. Integer consequat rhoncus libero, in molestie augue posuere et. Phasellus ac eleifend magna. Proin vulputate dui ac justo pharetra consequat. In vel iaculis ligula.
Cras vestibulum lacus sit amet sem commodo ullamcorper aliquet eros vestibulum. Sed fermentum nulla quis risus suscipit dapibus. Sed vitae velit ut dolor varius semper at id lectus. Aenean quis leo sit amet tellus tempus cursus. Vivamus semper vehicula ante eget semper. In ac ipsum erat. Suspendisse lectus erat, commodo nec fringilla quis, interdum non leo. Vivamus et lectus vitae risus porta sollicitudin luctus eget est. Etiam quis elit vel est suscipit tristique. Nullam fringilla purus ac velit gravida ullamcorper. Praesent porttitor ante non lacus suscipit porta. Nunc fermentum sem et metus aliquam ultricies non sollicitudin nibh. Vestibulum ut ligula dolor, in placerat tortor. Sed nec lacus sed nibh iaculis luctus. Pellentesque habitant morbi tristique senectus et netus et malesuada fames ac turpis egestas. Curabitur rutrum, diam vel tempor commodo, augue nunc viverra risus, in pellentesque neque justo eget dolor. Maecenas quis odio leo, a auctor lorem.
Curabitur dapibus odio quis enim hendrerit eu placerat lorem accumsan. Phasellus sagittis, orci vel laoreet molestie, urna orci imperdiet elit, quis ultricies orci mauris vel ante. Cras pharetra, nisl a sagittis feugiat, turpis magna placerat sem, sed euismod erat elit in magna. Phasellus blandit ullamcorper diam vel porta. Vivamus mollis, metus nec tincidunt venenatis, risus odio sodales risus, vitae ultrices est nisi eget ante. Aenean eget nisi mi. Nulla non nulla nec metus rhoncus congue. Curabitur quis nunc nibh. Cras metus lorem, euismod ornare mattis sagittis, ultrices eget turpis. Integer quis dui tellus. Morbi vel dolor sit amet metus eleifend fringilla. Fusce nunc neque, ultricies et commodo semper, dignissim vitae tortor. Phasellus et ipsum quis sapien accumsan auctor. Morbi congue nulla vel tortor aliquet imperdiet. Morbi eget odio elit, et cursus odio. Quisque a velit diam. Duis urna libero, tempus non mattis a, convallis ac erat. Etiam vel dui posuere lectus auctor viverra vitae id eros. Maecenas mollis eros non elit sollicitudin quis fermentum diam lacinia. Quisque at ante nibh, a molestie ligula.
Sed et enim nunc, nec vehicula sem. Sed risus orci, auctor et dictum at, hendrerit eu augue. Curabitur sed ante non quam fermentum vehicula. Lorem ipsum dolor sit amet, consectetur adipiscing elit. Nam tincidunt dictum molestie. Vestibulum ante ipsum primis in faucibus orci luctus et ultrices posuere cubilia Curae; Phasellus nec urna ut lorem tempus aliquet eget nec lectus. Phasellus quis venenatis tortor. Integer elementum, sapien at feugiat cursus, tortor sapien adipiscing massa, non molestie elit lacus vel velit. Suspendisse sit amet sem id libero auctor pharetra sit amet ut dui. Aenean sit amet tellus sit amet ante congue faucibus. Nullam hendrerit, justo et iaculis tristique, ligula risus pretium erat, sed tempus lacus felis ut nulla.
EOT;
if (!$punctuation) {
$text = str_replace(array(',', '.'), '', $text);
}
switch ($case) {
case 'mixed':
break;
case 'upper':
$text = strtoupper($text);
break;
case 'lower':
$text = strtolower($text);
break;
}
$graphs = explode("\n\n", $text);
$text = array_slice($graphs, 0, $size);
$spacer = ' ';
if ($returns) {
$spacer = "\n\n";
}
if ($words > 0) {
$elements = explode(' ', implode(' ', $text));
$output = array();
for ($i = 0; $i < $words; $i++) {
$val = array_rand($elements);
$output[] = $elements[$val];
}
return implode(' ', $output);
}
if (!$array) {
return implode($spacer, $text);
}
return $text;
}
/**
* Generate paragraph(s) of random text.
*
* @param $size
* The number of paragraphs to return.
* @return
* HTML paragraphs.
*/
function styleguide_paragraph($size = 5) {
$text = styleguide_lorem($size, 0, 'mixed', TRUE, TRUE, TRUE);
$output = '';
foreach ($text as $item) {
$output .= '<p>' . trim($item) . '</p>';
}
return $output;
}
/**
* Provide a default image for display.
*
* Images should be in the assets directory. The current images are
* (c) Ken Rickard and used by permission.
*
* @param $image
* The name of the image. Will be prefixed with 'image-'.
* @param $type
* The file type, (jpg, png, gif). Do not include a dot.
* @return
* The Drupal path to the file.
*/
function styleguide_image($image = 'vertical', $type = 'jpg') {
$path = drupal_get_path('module', 'styleguide');
$filepath = $path . '/assets/image-' . $image . '.' . $type;
if (file_exists($filepath)) {
return $filepath;
}
}
/**
* Implements hook_system_theme_page_alter().
*/
function styleguide_system_themes_page_alter(&$theme_groups) {
if (!user_access('view style guides')) {
return;
}
foreach ($theme_groups as $group => $members) {
if (empty($group)) {
continue;
}
foreach ($members as $key => $theme) {
if (!styleguide_access_check($theme)) {
continue;
}
$theme_groups[$group][$key]->operations[] = array(
'title' => t('Style guide'),
'href' => 'admin/appearance/styleguide/' . $theme->name,
'attributes' => array('title' => t('Style guide for @theme', array('@theme' => $theme->info['name']))),
);
}
}
}
/**
* Generate a random sentence.
*/
function styleguide_sentence() {
$graph = strip_tags(styleguide_paragraph());
$explode = explode('.', $graph);
$rand = array_rand($explode);
return trim($explode[$rand]) . '.';
}
/**
* Sample form, showing all elements.
*/
function styleguide_form($form, &$form_state, $form_keys = array()) {
$form = array();
$options = array();
$list = styleguide_list();
foreach ($list as $item) {
$options[$item] = $item;
}
$form['select'] = array(
'#type' => 'select',
'#title' => t('Select'),
'#options' => $options,
'#description' => styleguide_sentence(),
);
$form['checkbox'] = array(
'#type' => 'checkbox',
'#title' => t('Checkbox'),
'#value' => 1,
'#default_value' => 1,
'#description' => styleguide_sentence(),
);
$form['checkboxes'] = array(
'#type' => 'checkboxes',
'#title' => t('Checkboxes'),
'#options' => $options,
'#description' => styleguide_sentence(),
);
$form['radios'] = array(
'#type' => 'radios',
'#title' => t('Radios'),
'#options' => $options,
'#description' => styleguide_sentence(),
);
$form['textfield'] = array(
'#type' => 'textfield',
'#title' => t('Textfield'),
'#default_value' => styleguide_word(),
'#description' => styleguide_sentence(),
);
$form['autocomplete'] = array(
'#type' => 'textfield',
'#title' => t('Autocomplete textfield'),
'#default_value' => styleguide_word(),
'#description' => styleguide_sentence(),
'#autocomplete_path' => 'user/autocomplete',
);
$form['textfield-machine'] = array(
'#type' => 'textfield',
'#title' => t('Textfield, with machine name'),
'#default_value' => styleguide_word() . ' ' . styleguide_word() . ' ' . styleguide_word(),
'#description' => styleguide_sentence(),
);
$form['machine_name'] = array(
'#type' => 'machine_name',
'#title' => t('Machine name'),
'#machine_name' => array(
'source' => array('textfield-machine'),
),
'#description' => styleguide_sentence(),
);
$form['textarea'] = array(
'#type' => 'textarea',
'#title' => t('Textarea'),
'#default_value' => styleguide_paragraph(),
'#description' => styleguide_sentence(),
);
$form['date'] = array(
'#type' => 'date',
'#title' => t('Date'),
'#description' => styleguide_sentence(),
);
$form['file'] = array(
'#type' => 'file',
'#title' => t('File'),
'#description' => styleguide_sentence(),
);
$form['managed_file'] = array(
'#type' => 'managed_file',
'#title' => t('Managed file'),
'#description' => styleguide_sentence(),
);
$form['password'] = array(
'#type' => 'password',
'#title' => t('Password'),
'#default_value' => styleguide_word(),
'#description' => styleguide_sentence(),
);
$form['password_confirm'] = array(
'#type' => 'password_confirm',
'#title' => t('Password confirm'),
);
$form['weight'] = array(
'#type' => 'weight',
'#title' => t('Weight'),
'#delta' => 10,
'#description' => styleguide_sentence(),
);
$form['fieldset-collapsed'] = array(
'#type' => 'fieldset',
'#title' => t('Fieldset collapsed'),
'#collapsible' => TRUE,
'#collapsed' => TRUE,
'#description' => styleguide_sentence(),
);
$form['fieldset-collapsible'] = array(
'#type' => 'fieldset',
'#title' => t('Fieldset collapsible'),
'#collapsible' => TRUE,
'#description' => styleguide_sentence(),
);
$form['fieldset'] = array(
'#type' => 'fieldset',
'#title' => t('Fieldset'),
'#collapsible' => FALSE,
'#description' => styleguide_sentence(),
);
$fieldsets = array('fieldset', 'fieldset-collapsed', 'fieldset-collapsible');
$count = 0;
foreach ($form as $key => $value) {
if ($value['#type'] != 'fieldset' && $value['#type'] != 'checkbox' && $count < 2) {
$count++;
foreach ($fieldsets as $item) {
$form[$item][$key . '-' . $item] = $value;
}
}
}
$form['vertical_tabs'] = array(
'#type' => 'vertical_tabs',
);
foreach ($fieldsets as $fieldset) {
$form['vertical_tabs'][$fieldset] = $form[$fieldset];
}
$form['markup'] = array(
'#markup' => t('<p><em>Markup</em>: Note that markup does not allow titles or descriptions. Use "item" for those options.</p>') . styleguide_paragraph(1),
);
$form['item'] = array(
'#type' => 'item',
'#title' => t('Item'),
'#markup' => styleguide_paragraph(1),
'#description' => styleguide_sentence(),
);
$form['image_button'] = array(
'#type' => 'image_button',
'#src' => 'misc/druplicon.png',
'#attributes' => array('height' => 20),
'#name' => t('Image button'),
);
$form['submit'] = array(
'#type' => 'submit',
'#value' => t('Submit'),
);
$form['button'] = array(
'#type' => 'button',
'#value' => t('Button'),
);
if (!empty($form_keys)) {
$items = array();
foreach ($form_keys as $key) {
if (isset($form[$key])) {
$items[$key] = $form[$key];
}
}
return $items;
}
return $form;
}

View File

@ -0,0 +1,169 @@
<?php
// $Id: styleguide.styleguide.inc,v 1.7 2010/10/22 20:59:56 agentken Exp $
/**
* Implements hook_styleguide().
*/
function styleguide_styleguide() {
$items['a'] = array(
'title' => t('Link'),
'content' => ucfirst(styleguide_word(3)) . ' ' . l(styleguide_word(3), 'node') . ' ' . styleguide_word(4) . '.',
);
$items['em'] = array(
'title' => t('Emphasis'),
'content' => ucfirst(styleguide_word(3)) . ' <em>' . styleguide_word(3) . '</em> ' . styleguide_word(4) . '.',
);
$items['strong'] = array(
'title' => t('Strong'),
'content' => ucfirst(styleguide_word(3)) . ' <strong>' . styleguide_word(3) . '</strong> ' . styleguide_word(4) . '.',
);
$items['ul'] = array(
'title' => t('Unordered list'),
'theme' => 'item_list',
'variables' => array('items' => styleguide_list(), 'type' => 'ul'),
'group' => t('Lists'),
);
$items['ol'] = array(
'title' => t('Ordered list'),
'theme' => 'item_list',
'variables' => array('items' => styleguide_list(), 'type' => 'ol'),
'group' => t('Lists'),
);
$items['ul_title'] = array(
'title' => t('Unordered list, with title'),
'theme' => 'item_list',
'variables' => array('items' => styleguide_list(), 'type' => 'ul', 'title' => ucwords(styleguide_word())),
'group' => t('Lists'),
);
$items['ol_title'] = array(
'title' => t('Ordered list, with title'),
'theme' => 'item_list',
'variables' => array('items' => styleguide_list(), 'type' => 'ol', 'title' => ucwords(styleguide_word())),
'group' => t('Lists'),
);
$items['menu_tree'] = array(
'title' => t('Menu tree'),
'content' => menu_tree('management'),
'group' => t('Menus'),
);
$items['table'] = array(
'title' => t('Table'),
'theme' => 'table',
'variables' => array('header' => styleguide_header(), 'rows' => styleguide_rows()),
'group' => t('Tables'),
);
$items['text'] = array(
'title' => t('Text block'),
'content' => styleguide_paragraph(3),
'group' => t('Text'),
);
$items['image-horizontal'] = array(
'title' => t('Image, horizontal'),
'theme' => 'image',
'variables' => array('path' => styleguide_image('horizontal'), 'alt' => t('My image'), 'title' => t('My image')),
'group' => t('Media'),
);
$items['image-vertical'] = array(
'title' => t('Image, vertical'),
'theme' => 'image',
'variables' => array('path' => styleguide_image('vertical'), 'alt' => t('My image'), 'title' => t('My image')),
'group' => t('Media'),
);
$items['image-inset-horizontal'] = array(
'title' => t('Image, horizontal, within text'),
'content' => styleguide_paragraph(1) . theme('image', array('path' => styleguide_image('horizontal'), 'alt' => t('My image'), 'title' => t('My image'))) . styleguide_paragraph(2),
'group' => t('Media'),
);
$items['image-inset-vertical'] = array(
'title' => t('Image, vertical, within text'),
'content' => styleguide_paragraph(1) . theme('image', array('path' => styleguide_image('vertical'), 'alt' => t('My image'), 'title' => t('My image'))) . styleguide_paragraph(2),
'group' => t('Media'),
);
$content = '';
for ($i = 1; $i <=6; $i++) {
$content .= "<h$i>" . "h$i: " . implode(' ', styleguide_list()) . "</h$i>";
}
$items['headings'] = array(
'title' => "Headings",
'content' => $content,
'group' => t('Text'),
);
$content = '';
for ($i = 1; $i <=6; $i++) {
$content .= "<h$i>" . "h$i: " . implode(' ', styleguide_list()) . "</h$i>" . styleguide_paragraph(1);
}
$items['headings_text'] = array(
'title' => "Headings with text",
'content' => $content,
'group' => t('Text'),
);
$messages = array('status', 'warning', 'error');
foreach ($messages as $message) {
$items[$message . '-message'] = array(
'title' => ucwords($message) . ' message',
'content' => '<div class="messages ' . $message . '"><h2 class="element-invisible">Status message</h2>' . styleguide_sentence() . '</div>',
);
}
// Form elements.
$fake = $form_state = array();
$elements = styleguide_form($fake, $form_state);
$basic = array();
$fieldsets = array();
$tabs = array();
$markup = array();
foreach (element_children($elements) as $key) {
if (!isset($elements[$key]['#type']) || $elements[$key]['#type'] == 'item') {
$markup[] = $key;
}
elseif ($elements[$key]['#type'] == 'fieldset') {
$fieldsets[] = $key;
}
elseif ($key == 'vertical_tabs') {
$tabs[] = $key;
}
// We skip these.
elseif (in_array($elements[$key]['#type'], array('button', 'submit', 'image_button'))) {
$buttons[] = $key;
}
else {
$basic[] = $key;
}
}
$items['form'] = array(
'title' => t('Forms, basic'),
'content' => drupal_get_form('styleguide_form', $basic),
'group' => t('Forms'),
);
$items['form-submit'] = array(
'title' => t('Forms, submit'),
'content' => drupal_get_form('styleguide_form', array('submit')),
'group' => t('Forms'),
);
$items['form-button'] = array(
'title' => t('Forms, button'),
'content' => drupal_get_form('styleguide_form', array('button')),
'group' => t('Forms'),
);
$items['form-image-button'] = array(
'title' => t('Forms, image button'),
'content' => drupal_get_form('styleguide_form', array('image_button')),
'group' => t('Forms'),
);
$items['form-markup'] = array(
'title' => t('Forms, markup'),
'content' => drupal_get_form('styleguide_form', $markup),
'group' => t('Forms'),
);
$items['form-fieldsets'] = array(
'title' => t('Forms, fieldsets'),
'content' => drupal_get_form('styleguide_form', $fieldsets),
'group' => t('Forms'),
);
$items['form-vertical-tabs'] = array(
'title' => t('Forms, vertical tabs'),
'content' => drupal_get_form('styleguide_form', $tabs),
'group' => t('Forms'),
);
return $items;
}

View File

@ -0,0 +1,90 @@
<?php
// $Id: styleguide.theme.inc,v 1.1 2010/10/23 20:58:17 agentken Exp $
/**
* @file
* Theme file for Style Guide module.
*/
/**
* Theme the page header.
*
* @param $variables
* The theme variables array, including:
* -- 'theme_info' an array of information about the current theme.
*/
function theme_styleguide_header($variables) {
$theme_info = $variables['theme_info'];
$output = '<h2>' . t('Showing style guide for %theme', array('%theme' => $theme_info['name'])) . '</h2>';
if (isset($theme_info['description'])) {
$output .= '<p>' . $theme_info['description'] . '</p>';
}
$output .= '<h2 class="styleguide">'. t('Styleguide element entries') .'</h2>';
$output .= '<p class="styleguide-description">' . t('Optional item description.') . '</p>';
$output .= '<div class="styleguide">';
$output .= t('The header area indicates the style element being displayed. The horizontal rules indicate the top and bottom baselines of the rendered element.');
$output .= '</div>';
$output .= '<div class="break"><br /></div>';
return $output;
}
/**
* Theme a display item.
*
* @param $variables
* The theme variables array, including:
* -- 'key' a unique string indicating the name of the item.
* -- 'item' an array of data about the item.
* -- 'content' the content to display for this item.
*
* @see hook_styleguide()
*/
function theme_styleguide_item($variables) {
$key = $variables['key'];
$item = $variables['item'];
$content = $variables['content'];
$output = '';
$output .= "<a name=\"$key\"></a>";
$output .= '<h2 class="styleguide">'. $item['title'] .'</h2>';
if (!empty($item['description'])) {
$output .= '<p class="styleguide-description">';
$output .= $item['description'];
$output .= '</p>';
}
$output .= '<div class="styleguide">';
$output .= $content;
$output .= '</div>';
return $output;
}
/**
* Theme the page links.
*
* NOTE: these may be turned into sub-tabs.
*
* @param $variables
* The theme variables array, including:
* -- 'items' the list of links.
*/
function theme_styleguide_links($variables) {
// Close the header.
$output = '<div id="styleguide-header">';
$output .= $variables['items'];
$output .= '<div class="break"><br /></div>';
$output .= '</div>';
return $output;
}
/**
* Theme the content.
*
* This function is here in case anyone wants to change it.
*
* @param $variables
* The theme variables array, including:
* -- 'content' an HTML content element.
*/
function theme_styleguide_content($variables) {
return $variables['content'];
}