Skip to content

Commit

Permalink
Merge branch 'release/0.9.9'
Browse files Browse the repository at this point in the history
  • Loading branch information
rhukster committed Dec 5, 2014
2 parents d012c8e + dbfd237 commit 8991af1
Show file tree
Hide file tree
Showing 8 changed files with 133 additions and 62 deletions.
14 changes: 14 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,17 @@
# v0.9.9 beta
## 12/05/2014

1. [](#new)
* Added new `@page` collection type
* Added `ksort` and `contains` Twig filters
* Added `gist` Twig function
2. [](#improved)
* Refactored Page previous/next/adjacent functionality
* Updated to Symfony 2.6 for yaml/console/event-dispatcher libraries
* More PSR code fixes
3. [](#bugfix)
* Fix for over-escaped apostrophes in YAML

# v0.9.8 beta
## 12/01/2014

Expand Down
28 changes: 28 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,34 @@ You can download a **ready-built** package from the [Downloads page on http://ge

Check out the [install procedures](http://learn.getgrav.org/basics/installation) for more information.

# Adding Functionality

You can download manually from the [Downloads page on http://getgrav.org](http://getgrav.org/downloads), but the preferred solution is to use the [Grav Package Manager](http://learn.getgrav.org/advanced/grav-gpm) or `GPM`:

```
$ bin/gpm index
```

This will display all the available plugins and then you can install one ore more with:

```
$ bin/gpm install <plugin/theme>
```

# Updating

To update Grav you should use the [Grav Package Manager](http://learn.getgrav.org/advanced/grav-gpm) or `GPM`:

```
$ bin/gpm selfupgrade
```

To update plugins and themes:

```
$ bin/gpm update
```


# Contributing
We appreciate any contribution to Grav, whether it is related to bugs, grammar, or simply a suggestion or improvement.
Expand Down
Binary file modified bin/composer.phar
Binary file not shown.
6 changes: 3 additions & 3 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,9 @@
"php": ">=5.4.0",
"twig/twig": "~1.16",
"erusev/parsedown-extra": "dev-master",
"symfony/yaml": "~2.5",
"symfony/console": "~2.5",
"symfony/event-dispatcher": "~2.5",
"symfony/yaml": "~2.6",
"symfony/console": "~2.6",
"symfony/event-dispatcher": "~2.6",
"doctrine/cache": "~1.3",
"maximebf/debugbar": "dev-master",
"filp/whoops": "1.2.*@dev",
Expand Down
2 changes: 1 addition & 1 deletion system/defines.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

// Some standard defines
define('GRAV', true);
define('GRAV_VERSION', '0.9.8');
define('GRAV_VERSION', '0.9.9');
define('DS', '/');

// Directories and Paths
Expand Down
8 changes: 5 additions & 3 deletions system/src/Grav/Common/Page/Collection.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,8 @@ class Collection extends Iterator
*/
protected $params;

public function __construct($items = array(), array $params = array(), Pages $pages = null) {
public function __construct($items = array(), array $params = array(), Pages $pages = null)
{
parent::__construct($items);

$this->params = $params;
Expand Down Expand Up @@ -189,7 +190,8 @@ public function adjacentSibling($path, $direction = 1)
* @param string $path the path the item
* @return Page Item in the array the the current position.
*/
public function currentPosition($path) {
public function currentPosition($path)
{
return array_search($path, array_keys($this->items));
}

Expand All @@ -205,7 +207,7 @@ public function visible()
foreach ($this->items as $path => $slug) {
$page = $this->pages->get($path);
if ($page->visible()) {
$visible[$path] = $slug;
$visible[$path] = $slug;
}
}
return new static($visible, $this->params, $this->pages);
Expand Down
44 changes: 16 additions & 28 deletions system/src/Grav/Common/Page/Page.php
Original file line number Diff line number Diff line change
Expand Up @@ -1186,15 +1186,8 @@ public function children($type = Page::STANDARD_PAGES)
*/
public function isFirst()
{
/** @var Pages $pages */
$pages = self::$grav['pages'];
$parent = $pages->get($this->parent);

if ($this->path() == array_values($parent->items)[0]) {
return true;
} else {
return false;
}
$collection = $this->parent()->collection();
return $collection->isFirst($this->path());
}

/**
Expand All @@ -1204,15 +1197,8 @@ public function isFirst()
*/
public function isLast()
{
/** @var Pages $pages */
$pages = self::$grav['pages'];
$parent = $pages->get($this->parent);

if ($this->path() == array_values($parent->items)[count($parent->items)-1]) {
return true;
} else {
return false;
}
$collection = $this->parent()->collection();
return $collection->isLast($this->path());
}

/**
Expand Down Expand Up @@ -1243,16 +1229,8 @@ public function nextSibling()
*/
public function adjacentSibling($direction = 1)
{
/** @var Pages $pages */
$pages = self::$grav['pages'];
$parent = $pages->get($this->parent);
$current = $this->slug();

$keys = array_flip(array_keys($parent->items));
$values = array_values($parent->items);
$index = $keys[$current] - $direction;

return array_key_exists($index, $values) ? $pages->get($values[$index]) : $this;
$collection = $this->parent()->collection();
return $collection->adjacentSibling($this->path(), $direction);
}

/**
Expand Down Expand Up @@ -1454,6 +1432,16 @@ protected function evaluate($value)
}
}
break;

case '@page':
if (!empty($params)) {
$page = $this->find($params[0]);
if ($page) {
$results = $page->children(Page::STANDARD_PAGES);
}
}
break;

case '@taxonomy':
// Gets a collection of pages by using one of the following formats:
// @taxonomy.category: blog
Expand Down
93 changes: 66 additions & 27 deletions system/src/Grav/Common/TwigExtension.php
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,9 @@ public function getFilters()
new \Twig_SimpleFilter('truncate', [$this,'truncateFilter']),
new \Twig_SimpleFilter('*ize', [$this,'inflectorFilter']),
new \Twig_SimpleFilter('md5', [$this,'md5Filter']),
new \Twig_SimpleFilter('sort_by_key',[$this,'sortByKeyFilter']),
new \Twig_SimpleFilter('sort_by_key', [$this,'sortByKeyFilter']),
new \Twig_SimpleFilter('ksort', [$this,'ksortFilter']),
new \Twig_SimpleFilter('contains', [$this, 'containsFilter'])
];
}

Expand All @@ -61,6 +63,7 @@ public function getFunctions()
new \Twig_SimpleFunction('url', [$this, 'urlFunc']),
new \Twig_SimpleFunction('dump', [$this, 'dump'], ['needs_context' => true, 'needs_environment' => true]),
new \Twig_SimpleFunction('debug', [$this, 'dump'], ['needs_context' => true, 'needs_environment' => true]),
new \Twig_SimpleFunction('gist', [$this, 'gistFunc'])
];
}

Expand Down Expand Up @@ -201,6 +204,57 @@ public function md5Filter($str)
return md5($str);
}

/**
* Sorts a collection by key
*
* @param array $input
* @param string $filter
* @param array|int $direction
*
* @return string
*/
public function sortByKeyFilter(array $input, $filter, $direction = SORT_ASC)
{
$output = [];

if (!$input) {
return $output;
}

foreach ($input as $key => $row) {
$output[$key] = $row[$filter];
}

array_multisort($output, $direction, $input);

return $input;
}

/**
* Return ksorted collection.
*
* @param array $array
* @return array
*/
public function ksortFilter(array $array)
{
ksort($array);
return $array;
}

/**
* determine if a string contains another
*
* @param String $haystack
* @param String $needle
*
* @return boolean
*/
public function containsFilter($haystack, $needle)
{
return (strpos($haystack, $needle) !== false);
}

/**
* Repeat given string x times.
*
Expand Down Expand Up @@ -231,32 +285,6 @@ public function urlFunc($input, $domain = false)
return $uri->rootUrl($domain) .'/'. $locator->findResource($input, false);
}

/**
* Sorts a collection by key
*
* @param array $input
* @param string $filter
* @param array|int $direction
*
* @return string
*/
public function sortByKeyFilter(array $input, $filter, $direction = SORT_ASC)
{
$output = [];

if (!$input) {
return $output;
}

foreach ($input as $key => $row) {
$output[$key] = $row[$filter];
}

array_multisort($output, $direction, $input);

return $input;
}

/**
* Based on Twig_Extension_Debug / twig_var_dump
* (c) 2011 Fabien Potencier
Expand Down Expand Up @@ -291,4 +319,15 @@ public function dump(\Twig_Environment $env, $context)
}
}
}

/**
* Output a Gist
*
* @param string $id
* @return string
*/
public function gistFunc($id)
{
return '<script src="https://gist.github.com/'.$id.'.js"></script>';
}
}

0 comments on commit 8991af1

Please sign in to comment.