Skip to content

Commit 53a6530

Browse files
committed
Merge branch 'release/4.0.0'
2 parents b9435fb + cf431bd commit 53a6530

File tree

8 files changed

+68
-53
lines changed

8 files changed

+68
-53
lines changed

CHANGELOG.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,11 @@
1+
# v4.0.0
2+
## 03/20/2019
3+
4+
1. [](#improved)
5+
* Improved way to handle shortcodeAssets from `Page::contentMeta()` - Fixes numerous issues
6+
* Allow `size` shortcode to handle non-numeric values (e.g. `%`, `x-large`, etc.) [#63](https://github.com/getgrav/grav-plugin-shortcode-core/pull/63)
7+
* Added FontAwesome 5 support [#56](https://github.com/getgrav/grav-plugin-shortcode-core/pull/56)
8+
19
# v3.1.2
210
## 03/15/2019
311

blueprints.yaml

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
name: Shortcode Core
2-
version: 3.1.2
2+
version: 4.0.0
33
description: "This plugin provides the core functionality for shortcode plugins"
44
icon: code
55
author:
@@ -13,7 +13,7 @@ bugs: https://github.com/getgrav/grav-plugin-shortcode-core/issues
1313
license: MIT
1414

1515
dependencies:
16-
- { name: grav, version: '~1.5' }
16+
- { name: grav, version: '>=1.5.9' }
1717

1818
form:
1919
validation: strict
@@ -99,3 +99,15 @@ form:
9999
label: Fontawesome URL
100100
help: You can change the location of fontawesome by changing this URL
101101
size: large
102+
103+
fontawesome.v5:
104+
type: toggle
105+
label: Use Fontawesome Version 5
106+
help: Allows usage of the 'fab', 'fas' and other new font families of Fontawesome 5.
107+
highlight: 0
108+
default: 0
109+
options:
110+
1: Enabled
111+
0: Disabled
112+
validate:
113+
type: bool

shortcode-core.php

Lines changed: 18 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
<?php
22
namespace Grav\Plugin;
33

4+
use Grav\Common\Assets;
45
use Grav\Common\Page\Page;
56
use Grav\Common\Plugin;
67
use Grav\Common\Utils;
@@ -45,7 +46,7 @@ public function onPluginsInitialized()
4546
'onMarkdownInitialized' => ['onMarkdownInitialized', 0],
4647
'onShortcodeHandlers' => ['onShortcodeHandlers', 0],
4748
'onPageContentProcessed' => ['onPageContentProcessed', 0],
48-
'onPageInitialized' => ['onPageInitialized', 0],
49+
'onPageContent' => ['onPageContent', 0],
4950
'onTwigInitialized' => ['onTwigInitialized', 0],
5051
'onTwigPageVariables' => ['onTwigPageVariables', 0],
5152
'onTwigSiteVariables' => ['onTwigSiteVariables', 0],
@@ -127,54 +128,35 @@ public function onPageContentProcessed(Event $e)
127128
/**
128129
* Handle the assets that might be associated with this page
129130
*/
130-
public function onPageInitialized(Event $event)
131+
public function onPageContent(Event $event)
131132
{
132133
if (!$this->active) {
133134
return;
134135
}
135136

136137
$page = $event['page'];
137-
$assets = $this->grav['assets'];
138-
$meta = [];
139-
140-
// Initialize all page content up front before Twig happens
141-
if (isset($page->header()->content['items'])) {
142-
foreach ($page->collection() as $item) {
143-
// initialize modular item content
144-
$item->content();
145-
146-
$item_meta = $item->getContentMeta('shortcodeMeta');
147-
if ($item_meta) {
148-
$meta = array_merge_recursive($meta, $item_meta);
149-
}
150-
}
151-
}
152-
153-
// Always initialize current page
154-
$page->content();
155138

156139
// get the meta and check for assets
157140
$page_meta = $page->getContentMeta('shortcodeMeta');
158-
if ($page_meta) {
159-
$meta = array_merge_recursive($meta, $page_meta);
160-
}
161141

162-
// if assets found, add them to Assets manager
163-
if (isset($meta['shortcodeAssets'])) {
164-
$page_assets = (array) $meta['shortcodeAssets'];
165-
if (!empty($page_assets)) {
166-
// if we actually have data now, add it to asset manager
167-
foreach ($page_assets as $type => $asset) {
168-
foreach ($asset as $item) {
169-
$method = 'add'.ucfirst($type);
170-
if (is_array($item)) {
171-
$assets->add($item[0], $item[1]);
172-
} else {
173-
$assets->$method($item);
174-
}
142+
if (is_array($page_meta) && isset($page_meta['shortcodeAssets'])) {
143+
144+
$page_assets = (array) $page_meta['shortcodeAssets'];
145+
146+
/** @var Assets $assets */
147+
$assets = $this->grav['assets'];
148+
// if we actually have data now, add it to asset manager
149+
foreach ($page_assets as $type => $asset) {
150+
foreach ($asset as $item) {
151+
$method = 'add'.ucfirst($type);
152+
if (is_array($item)) {
153+
$assets->$method($item[0], $item[1]);
154+
} else {
155+
$assets->$method($item);
175156
}
176157
}
177158
}
159+
178160
}
179161
}
180162

shortcode-core.yaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,4 +7,5 @@ custom_shortcodes:
77
fontawesome:
88
load: true
99
url: '//maxcdn.bootstrapcdn.com/font-awesome/4.6.1/css/font-awesome.min.css'
10+
v5: false
1011

shortcodes/ColorShortcode.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ class ColorShortcode extends Shortcode
88
public function init()
99
{
1010
$this->shortcode->getHandlers()->add('color', function(ShortcodeInterface $sc) {
11-
$color = $sc->getParameter('color', $sc->getBbCode());
11+
$color = $sc->getParameter('color', $this->getBbCode($sc));
1212
return '<span style="color: '.$color.';">'.$sc->getContent().'</span>';
1313
});
1414
}

shortcodes/FontAwesomeShortcode.php

Lines changed: 21 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -13,31 +13,42 @@ public function init()
1313
if ($this->config->get('plugins.shortcode-core.fontawesome.load', false)) {
1414
$this->shortcode->addAssets('css', $this->config->get('plugins.shortcode-core.fontawesome.url'));
1515
}
16+
if ($this->config->get('plugins.shortcode-core.fontawesome.v5', false)) {
17+
$v5classes = array('fab', 'fal', 'fas', 'far');
18+
} else {
19+
$v5classes = array();
20+
}
1621

1722
// Get shortcode content and parameters
1823
$str = $sc->getContent();
19-
$icon = $sc->getParameter('icon', $sc->getParameter('fa', $sc->getBbCode()));
24+
$icon = $sc->getParameter('icon', $sc->getParameter('fa', $this->getBbCode($sc)));
2025

2126
if (!Utils::startsWith($icon, 'fa-')) {
2227
$icon = 'fa-'.$icon;
2328
}
2429

25-
if ($icon) {
26-
$extras = explode(',',$sc->getParameter('extras', ''));
27-
foreach ($extras as $extra) {
28-
if (!empty($extra)) {
29-
if (!Utils::startsWith($extra, 'fa-')) {
30-
$extra = 'fa-'.$extra;
30+
if($icon) {
31+
$fa_class = 'fa';
32+
$extras = explode(',', $sc->getParameter('extras', ''));
33+
34+
foreach($extras as $extra) {
35+
if(!empty($extra)) {
36+
if(in_array($extra, $v5classes)) {
37+
$fa_class = $extra;
38+
continue;
39+
}
40+
if(!Utils::startsWith($extra, 'fa-')) {
41+
$extra = 'fa-' . $extra;
3142
}
32-
$icon .= ' '.$extra;
43+
$icon .= ' ' . $extra;
3344
}
3445
}
3546

36-
$output = '<i class="fa '.$icon.'">'.$str.'</i>';
47+
$output = '<i class="' . $fa_class . ' ' . $icon . '">' . $str . '</i>';
3748

3849
return $output;
3950
}
4051

4152
});
4253
}
43-
}
54+
}

shortcodes/NoticeShortcode.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ public function init()
99
{
1010
$this->shortcode->getHandlers()->add('notice', function(ShortcodeInterface $sc) {
1111
$this->shortcode->addAssets('css', 'plugin://shortcode-core/css/shortcode-notice.css');
12-
$type = $sc->getParameter('notice', $sc->getBbCode()) ?: 'info';
12+
$type = $sc->getParameter('notice', $this->getBbCode($sc)) ?: 'info';
1313
return '<div class="sc-notice '.$type.'"><div>'.$sc->getContent().'</div></div>';
1414
});
1515
}

shortcodes/SizeShortcode.php

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,9 @@ class SizeShortcode extends Shortcode
88
public function init()
99
{
1010
$this->shortcode->getHandlers()->add('size', function(ShortcodeInterface $sc) {
11-
$size = $sc->getParameter('size', $sc->getBbCode());
12-
return '<span style="font-size: '.$size.'px;">'.$sc->getContent().'</span>';
11+
$size = $sc->getParameter('size', $this->getBbCode($sc));
12+
if ( is_numeric($size) ) { $size = $size.'px' ; }
13+
return '<span style="font-size: '.$size.';">'.$sc->getContent().'</span>';
1314
});
1415
}
15-
}
16+
}

0 commit comments

Comments
 (0)