Merge branch 'release/0.9.8'

This commit is contained in:
Andy Miller
2014-12-01 15:31:13 -07:00
13 changed files with 77 additions and 89 deletions

View File

@@ -1,3 +1,19 @@
# v0.9.8 beta
## 12/01/2014
1. [](#new)
* Added configuration option to set default lifetime on cache saves
* Added ability to set HTTP status code from page header
* Implemented simple wild-card custom routing
2. [](#improved)
* Fixed elusive double load to fully cache issue (hopefully!)
* Ensure Twig tags are treated as block items in markdown
* Removed some older deprecated methods
* Ensure onPageContentProcessed() event only fires when not cached
* More PSR code fixes
3. [](#bugfix)
* Fix issue with miscalculation of blog separator location `===`
# v0.9.7 beta
## 11/24/2014

View File

@@ -27,6 +27,7 @@ cache:
method: file # Method to check for updates in pages: file|folder|none
driver: auto # One of: auto|file|apc|xcache|memcache|wincache
prefix: 'g' # Cache prefix string (prevents cache conflicts)
lifetime: 0 # Lifetime of cached data in seconds (0 = infinite)
twig:
cache: true # Set to true to enable twig caching

View File

@@ -2,7 +2,7 @@
// Some standard defines
define('GRAV', true);
define('GRAV_VERSION', '0.9.7');
define('GRAV_VERSION', '0.9.8');
define('DS', '/');
// Directories and Paths

View File

@@ -73,7 +73,7 @@ class Cache extends Getters
$this->driver = $this->getCacheDriver();
// Set the cache namespace to our unique key
$this->driver->setNamespace($this->key);
// $this->driver->setNamespace($this->key);
}
/**
@@ -154,6 +154,10 @@ class Cache extends Getters
public function save($id, $data, $lifetime = null)
{
if ($this->enabled) {
if ($lifetime == null) {
$lifetime = $this->config->get('system.cache.lifetime') ?: null;
}
$this->driver->save($id, $data, $lifetime);
}
}

View File

@@ -282,6 +282,11 @@ class Grav extends Container
$this['debugger']->enabled(false);
// $this['debugger']->sendDataInHeaders();
}
// Set HTTP response code
if (isset($this['page']->header()->http_response_code)) {
http_response_code($this['page']->header()->http_response_code);
}
}
/**

View File

@@ -5,9 +5,10 @@ class Markdown extends \Parsedown
{
use MarkdownGravLinkTrait;
function __construct($page)
public function __construct($page)
{
$this->page = $page;
$this->BlockTypes['{'] [] = "TwigTag";
}
}

View File

@@ -5,9 +5,10 @@ class MarkdownExtra extends \ParsedownExtra
{
use MarkdownGravLinkTrait;
function __construct($page)
public function __construct($page)
{
parent::__construct();
$this->page = $page;
$this->BlockTypes['{'] [] = "TwigTag";
}
}

View File

@@ -14,6 +14,19 @@ trait MarkdownGravLinkTrait
{
use GravTrait;
/**
* Ensure Twig tags are treated as block level items with no <p></p> tags
*/
protected function identifyTwigTag($Line)
{
if (preg_match('/[{%|{{|{#].*[#}|}}|%}]/', $Line['body'], $matches)) {
$Block = array(
'element' => $Line['body'],
);
return $Block;
}
}
protected function identifyLink($Excerpt)
{
/** @var Config $config */

View File

@@ -58,6 +58,7 @@ class Page
protected $routable;
protected $modified;
protected $id;
protected $items;
protected $header;
protected $frontmatter;
protected $content;
@@ -128,7 +129,8 @@ class Page
* @param string $var Raw content string
* @return Object Raw content string
*/
public function raw($var = null) {
public function raw($var = null)
{
$file = $this->file();
if ($var) {
@@ -146,7 +148,8 @@ class Page
return $file ? $file->raw() : '';
}
public function frontmatter($var = null) {
public function frontmatter($var = null)
{
if ($var) {
$this->frontmatter = (string) $var;
@@ -244,7 +247,6 @@ class Page
$this->process[$process] = $status;
}
}
}
return $this->header;
@@ -258,7 +260,6 @@ class Page
*/
public function summary($size = null)
{
$content = $this->content();
// Return calculated summary based on summary divider's position
@@ -346,6 +347,8 @@ class Page
// Cache the whole page, including processed content
if ($update_cache) {
// Process any post-processing but pre-caching functionality
self::$grav->fireEvent('onPageContentProcessed', new Event(['page' => $this]));
$cache->save($cache_id, $this->content);
}
@@ -356,9 +359,6 @@ class Page
$this->content = str_replace('<p>'.SUMMARY_DELIMITER.'</p>', '', $this->content);
}
// Process any post-processing but pre-caching functionality
self::$grav->fireEvent('onPageContentProcessed', new Event(['page' => $this]));
}
return $this->content;
@@ -647,7 +647,7 @@ class Page
*
* @return string
*/
public function child_type()
public function childType()
{
return isset($this->header->child_type) ? (string) $this->header->child_type : 'default';
}
@@ -786,7 +786,7 @@ class Page
}
// Build an array of meta objects..
foreach((array)$page_header->metadata as $key => $value) {
foreach ((array)$page_header->metadata as $key => $value) {
// If this is a property type metadata: "og", "twitter", "facebook" etc
if (is_array($value)) {
@@ -1179,73 +1179,6 @@ class Page
return $children;
}
/**
* @throws \Exception
* @deprecated
*/
public function count()
{
throw new \Exception('Use $page->children()->count() instead.');
}
/**
* @param $key
* @throws \Exception
* @deprecated
*/
public function __get($key)
{
throw new \Exception('Use $page->children()->__get() instead.');
}
/**
* @param $key
* @param $value
* @throws \Exception
* @deprecated
*/
public function __set($key, $value)
{
throw new \Exception('Use $page->children()->__set() instead.');
}
/**
* @throws \Exception
* @deprecated
*/
public function current()
{
throw new \Exception('Use $page->children()->current() instead.');
}
/**
* @throws \Exception
* @deprecated
*/
public function next()
{
throw new \Exception('Use $page->children()->next() instead.');
}
/**
* @throws \Exception
* @deprecated
*/
public function prev()
{
throw new \Exception('Use $page->children()->prev() instead.');
}
/**
* @param string $key
* @throws \Exception
* @deprecated
*/
public function nth($key)
{
throw new \Exception('Use $page->children()->nth($position) instead.');
}
/**
* Check to see if this item is the first in an array of sub-pages.
*

View File

@@ -236,14 +236,27 @@ class Pages
// Fetch page if there's a defined route to it.
$page = isset($this->routes[$url]) ? $this->get($this->routes[$url]) : null;
// If the page cannot be reached, look into site wide routes.
// If the page cannot be reached, look into site wide routes + wildcards
if (!$all && (!$page || !$page->routable())) {
/** @var Config $config */
$config = $this->grav['config'];
// See if route matches one in the site configuration
$route = $config->get("site.routes.{$url}");
if ($route) {
$page = $this->dispatch($route, $all);
} else {
// Try looking for wildcards
foreach ($config->get("site.routes") as $alias => $route) {
$match = rtrim($alias, '*');
if (strpos($alias, '*') !== false && strpos($url, $match) !== false) {
$wildcard_url = str_replace('*', str_replace($match, '', $url), $route);
$page = isset($this->routes[$wildcard_url]) ? $this->get($this->routes[$wildcard_url]) : null;
if ($page) {
return $page;
}
}
}
}
}

View File

@@ -30,7 +30,8 @@ class Plugin implements EventSubscriberInterface
*
* @return array
*/
public static function getSubscribedEvents() {
public static function getSubscribedEvents()
{
$methods = get_class_methods(get_called_class());
$list = array();

View File

@@ -19,7 +19,8 @@ class Plugins extends Iterator
{
protected $grav;
public function __construct(Grav $grav) {
public function __construct(Grav $grav)
{
$this->grav = $grav;
}
@@ -78,7 +79,7 @@ class Plugins extends Iterator
*
* @return array
*/
static public function all()
public static function all()
{
$list = array();
$iterator = new \DirectoryIterator('plugins://');
@@ -98,7 +99,7 @@ class Plugins extends Iterator
return $list;
}
static public function get($name)
public static function get($name)
{
$blueprints = new Blueprints("plugins://{$name}");
$blueprint = $blueprints->get('blueprints');
@@ -117,4 +118,5 @@ class Plugins extends Iterator
return $obj;
}
}

View File

@@ -222,13 +222,11 @@ class TwigExtension extends \Twig_Extension
*/
public function urlFunc($input, $domain = false)
{
$grav = Grav::instance();
/** @var UniformResourceLocator $locator */
$locator = $grav['locator'];
$locator = $this->grav['locator'];
/** @var Uri $uri */
$uri = $grav['uri'];
$uri = $this->grav['uri'];
return $uri->rootUrl($domain) .'/'. $locator->findResource($input, false);
}