Permalink
Browse files

feature(views): allow multiple paths in views.php files

  • Loading branch information...
mrclay committed Apr 6, 2016
1 parent d59f7ae commit 7672d7542f322322b5a4868a8af4e61e8a9a702b
Showing with 37 additions and 17 deletions.
  1. +14 −0 docs/guides/views.rst
  2. +18 −12 engine/classes/Elgg/ViewsService.php
  3. +1 −1 engine/tests/phpunit/Elgg/ViewsServiceTest.php
  4. +4 −4 engine/views.php
@@ -206,6 +206,20 @@ With the above, files found within the ``icons`` folder will be interpreted as v

This is a fully recursive scan. All files found will be brought into the views system.

Multiple paths can share the same prefix, just give an array of paths:

.. code-block:: php
<?php // mod/file/views.php
return [
'default' => [
'file/icon/' => [
__DIR__ . '/graphics/icons',
__DIR__ . '/more_icons', // processed 2nd (may override)
],
],
];
Viewtypes
=========

@@ -570,26 +570,32 @@ public function registerPluginViews($path, &$failed_dir = '') {
*
* @param array $spec Specification
* viewtype => [
* view_name => path
* view_name => path or array of paths
* ]
*
* @access private
*/
public function mergeViewsSpec(array $spec) {
foreach ($spec as $viewtype => $list) {
foreach ($list as $view => $path) {
if (preg_match('~^([/\\\\]|[a-zA-Z]\:)~', $path)) {
// absolute path
} else {
// relative path
$path = Directory\Local::root()->getPath($path);
foreach ($list as $view => $paths) {
if (!is_array($paths)) {
$paths = [$paths];
}
if (substr($view, -1) === '/') {
// prefix
$this->autoregisterViews($view, $path, $viewtype);
} else {
$this->setViewLocation($view, $viewtype, $path);
foreach ($paths as $path) {
if (preg_match('~^([/\\\\]|[a-zA-Z]\:)~', $path)) {
// absolute path
} else {
// relative path
$path = Directory\Local::root()->getPath($path);
}
if (substr($view, -1) === '/') {
// prefix
$this->autoregisterViews($view, $path, $viewtype);
} else {
$this->setViewLocation($view, $viewtype, $path);
}
}
}
}
@@ -67,7 +67,7 @@ public function testCanSetViewPathsViaSpec() {
$this->views->mergeViewsSpec([
'default' => [
'hello.js' => __DIR__ . '/../test_files/views/default/js/static.js',
'hello/world.js' => 'engine/tests/phpunit/test_files/views/default/js/interpreted.js.php',
'hello/world.js' => ['engine/tests/phpunit/test_files/views/default/js/interpreted.js.php'],
],
]);
@@ -26,7 +26,10 @@
/**
* __DIR__ should be utilized when referring to assets that are checked in to version control.
*/
"/" => dirname(__DIR__) . "/_graphics",
"/" => [
dirname(__DIR__) . "/_graphics",
dirname(__DIR__) . "/views/default/lightbox/elgg-colorbox-theme",
],
"elgg/ui.avatar_cropper.js" => dirname(__DIR__) . "/js/lib/ui.avatar_cropper.js",
"elgg/ui.friends_picker.js" => dirname(__DIR__) . "/js/lib/ui.friends_picker.js",
@@ -42,8 +45,5 @@
"jquery.jeditable.js" => dirname(__DIR__) . "/bower_components/jquery-jeditable/jquery.jeditable.js",
"jquery.ui.autocomplete.html.js" => dirname(__DIR__) . "/bower_components/jquery-ui-extensions/src/autocomplete/jquery.ui.autocomplete.html.js",
"sprintf.js" => dirname(__DIR__) . "/bower_components/sprintf/src/sprintf.js",
'colorbox.css' => dirname(__DIR__) . "/views/default/lightbox/elgg-colorbox-theme/colorbox.css",
'colorbox-images/' => dirname(__DIR__) . "/views/default/lightbox/elgg-colorbox-theme/colorbox-images",
],
];

0 comments on commit 7672d75

Please sign in to comment.