Skip to content

Commit

Permalink
Merge branch 'release/4.1.6'
Browse files Browse the repository at this point in the history
  • Loading branch information
rhukster committed Oct 3, 2019
2 parents 095c2a2 + c11871b commit 160a7bd
Show file tree
Hide file tree
Showing 10 changed files with 71 additions and 48 deletions.
10 changes: 10 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,13 @@
# v4.1.6
## 10/03/2019

1. [](#improved)
* Support markdown in `Figure` shortcode caption attribute
* FlexObjects compatibility: changed references to `Page` class to use `PageInterface`
* Reworked the `shortcode` twig var to use a class/method approach for better compatibility in modular/page formats
1. [](#bugfix)
* Fix issue with `[language]` when `include_default_lang: false` [#76](https://github.com/getgrav/grav-plugin-shortcode-core/issues/76)

# v4.1.5
## 09/05/2019

Expand Down
4 changes: 2 additions & 2 deletions blueprints.yaml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
name: Shortcode Core
version: 4.1.5
version: 4.1.6
description: "This plugin provides the core functionality for shortcode plugins"
icon: code
author:
Expand All @@ -13,7 +13,7 @@ bugs: https://github.com/getgrav/grav-plugin-shortcode-core/issues
license: MIT

dependencies:
- { name: grav, version: '>=1.5.10' }
- { name: grav, version: '>=1.6.4' }

form:
validation: strict
Expand Down
14 changes: 12 additions & 2 deletions classes/Shortcode.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,24 @@

namespace Grav\Plugin\Shortcodes;

use Grav\Common\Config\Config;
use Grav\Common\Grav;
use Grav\Common\Twig\Twig;
use Grav\Plugin\ShortcodeManager;
use Thunder\Shortcode\Shortcode\ShortcodeInterface;

class Shortcode
{
/** @var ShortcodeManager */
protected $shortcode;

/** @var Grav */
protected $grav;

/** @var Config */
protected $config;

/** @var Twig */
protected $twig;

/**
Expand All @@ -28,7 +38,7 @@ public function __construct()
*/
public function init()
{
$this->shortcode->handlers->add('u', function(ShortcodeInterface $shortcode) {
$this->shortcode->getHandlers()->add('u', function(ShortcodeInterface $shortcode) {
return $shortcode->getContent();
});
}
Expand All @@ -48,7 +58,7 @@ public function getParser()
return $this->config->get('plugins.shortcode-core.parser');
}

public function getBbCode($sc, $default = null)
public function getBbCode(ShortcodeInterface $sc, $default = null)
{
$code = $default;

Expand Down
15 changes: 7 additions & 8 deletions classes/ShortcodeManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

use Grav\Common\Data\Data;
use Grav\Common\Grav;
use Grav\Common\Page\Page;
use Grav\Common\Page\Interfaces\PageInterface;
use Guzzle\Common\Exception\UnexpectedValueException;
use Thunder\Shortcode\EventContainer\EventContainer;
use Thunder\Shortcode\HandlerContainer\HandlerContainer;
Expand All @@ -17,7 +17,7 @@ class ShortcodeManager
/** @var Grav $grav */
protected $grav;

/** @var Page $page */
/** @var PageInterface $page */
protected $page;

/** @var HandlerContainer $handlers */
Expand All @@ -37,7 +37,6 @@ class ShortcodeManager

/**
* initialize some internal instance variables
* @param Page $page
*/
public function __construct()
{
Expand Down Expand Up @@ -226,12 +225,12 @@ public function setupMarkdown($markdown)
* process the content by running over all the known shortcodes with the
* chosen parser
*
* @param Page $page the page to work on
* @param PageInterface $page the page to work on
* @param Data $config configuration merged with the page config
* @param null $handlers
* @return string
*/
public function processContent(Page $page, Data $config, $handlers = null)
public function processContent(PageInterface $page, Data $config, $handlers = null)
{
$parser = $this->getParser($config->get('parser'));

Expand All @@ -250,7 +249,7 @@ public function processContent(Page $page, Data $config, $handlers = null)
}
}

public function processRawContent(Page $page, Data $config)
public function processRawContent(PageInterface $page, Data $config)
{
return $this->processContent($page, $config, $this->raw_handlers);
}
Expand Down Expand Up @@ -309,9 +308,9 @@ public function getId(ShortcodeInterface $shortcode)
/**
* Sets the current page context
*
* @param Page $page
* @param PageInterface $page
*/
public function setPage(Page $page)
public function setPage(PageInterface $page)
{
$this->page = $page;
}
Expand Down
26 changes: 26 additions & 0 deletions classes/ShortcodeTwigVar.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
<?php
namespace Grav\Plugin\ShortcodeCore;

use Grav\Common\Grav;

class ShortcodeTwigVar
{
public function __call($name, $args)
{
/** @var ShortcodeManager $shortcode */
$shortcode = Grav::instance()['shortcode'];
$objects = $shortcode->getObjects();

if ($objects) {
return $objects[$name] ?? [];
} else {
$page_meta = Grav::instance()['page']->getContentMeta('shortcodeMeta');
if (isset($page_meta['shortcode'])) {
$objects = (array) $page_meta['shortcode'];
return $objects[$name] ?? [];
} else {
return [];
}
}
}
}
39 changes: 5 additions & 34 deletions shortcode-core.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,11 @@
namespace Grav\Plugin;

use Grav\Common\Assets;
use Grav\Common\Page\Page;
use Grav\Common\Plugin;
use Grav\Common\Utils;
use Grav\Plugin\ShortcodeCore\ShortcodeTwigVar;
use RocketTheme\Toolbox\Event\Event;
use RocketTheme\Toolbox\ResourceLocator\UniformResourceLocator;


class ShortcodeCorePlugin extends Plugin
{
Expand All @@ -23,9 +23,10 @@ public static function getSubscribedEvents()
require_once(__DIR__.'/classes/Shortcode.php');
require_once(__DIR__.'/classes/ShortcodeObject.php');
require_once(__DIR__.'/classes/ShortcodeManager.php');
require_once(__DIR__.'/classes/ShortcodeTwigVar.php');

return [
'onPluginsInitialized' => ['onPluginsInitialized', 10],
'onPluginsInitialized' => ['onPluginsInitialized', 10]
];
}

Expand Down Expand Up @@ -181,17 +182,6 @@ public function onPageContent(Event $event)
}
}
}

if (isset($page_meta['shortcode'])) {
$objects = $page_meta['shortcode'];
$twig = $this->grav['twig'];

if (!empty($objects)) {
foreach ($objects as $key => $object) {
$twig->twig_vars['shortcode'][$key] = $object;
}
}
}
}
}

Expand Down Expand Up @@ -220,25 +210,6 @@ public function onTwigInitialized()
[$this->shortcodes, 'processShortcodes']
)
);
}

