Browse files

Patterns available components are displayed in the INFO page

  • Loading branch information...
1 parent 0bf9a09 commit 02f369d918aabd849ebabf525dea10b849a3ecb5 @shakty committed Apr 13, 2012
Showing with 68 additions and 14 deletions.
  1. +30 −3 includes/components.inc
  2. +7 −7 includes/forms/info.inc
  3. +7 −3 includes/io.inc
  4. +0 −1 includes/utils.inc
  5. +2 −0 patterns.module
  6. +22 −0 theme/common.inc
View
33 includes/components.inc
@@ -5,8 +5,35 @@
*
*/
+/**
+ * Returns a list of uris to components files.
+ *
+ * Wrapper method for patterns_io_load_components($reset, TRUE);
+ *
+ * @param bool $reset (optional) If TRUE, always forces reloading
+ * the components from the file system. Defaults FALSE
+ *
+ * @see patterns_io_load_components
+ */
function patterns_components_list($reset = FALSE) {
- $components = patterns_io_load_components($reset);
-
- return $components;
+ return patterns_io_load_components($reset, TRUE);
+}
+
+/**
+ * Returns a list of all the directories containing
+ * Patterns components.
+ *
+ * @param bool $reset (optional) If TRUE, forces to
+ * reload the directory index.
+ */
+function patterns_components_dirs($reset = FALSE) {
+ $components_dirs = &drupal_static(__FUNCTION__);
+
+ if (isset($components_dirs) && !$reset) {
+ return $components_dirs;
+ }
+
+ // Get list of directories to scan for components.
+ return module_invoke_all('patterns_components');
}
+
View
14 includes/forms/info.inc
@@ -23,10 +23,7 @@ function patterns_info_page() {
function patterns_info_directories($form = array()) {
$dirs = patterns_path_get_patterns_dirs();
-
- foreach ($dirs as $key => $value) {
- $dirs[$key] = array(($key+1), $value);
- }
+ $dirs = patterns_array_to_rows($dirs);
$form['pd'] = array(
'#type' => 'fieldset',
@@ -44,15 +41,18 @@ function patterns_info_directories($form = array()) {
function patterns_info_components($form = array()) {
+ $components = patterns_components_list();
+ $components = patterns_array_to_rows($components);
+
$form['cd'] = array(
'#type' => 'fieldset',
- '#title' => t('Patterns Components Directories'),
+ '#title' => t('Patterns Components'),
'#collapsible' => TRUE,
'#collapsed' => FALSE,
);
- $form['cd']['dirs'] = array(
- '#markup' => 'TODO',
+ $form['cd']['components'] = array(
+ '#markup' => theme('table', array('rows' => $components, 'attributes' => array('class' => 'patterns-list'))),
);
return $form;
View
10 includes/io.inc
@@ -37,11 +37,14 @@ function patterns_io_get_pattern_service($pattern) {
*
* @param bool $reset (optional) If TRUE, always forces reloading
* the components from the file system. Defaults FALSE
- *
+ * @param bool $dryrun (optional) If TRUE, it does not actually load
+ * the components, but just returns the paths to each of them.
+ * Defaults FALSE
+ *
* @return Array $components Array containing the paths of the
* components files.
*/
-function patterns_io_load_components($reset = FALSE) {
+function patterns_io_load_components($reset = FALSE, $dryrun = FALSE) {
$components = &drupal_static(__FUNCTION__);
if (isset($paths) && !$reset) {
@@ -55,8 +58,9 @@ function patterns_io_load_components($reset = FALSE) {
foreach ($paths as $path) {
foreach (file_scan_directory($path, '/\.inc$/') as $file) {
- require_once $file->uri;
$components[] = $file->uri;
+ if ($dryrun) continue;
+ require_once $file->uri;
}
}
View
1 includes/utils.inc
@@ -211,4 +211,3 @@ function patterns_utils_is_public_page() {
}
return (request_path() == $p) ? TRUE : FALSE;
}
-
View
2 patterns.module
@@ -61,6 +61,8 @@ module_load_include('inc', 'patterns', 'includes/forms/forms');
module_load_include('inc', 'patterns', 'includes/parser/parser');
module_load_include('inc', 'patterns', 'includes/io');
+module_load_include('inc', 'patterns', 'includes/components');
+
module_load_include('inc', 'patterns', 'includes/api/api');
module_load_include('inc', 'patterns', 'includes/api/drush');
View
22 theme/common.inc
@@ -109,3 +109,25 @@ function patterns_get_patterns_links($pattern = NULL, $options = NULL) {
return $actions;
}
+
+/**
+ * Helper function to transform an array of items, into an array
+ * of of arrays of items, so that the returned value can be themed
+ * with theme_table.
+ *
+ * @param array $array An array of items
+ * @param mixed $empty (optional) A string that will be added in case
+ * the array is empty. Defaults 'No item found'
+ *
+ * @return array $array The transformed array
+ */
+function patterns_array_to_rows($array, $empty = 'No item found') {
+ if (empty($array)) {
+ return array(0 => array($empty));
+ }
+
+ foreach ($array as $key => $value) {
+ $array[$key] = array(($key+1), $value);
+ }
+ return $array;
+}

0 comments on commit 02f369d

Please sign in to comment.