diff --git a/CHANGELOG.md b/CHANGELOG.md index 040f40208..67d03f96a 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,27 @@ +# v0.9.20 +## 02/XX/2015 + +1. [](#new) + * Added `addAsyncJs()` and `addDeferJs()` to Assets manager +2. [](#improved) + * +3. [](#bugfix) + * + +# v0.9.19 +## 02/28/2015 + +1. [](#new) + * Added named assets capability and bundled jQuery into Grav core + * Added `first()` and `last()` to `Iterator` class +2. [](#improved) + * Improved page modification routine to skip _dot files_ + * Only use files to calculate page modification dates + * Broke out Folder iterators into their own classes + * Various Sensiolabs Insight fixes +3. [](#bugfix) + * Fixed `Iterator.nth()` method + # v0.9.18 ## 02/19/2015 @@ -11,7 +35,7 @@ * Added new `processTemplate()` method to Twig object for on-the-fly processing of twig template * Added `rcopy()` and `contains()` helper methods in Utils 2. [](#improved) - * Provied new `param_sep` variable to better support Apache on Windows + * Provided new `param_sep` variable to better support Apache on Windows * Moved parsedown configuration into the trait * Added optional **deep-copy** option to `mergeConfig()` for plugins * Updated bundled `composer.phar` package diff --git a/system/defines.php b/system/defines.php index 867cbfa4e..13aca8638 100644 --- a/system/defines.php +++ b/system/defines.php @@ -2,7 +2,7 @@ // Some standard defines define('GRAV', true); -define('GRAV_VERSION', '0.9.18'); +define('GRAV_VERSION', '0.9.19'); define('DS', '/'); // Directories and Paths diff --git a/system/src/Grav/Common/Assets.php b/system/src/Grav/Common/Assets.php index 70bc73dde..57830fb95 100644 --- a/system/src/Grav/Common/Assets.php +++ b/system/src/Grav/Common/Assets.php @@ -265,10 +265,11 @@ class Assets * @param mixed $asset * @param int $priority the priority, bigger comes first * @param bool $pipeline false if this should not be pipelined + * @param string $loading how the asset is loaded (async/defer) * * @return $this */ - public function addJs($asset, $priority = 10, $pipeline = true) + public function addJs($asset, $priority = 10, $pipeline = true, $loading = '') { if (is_array($asset)) { foreach ($asset as $a) { @@ -290,13 +291,42 @@ class Assets 'asset' => $asset, 'priority' => $priority, 'order' => count($this->js), - 'pipeline' => $pipeline + 'pipeline' => $pipeline, + 'loading' => $loading ]; } return $this; } + /** + * Convenience wrapper for async loading of JavaScript + * + * @param $asset + * @param int $priority + * @param bool $pipeline + * + * @return \Grav\Common\Assets + */ + public function addAsyncJs($asset, $priority = 10, $pipeline = true) + { + return $this->addJs($asset, $priority, $pipeline, 'async'); + } + + /** + * Convenience wrapper for deferred loading of JavaScript + * + * @param $asset + * @param int $priority + * @param bool $pipeline + * + * @return \Grav\Common\Assets + */ + public function addDeferJs($asset, $priority = 10, $pipeline = true) + { + return $this->addJs($asset, $priority, $pipeline, 'defer'); + } + /** * Add an inline CSS asset. * @@ -450,11 +480,11 @@ class Assets if ($this->js_pipeline) { $output .= '' . "\n"; foreach ($this->js_no_pipeline as $file) { - $output .= '' . "\n"; + $output .= '' . "\n"; } } else { foreach ($this->js as $file) { - $output .= '' . "\n"; + $output .= '' . "\n"; } } diff --git a/system/src/Grav/Common/Data/Blueprint.php b/system/src/Grav/Common/Data/Blueprint.php index 9c4925105..19448bc58 100644 --- a/system/src/Grav/Common/Data/Blueprint.php +++ b/system/src/Grav/Common/Data/Blueprint.php @@ -11,7 +11,7 @@ use RocketTheme\Toolbox\ArrayTraits\Export; */ class Blueprint { - use Export; + use Export, DataMutatorTrait; public $name; @@ -46,68 +46,6 @@ class Blueprint $this->filter = array_flip($filter); } - /** - * Get value by using dot notation for nested arrays/objects. - * - * @example $value = $data->get('this.is.my.nested.variable'); - * - * @param string $name Dot separated path to the requested value. - * @param mixed $default Default value (or null). - * @param string $separator Separator, defaults to '.' - * - * @return mixed Value. - */ - public function get($name, $default = null, $separator = '.') - { - $path = explode($separator, $name); - $current = $this->items; - foreach ($path as $field) { - if (is_object($current) && isset($current->{$field})) { - $current = $current->{$field}; - } elseif (is_array($current) && isset($current[$field])) { - $current = $current[$field]; - } else { - return $default; - } - } - - return $current; - } - - /** - * Sey value by using dot notation for nested arrays/objects. - * - * @example $value = $data->set('this.is.my.nested.variable', true); - * - * @param string $name Dot separated path to the requested value. - * @param mixed $value New value. - * @param string $separator Separator, defaults to '.' - */ - public function set($name, $value, $separator = '.') - { - $path = explode($separator, $name); - $current = &$this->items; - foreach ($path as $field) { - if (is_object($current)) { - // Handle objects. - if (!isset($current->{$field})) { - $current->{$field} = array(); - } - $current = &$current->{$field}; - } else { - // Handle arrays and scalars. - if (!is_array($current)) { - $current = array($field => array()); - } elseif (!isset($current[$field])) { - $current[$field] = array(); - } - $current = &$current[$field]; - } - } - - $current = $value; - } - /** * Return all form fields. * @@ -146,10 +84,9 @@ class Blueprint * * @param array $data1 * @param array $data2 - * @param string $name * @return array */ - public function mergeData(array $data1, array $data2, $name = null) + public function mergeData(array $data1, array $data2) { // Initialize data $this->fields(); @@ -213,7 +150,7 @@ class Blueprint $bref = array_merge($bref, array($key => $head[$key])); } } - } while(count($head_stack)); + } while (count($head_stack)); $this->items = $blueprints; } diff --git a/system/src/Grav/Common/Data/Data.php b/system/src/Grav/Common/Data/Data.php index d8378688e..6a35fbc9e 100644 --- a/system/src/Grav/Common/Data/Data.php +++ b/system/src/Grav/Common/Data/Data.php @@ -15,7 +15,7 @@ use RocketTheme\Toolbox\File\FileInterface; */ class Data implements DataInterface { - use ArrayAccessWithGetters, Countable, Export; + use ArrayAccessWithGetters, Countable, Export, DataMutatorTrait; protected $gettersVariable = 'items'; protected $items; @@ -56,67 +56,6 @@ class Data implements DataInterface return $this->get($name, $default, $separator); } - /** - * Get value by using dot notation for nested arrays/objects. - * - * @example $value = $data->get('this.is.my.nested.variable'); - * - * @param string $name Dot separated path to the requested value. - * @param mixed $default Default value (or null). - * @param string $separator Separator, defaults to '.' - * @return mixed Value. - */ - public function get($name, $default = null, $separator = '.') - { - $path = explode($separator, $name); - $current = $this->items; - foreach ($path as $field) { - if (is_object($current) && isset($current->{$field})) { - $current = $current->{$field}; - } elseif (is_array($current) && isset($current[$field])) { - $current = $current[$field]; - } else { - return $default; - } - } - - return $current; - } - - /** - * Sey value by using dot notation for nested arrays/objects. - * - * @example $value = $data->set('this.is.my.nested.variable', true); - * - * @param string $name Dot separated path to the requested value. - * @param mixed $value New value. - * @param string $separator Separator, defaults to '.' - */ - public function set($name, $value, $separator = '.') - { - $path = explode($separator, $name); - $current = &$this->items; - foreach ($path as $field) { - if (is_object($current)) { - // Handle objects. - if (!isset($current->{$field})) { - $current->{$field} = array(); - } - $current = &$current->{$field}; - } else { - // Handle arrays and scalars. - if (!is_array($current)) { - $current = array($field => array()); - } elseif (!isset($current[$field])) { - $current[$field] = array(); - } - $current = &$current[$field]; - } - } - - $current = $value; - } - /** * Set default value by using dot notation for nested arrays/objects. * diff --git a/system/src/Grav/Common/Data/DataMutatorTrait.php b/system/src/Grav/Common/Data/DataMutatorTrait.php new file mode 100644 index 000000000..c2110fe50 --- /dev/null +++ b/system/src/Grav/Common/Data/DataMutatorTrait.php @@ -0,0 +1,68 @@ +get('this.is.my.nested.variable'); + * + * @param string $name Dot separated path to the requested value. + * @param mixed $default Default value (or null). + * @param string $separator Separator, defaults to '.' + * @return mixed Value. + */ + public function get($name, $default = null, $separator = '.') + { + $path = explode($separator, $name); + $current = $this->items; + foreach ($path as $field) { + if (is_object($current) && isset($current->{$field})) { + $current = $current->{$field}; + } elseif (is_array($current) && isset($current[$field])) { + $current = $current[$field]; + } else { + return $default; + } + } + + return $current; + } + + /** + * Sey value by using dot notation for nested arrays/objects. + * + * @example $value = $data->set('this.is.my.nested.variable', true); + * + * @param string $name Dot separated path to the requested value. + * @param mixed $value New value. + * @param string $separator Separator, defaults to '.' + */ + public function set($name, $value, $separator = '.') + { + $path = explode($separator, $name); + $current = &$this->items; + foreach ($path as $field) { + if (is_object($current)) { + // Handle objects. + if (!isset($current->{$field})) { + $current->{$field} = array(); + } + $current = &$current->{$field}; + } else { + // Handle arrays and scalars. + if (!is_array($current)) { + $current = array($field => array()); + } elseif (!isset($current[$field])) { + $current[$field] = array(); + } + $current = &$current[$field]; + } + } + + $current = $value; + } + +} diff --git a/system/src/Grav/Common/Filesystem/Folder.php b/system/src/Grav/Common/Filesystem/Folder.php index 223b3dce8..b30751e6a 100644 --- a/system/src/Grav/Common/Filesystem/Folder.php +++ b/system/src/Grav/Common/Filesystem/Folder.php @@ -20,7 +20,7 @@ abstract class Folder $last_modified = 0; $dirItr = new \RecursiveDirectoryIterator($path, \RecursiveDirectoryIterator::SKIP_DOTS); - $filterItr = new GravRecursiveFolderFilterIterator($dirItr); + $filterItr = new RecursiveFolderFilterIterator($dirItr); $itr = new \RecursiveIteratorIterator($filterItr, \RecursiveIteratorIterator::SELF_FIRST); /** @var \RecursiveDirectoryIterator $file */ @@ -45,7 +45,7 @@ abstract class Folder $last_modified = 0; $dirItr = new \RecursiveDirectoryIterator($path, \RecursiveDirectoryIterator::SKIP_DOTS); - $filterItr = new GravRecursiveFileFilterIterator($dirItr); + $filterItr = new RecursiveFileFilterIterator($dirItr); $itr = new \RecursiveIteratorIterator($filterItr, \RecursiveIteratorIterator::SELF_FIRST); /** @var \RecursiveDirectoryIterator $file */ @@ -301,23 +301,3 @@ abstract class Folder return @rmdir($folder); } } - -class GravRecursiveFolderFilterIterator extends \RecursiveFilterIterator -{ - public function accept() - { - // only accept directories - return $this->current()->isDir(); - } -} - -class GravRecursiveFileFilterIterator extends \RecursiveFilterIterator -{ - public static $FILTERS = ['.DS_Store']; - - public function accept() - { - // Ensure any filtered file names are skipped - return !in_array($this->current()->getFilename(), self::$FILTERS, true); - } -} diff --git a/system/src/Grav/Common/Filesystem/RecursiveFileFilterIterator.php b/system/src/Grav/Common/Filesystem/RecursiveFileFilterIterator.php new file mode 100644 index 000000000..be9667c3b --- /dev/null +++ b/system/src/Grav/Common/Filesystem/RecursiveFileFilterIterator.php @@ -0,0 +1,13 @@ +current()->getFilename(), self::$FILTERS, true); + } +} diff --git a/system/src/Grav/Common/Filesystem/RecursiveFolderFilterIterator.php b/system/src/Grav/Common/Filesystem/RecursiveFolderFilterIterator.php new file mode 100644 index 000000000..f2d63f72e --- /dev/null +++ b/system/src/Grav/Common/Filesystem/RecursiveFolderFilterIterator.php @@ -0,0 +1,11 @@ +current()->isDir(); + } +} diff --git a/system/src/Grav/Common/GPM/Remote/Collection.php b/system/src/Grav/Common/GPM/Remote/Collection.php index 0373c4534..484661222 100644 --- a/system/src/Grav/Common/GPM/Remote/Collection.php +++ b/system/src/Grav/Common/GPM/Remote/Collection.php @@ -24,8 +24,6 @@ class Collection extends Iterator { private $repository; private $cache; - private $plugins, $themes; - public function __construct($repository = null) { if ($repository === null) { diff --git a/system/src/Grav/Common/Iterator.php b/system/src/Grav/Common/Iterator.php index 906a9be40..9105c0630 100644 --- a/system/src/Grav/Common/Iterator.php +++ b/system/src/Grav/Common/Iterator.php @@ -84,10 +84,43 @@ class Iterator implements \ArrayAccess, \Iterator, \Countable, \Serializable */ public function nth($key) { - $items = array_values($this->items); + $items = array_keys($this->items); return (isset($items[$key])) ? $this->offsetGet($items[$key]) : false; } + /** + * Get the first item + * + * @return mixed + */ + public function first() + { + $items = array_keys($this->items); + return $this->offsetGet(array_shift($items)); + } + + /** + * Get the last item + * + * @return mixed + */ + public function last() + { + $items = array_keys($this->items); + return $this->offsetGet(array_pop($items)); + } + + /** + * Reverse the Iterator + * + * @return $this + */ + public function reverse() + { + $this->items = array_reverse($this->items); + return $this; + } + /** * @param mixed $needle Searched value. * @return string|bool Key if found, otherwise false. diff --git a/system/src/Grav/Common/Page/Page.php b/system/src/Grav/Common/Page/Page.php index e9a0e3dbf..44a5665e2 100644 --- a/system/src/Grav/Common/Page/Page.php +++ b/system/src/Grav/Common/Page/Page.php @@ -90,10 +90,8 @@ class Page /** * Page Object Constructor - * - * @param array $array An array of existing page objects */ - public function __construct($array = array()) + public function __construct() { /** @var Config $config */ $config = self::getGrav()['config']; diff --git a/system/src/Grav/Common/Page/Pages.php b/system/src/Grav/Common/Page/Pages.php index 8d8966d62..bbff00e8d 100644 --- a/system/src/Grav/Common/Page/Pages.php +++ b/system/src/Grav/Common/Page/Pages.php @@ -523,19 +523,30 @@ class Pages /** @var \DirectoryIterator $file */ foreach ($iterator as $file) { + + if ($file->isDot()) { + continue; + } + $name = $file->getFilename(); - $modified = $file->getMTime(); - if ($file->isFile() && Utils::endsWith($name, CONTENT_EXT)) { + if ($file->isFile()) { - $page->init($file); - $content_exists = true; - - if ($config->get('system.pages.events.page')) { - $this->grav->fireEvent('onPageProcessed', new Event(['page' => $page])); + // Update the last modified if it's newer than already found + if ($file->getBasename() !== '.DS_Store' && ($modified = $file->getMTime()) > $last_modified) { + $last_modified = $modified; } - } elseif ($file->isDir() && !$file->isDot()) { + if (Utils::endsWith($name, CONTENT_EXT)) { + + $page->init($file); + $content_exists = true; + + if ($config->get('system.pages.events.page')) { + $this->grav->fireEvent('onPageProcessed', new Event(['page' => $page])); + } + } + } elseif ($file->isDir()) { if (!$page->path()) { $page->path($file->getPath()); @@ -554,11 +565,6 @@ class Pages $this->grav->fireEvent('onFolderProcessed', new Event(['page' => $page])); } } - - // Update the last modified if it's newer than already found - if ($modified > $last_modified) { - $last_modified = $modified; - } } // Set routability to false if no page found diff --git a/web.config b/web.config index 72a041f63..85d2c1b1b 100644 --- a/web.config +++ b/web.config @@ -38,7 +38,7 @@ - +