/**
* Helper method that merges the content meta shortcode data with twig variables
*
* @param $meta
*/
private function mergeTwigVars($meta)
{
// check content meta for objects, and if found as them as twig variables
if (isset($meta['shortcode'])) {
$objects = $meta['shortcode'];
$twig = $this->grav['twig'];

if (!empty($objects)) {
foreach ($objects as $key => $object) {
$twig->twig_vars['shortcode'][$key] = $object;
}
}
}
$this->grav['twig']->twig_vars['shortcode'] = new ShortcodeTwigVar();
}
}
7 changes: 6 additions & 1 deletion shortcodes/FigureShortcode.php
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
<?php
namespace Grav\Plugin\Shortcodes;

use Grav\Common\Utils;
use Thunder\Shortcode\Shortcode\ShortcodeInterface;

class FigureShortcode extends Shortcode
Expand All @@ -10,7 +11,11 @@ public function init()
$this->shortcode->getHandlers()->add('figure', function(ShortcodeInterface $sc) {
$id = $sc->getParameter('id');
$class = $sc->getParameter('class');
$caption = $sc->getParameter('caption');
$caption = $sc->getParameter('caption');
$page = $this->grav['page'];

// Process any markdown on caption
$caption = Utils::processMarkdown($caption, false, $page);

$id_output = $id ? 'id="' . $id . '" ': '';
$class_output = $class ? 'class="' . $class . '"' : '';
Expand Down
2 changes: 1 addition & 1 deletion shortcodes/LanguageShortcode.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ public function init()
if ($lang) {
/** @var Language $language */
$language = $this->grav['language'];
$current = $language->getActive();
$current = $language->getLanguage();

if ($current == $lang) {
return $sc->getContent();
Expand Down
1 change: 1 addition & 0 deletions shortcodes/SectionShortcode.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,5 +12,6 @@ public function init()
$object = new ShortcodeObject($name, $sc->getContent());
$this->shortcode->addObject($sc->getName(), $object);
});

}
}
1 change: 1 addition & 0 deletions vendor/composer/autoload_psr4.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,5 @@

return array(
'Thunder\\Shortcode\\' => array($vendorDir . '/thunderer/shortcode/src'),
'Grav\\Plugin\\ShortcodeCore' => array($baseDir . '/classes'),
);

0 comments on commit 160a7bd

Please sign in to comment.