Merge branch 'release/0.9.19'

This commit is contained in:
Andy Miller
2015-02-28 17:53:09 -07:00
16 changed files with 241 additions and 196 deletions

View File

@@ -1,3 +1,17 @@
# v0.9.19
## 02/38/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 +25,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

File diff suppressed because one or more lines are too long

View File

@@ -55,6 +55,8 @@ assets: # Configuration for Assets Manager (JS, C
css_rewrite: true # Rewrite any CSS relative URLs during pipelining
js_pipeline: false # The JS pipeline is the unification of multiple JS resources into one file
js_minify: true # Minify the JS during pipelining
collections:
jquery: system://assets/jquery/jquery-2.1.3.min.js
errors:
display: true # Display full backtrace-style error page

View File

@@ -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

View File

@@ -169,6 +169,11 @@ class Assets
$this->config($asset_config);
$this->base_url = $base_url . '/';
// Register any preconfigured collections
foreach ($config->get('system.assets.collections') as $name => $collection) {
$this->registerCollection($name, (array)$collection);
}
}
/**
@@ -228,7 +233,9 @@ class Assets
foreach ($asset as $a) {
$this->addCss($a, $priority, $pipeline);
}
return $this;
} elseif (isset($this->collections[$asset])) {
$this->add($this->collections[$asset], $priority, $pipeline);
return $this;
}
@@ -267,7 +274,9 @@ class Assets
foreach ($asset as $a) {
$this->addJs($a, $priority, $pipeline);
}
return $this;
} elseif (isset($this->collections[$asset])) {
$this->add($this->collections[$asset], $priority, $pipeline);
return $this;
}
@@ -529,17 +538,68 @@ class Assets
return $relative_path . $key;
}
/**
* Return the array of all the registered CSS assets
*
* @return array
*/
public function getCss()
{
return $this->css;
}
/**
* Return the array of all the registered JS assets
*
* @return array
*/
public function getJs()
{
return $this->js;
}
/**
* Return the array of all the registered collections
*
* @return array
*/
public function getCollections()
{
return $this->collections;
}
/**
* Determines if an asset exists as a collection, CSS or JS reference
*
* @param $asset
*
* @return bool
*/
public function exists($asset)
{
if (isset($this->collections[$asset]) ||
isset($this->css[$asset]) ||
isset($this->js[$asset])) {
return true;
} else {
return false;
}
}
/**
* Add/replace collection.
*
* @param string $collectionName
* @param array $assets
* @param bool $overwrite
*
* @return $this
*/
public function registerCollection($collectionName, Array $assets)
public function registerCollection($collectionName, Array $assets, $overwrite = false)
{
$this->collections[$collectionName] = $assets;
if ($overwrite || !isset($this->collections[$collectionName])) {
$this->collections[$collectionName] = $assets;
}
return $this;
}
@@ -578,26 +638,6 @@ class Assets
return $this;
}
/**
* Get all CSS assets already added.
*
* @return array
*/
public function getCss()
{
return $this->css;
}
/**
* Get all JavaScript assets already added.
*
* @return array
*/
public function getJs()
{
return $this->js;
}
/**
* Add all CSS assets within $directory (relative to public dir).
*

View File

@@ -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;
}

View File

@@ -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.
*

View File

@@ -0,0 +1,68 @@
<?php
namespace Grav\Common\Data;
trait DataMutatorTrait
{
/**
* 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;
}
}

View File

@@ -46,9 +46,11 @@ class Debugger
public function addAssets()
{
if ($this->enabled()) {
$assets = $this->grav['assets'];
// Add jquery library
$assets->add('jquery', 101);
$this->renderer = $this->debugbar->getJavascriptRenderer();
$this->renderer->setIncludeVendors(false);

View File

@@ -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);
}
}

View File

@@ -0,0 +1,13 @@
<?php
namespace Grav\Common\Filesystem;
class RecursiveFileFilterIterator 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);
}
}

View File

@@ -0,0 +1,11 @@
<?php
namespace Grav\Common\Filesystem;
class RecursiveFolderFilterIterator extends \RecursiveFilterIterator
{
public function accept()
{
// only accept directories
return $this->current()->isDir();
}
}

View File

@@ -24,8 +24,6 @@ class Collection extends Iterator {
private $repository;
private $cache;
private $plugins, $themes;
public function __construct($repository = null)
{
if ($repository === null) {

View File

@@ -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.

View File

@@ -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'];

View File

@@ -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