-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Assets from shortcode
{{% assets %}}
are now being cached with page…
… contents
- Loading branch information
1 parent
bd4f767
commit c0f748f
Showing
6 changed files
with
308 additions
and
20 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,160 @@ | ||
<?php | ||
/** | ||
* This file is part of Grav Shortcodes plugin. | ||
* | ||
* Dual licensed under the MIT or GPL Version 3 licenses, see LICENSE. | ||
* http://benjamin-regler.de/license/ | ||
*/ | ||
|
||
namespace Grav\Plugin\Shortcodes; | ||
|
||
use Grav\Common\Grav; | ||
use Grav\Common\Page\Page; | ||
use RocketTheme\Toolbox\Event\Event; | ||
|
||
class GravProxy implements \ArrayAccess | ||
{ | ||
protected $object; | ||
protected $page; | ||
protected $name = []; | ||
protected $callable; | ||
|
||
/** | ||
* Constructor. | ||
* | ||
* @param object $object [description] | ||
* @param Page $page [description] | ||
* @param [type] $name [description] | ||
*/ | ||
public function __construct($object, $page, $callable = null, $name = null) | ||
{ | ||
$this->object = $object; | ||
$this->page = $page; | ||
$this->callable = $callable; | ||
|
||
if ($name) { | ||
$this->name = is_array($name) ? $name : [$name]; | ||
} | ||
|
||
if ($callable && !is_callable($callable)) { | ||
throw new \Exception(sprintf("Function '%s' must be callable.", $callable)); | ||
} | ||
} | ||
|
||
public function __call($method, array $arguments = []) | ||
{ | ||
if ($callable = $this->callable) { | ||
$result = $callable([// new Event([ | ||
'type' => '__call', | ||
'object' => $this->object, | ||
'page' => $this->page, | ||
'name' => implode('.', $this->name), | ||
'arguments' => [$method, $arguments] | ||
]); | ||
} | ||
|
||
return is_null($result) ? call_user_func_array([$this->object, $method], $arguments) : $result; | ||
} | ||
|
||
/** | ||
* ArrayAccess implementation | ||
*/ | ||
|
||
/** | ||
* Whether or not an offset exists. | ||
* | ||
* @param mixed $offset An offset to check for. | ||
* @return bool Returns TRUE on success or FALSE on failure. | ||
*/ | ||
public function offsetExists($offset) | ||
{ | ||
if ($callable = $this->callable) { | ||
$result = $callable([ //new Event([ | ||
'type' => 'offsetExists', | ||
'object' => $this->object, | ||
'page' => $this->page, | ||
'name' => implode('.', $this->name), | ||
'arguments' => [$offset] | ||
]); | ||
} | ||
|
||
return is_null($result) ? isset($this->object[$offset]) : $result; | ||
} | ||
|
||
/** | ||
* Returns the value at specified offset. | ||
* | ||
* @param mixed $offset The offset to retrieve. | ||
* @return mixed Can return all value types. | ||
*/ | ||
public function offsetGet($offset) | ||
{ | ||
if (isset($this->object[$offset])) { | ||
if ($callable = $this->callable) { | ||
$result = $callable([ // new Event([ | ||
'type' => 'offsetGet', | ||
'object' => $this->object, | ||
'page' => $this->page, | ||
'name' => implode('.', $this->name), | ||
'arguments' => [$offset] | ||
]); | ||
} | ||
|
||
if (is_null($result)) { | ||
$name = array_merge($this->name, [$offset]); | ||
$result = new static($this->object[$offset], $this->page, $this->callable, $name); | ||
} | ||
|
||
return $result; | ||
} | ||
} | ||
|
||
/** | ||
* Assigns a value to the specified offset. | ||
* | ||
* @param mixed $offset The offset to assign the value to. | ||
* @param mixed $value The value to set. | ||
*/ | ||
public function offsetSet($offset, $value) | ||
{ | ||
if ($callable = $this->callable) { | ||
$result = $callable([ //new Event([ | ||
'type' => 'offsetSet', | ||
'object' => $object, | ||
'page' => $this->page, | ||
'name' => implode('.', $this->name), | ||
'arguments' => [$offset] | ||
]); | ||
} | ||
|
||
if (is_null($result)) { | ||
if (is_null($offset)) { | ||
$this->object[] = $value; | ||
} else { | ||
$this->object[$offset] = $value; | ||
} | ||
} | ||
} | ||
|
||
/** | ||
* Unsets an offset. | ||
* | ||
* @param mixed $offset The offset to unset. | ||
*/ | ||
public function offsetUnset($offset) | ||
{ | ||
if ($callable = $this->callable) { | ||
$result = $callable([// new Event([ | ||
'type' => 'offsetUnset', | ||
'object' => $this->object, | ||
'page' => $this->page, | ||
'name' => implode('.', $this->name), | ||
'arguments' => [$offset] | ||
]); | ||
} | ||
|
||
if (is_null($result)) { | ||
unset($this->object[$offset]); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,82 @@ | ||
# German | ||
de: | ||
PLUGINS: | ||
SHORTCODES: | ||
GLOBAL_CONFIG: "Globale Einstellungen" | ||
DEFAULT_CONFIG: "Standardeinstellungen für Shortcodes" | ||
PLUGIN_STATUS: "Plugin Status" | ||
|
||
OPTIONS: "Optionen" | ||
|
||
ASSETS: "Assets" | ||
ASSETS_ENABLED: "<code>{{% assets %}}</code> Shortcode aktivieren" | ||
ASSETS_OPTIONS: | ||
TYPE: "Assets-Typ" | ||
CSS: "CSS" | ||
JS: "JavaScript" | ||
INLINE: "Assets als Inline-Element" | ||
PRIORITY: "Assets Priorität" | ||
PRIORITY_HELP: "Priorität des Assets, wenn sie zur Grav Pipeline hinzugefügt werden; größere Werte werden zuerst geladen" | ||
PIPELINE: "Kombiniere Assets" | ||
LOAD: "Ladeverhalten" | ||
LOAD_HELP: 'Lade Assets asynchron "async" oder verzögert "defer"' | ||
DEFAULT: "- Standard -" | ||
ASYNC: "Async - asynchrones Laden von JavaScript" | ||
DEFER: "Defer - verzögertes Laden von JavaScript" | ||
|
||
COMMENT: "Comment" | ||
COMMENT_ENABLED: "<code>{{% comment %}}</code> Shortcode aktivieren" | ||
|
||
EMBED: "Embed" | ||
EMBED_ENABLED: "<code>{{% embed %}}</code> Shortcode aktivieren" | ||
EMBED_TEMPLATE: "Standard Seiten-Template" | ||
|
||
MARKDOWN: "Markdown" | ||
MARKDOWN_ENABLED: "<code>{{% markdown %}}</code> Shortcode aktivieren" | ||
|
||
SUMMARY: "Summary" | ||
SUMMARY_ENABLED: "<code>{{% summary %}}</code> Shortcode aktivieren" | ||
|
||
TWIG: "Twig" | ||
TWIG_ENABLED: "<code>{{% twig %}}</code> Shortcode aktivieren" | ||
|
||
# English | ||
en: | ||
PLUGINS: | ||
SHORTCODES: | ||
GLOBAL_CONFIG: "Global plugin configurations" | ||
DEFAULT_CONFIG: "Default values for Shortcodes configuration" | ||
PLUGIN_STATUS: "Plugin status" | ||
OPTIONS: "Options" | ||
|
||
ASSETS: "Assets" | ||
ASSETS_ENABLED: "Activate <code>{{% assets %}}</code> shortcode" | ||
ASSETS_OPTIONS: | ||
TYPE: "Default assets type" | ||
CSS: "CSS" | ||
JS: "JavaScript" | ||
INLINE: "Inline assets by default" | ||
PRIORITY: "Default assets priority" | ||
PRIORITY_HELP: "Priority to add CSS or JS to Grav pipeline; bigger comes first" | ||
PIPELINE: "Pipeline assets" | ||
LOAD: "Load behavior" | ||
LOAD_HELP: 'Load asset either asynchronously "async" or deferred "defer"' | ||
DEFAULT: "- default -" | ||
ASYNC: "Async - asynchronously load JavaScript" | ||
DEFER: "Defer - deferred loading of JavaScript" | ||
|
||
COMMENT: "Comment" | ||
COMMENT_ENABLED: "Activate <code>{{% comment %}}</code> shortcode" | ||
|
||
EMBED: "Embed" | ||
EMBED_ENABLED: "Activate <code>{{% embed %}}</code> shortcode" | ||
EMBED_TEMPLATE: "Default page template" | ||
|
||
MARKDOWN: "Markdown" | ||
MARKDOWN_ENABLED: "Activate <code>{{% markdown %}}</code> shortcode" | ||
|
||
SUMMARY: "Summary" | ||
SUMMARY_ENABLED: "Activate <code>{{% summary %}}</code> shortcode" | ||
|
||
TWIG: "Twig" | ||
TWIG_ENABLED: "Activate <code>{{% twig %}}</code> shortcode" |
Oops, something went wrong.