(Grav GitSync) Automatic Commit from smokephil
This commit is contained in:
commit
4267db646d
2765 changed files with 462171 additions and 0 deletions
49
plugins/assets/CHANGELOG.md
Normal file
49
plugins/assets/CHANGELOG.md
Normal file
|
|
@ -0,0 +1,49 @@
|
|||
# v2.0.1
|
||||
## 12/21/2018
|
||||
|
||||
1. [](#bugfix)
|
||||
* Fire `onPageInitialized` later as it breaks on-page forms
|
||||
* Fixed a spelling error
|
||||
|
||||
# v2.0.0
|
||||
## 01/01/2015
|
||||
|
||||
1. [](#improved)
|
||||
* Uses Grav cache internally to store assets
|
||||
* Works with modular pages now too
|
||||
1. [](#bugfix)
|
||||
* Actually works with page cache enabled now
|
||||
|
||||
# v1.2.1
|
||||
## 10/07/2015
|
||||
|
||||
1. [](#bugfix)
|
||||
* Fixed a bug with inline CSS and JS
|
||||
|
||||
# v1.2.0
|
||||
## 06/23/2015
|
||||
|
||||
1. [](#new)
|
||||
* Support for multiple items
|
||||
* added ability to use Grav page refs and local assets + page enable override
|
||||
|
||||
# v1.0.4
|
||||
## 02/05/2015
|
||||
|
||||
1. [](#improved)
|
||||
* REGEX optimizations
|
||||
* Code improvements
|
||||
|
||||
# v1.0.3
|
||||
## 01/23/2015
|
||||
|
||||
1. [](#improved)
|
||||
* Changed event to utilize new `onPageContentRaw()` -> requires Grav 0.9.14+
|
||||
* Added admin checks
|
||||
* PSR fixes
|
||||
|
||||
# v1.0.2
|
||||
## 11/30/2014
|
||||
|
||||
1. [](#new)
|
||||
* ChangeLog started...
|
||||
21
plugins/assets/LICENSE
Normal file
21
plugins/assets/LICENSE
Normal file
|
|
@ -0,0 +1,21 @@
|
|||
The MIT License (MIT)
|
||||
|
||||
Copyright (c) 2014 Grav
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
in the Software without restriction, including without limitation the rights
|
||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
copies of the Software, and to permit persons to whom the Software is
|
||||
furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in all
|
||||
copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
SOFTWARE.
|
||||
97
plugins/assets/README.md
Normal file
97
plugins/assets/README.md
Normal file
|
|
@ -0,0 +1,97 @@
|
|||
# Grav Assets Plugin
|
||||
|
||||
|
||||
`assets` is a [Grav](http://github.com/getgrav/grav) plugin that provides a convenient way to add CSS and JS assets directly from your pages.
|
||||
|
||||
# Installation
|
||||
|
||||
Installing the Assets plugin can be done in one of two ways. Our GPM (Grav Package Manager) installation method enables you to quickly and easily install the plugin with a simple terminal command, while the manual method enables you to do so via a zip file.
|
||||
|
||||
## GPM Installation (Preferred)
|
||||
|
||||

|
||||
|
||||
The simplest way to install this plugin is via the [Grav Package Manager (GPM)](http://learn.getgrav.org/advanced/grav-gpm) through your system's Terminal (also called the command line). From the root of your Grav install type:
|
||||
|
||||
bin/gpm install assets
|
||||
|
||||
This will install the Assets plugin into your `/user/plugins` directory within Grav. Its files can be found under `/your/site/grav/user/plugins/assets`.
|
||||
|
||||
## Manual Installation
|
||||
|
||||
To install this plugin, just download the zip version of this repository and unzip it under `/your/site/grav/user/plugins`. Then, rename the folder to `assets`. You can find these files either on [GitHub](https://github.com/getgrav/grav-plugin-assets) or via [GetGrav.org](http://getgrav.org/downloads/plugins#extras).
|
||||
|
||||
You should now have all the plugin files under
|
||||
|
||||
/your/site/grav/user/plugins/assets
|
||||
|
||||
>> NOTE: This plugin is a modular component for Grav which requires [Grav](http://github.com/getgrav/grav), the [Error](https://github.com/getgrav/grav-plugin-error) and [Problems](https://github.com/getgrav/grav-plugin-problems) plugins, and a theme to be installed in order to operate.
|
||||
|
||||
# Config Defaults
|
||||
|
||||
```
|
||||
enabled: true
|
||||
```
|
||||
|
||||
If you need to change any value, then the best process is to copy the [assets.yaml](assets.yaml) file into your `users/config/plugins/` folder (create it if it doesn't exist), and then modify there. This will override the default settings.
|
||||
|
||||
# Usage
|
||||
|
||||
Once the plugin is installed you can use the following syntax to add various asset types, where default order is 10 for `js` and `css` types:
|
||||
|
||||
```
|
||||
{assets:css order:5}
|
||||
custom-style.css
|
||||
/blog/some-blog/post/style.css
|
||||
//cdnjs.cloudflare.com/ajax/libs/1140/2.0/1140.css
|
||||
http://somesite.com/js/cookies.min.css
|
||||
{/assets}
|
||||
|
||||
{assets:js order:10}
|
||||
custom-script.js
|
||||
/blog/some-blog/post/script.js
|
||||
//cdnjs.cloudflare.com/ajax/libs/1140/2.0/1140.min.js
|
||||
http://somesite.com/js/cookies.min.js
|
||||
{/assets}
|
||||
|
||||
{assets:inline_css}
|
||||
h1 {color: red !important;}
|
||||
{/assets}
|
||||
|
||||
{assets:inline_js}
|
||||
function initialize() {
|
||||
var mapCanvas = document.getElementById('map_canvas');
|
||||
var mapOptions = {
|
||||
center: new google.maps.LatLng(44.5403, -78.5463),
|
||||
zoom: 8,
|
||||
mapTypeId: google.maps.MapTypeId.ROADMAP
|
||||
}
|
||||
var map = new google.maps.Map(mapCanvas, mapOptions);
|
||||
}
|
||||
{/assets}
|
||||
```
|
||||
|
||||
> Note: If you want to see this plugin in action, have a look at [Grav Learn Site](http://learn.getgrav.org)
|
||||
|
||||
# Updating
|
||||
|
||||
As development for the Assets plugin continues, new versions may become available that add additional features and functionality, improve compatibility with newer Grav releases, and generally provide a better user experience. Updating Assets is easy, and can be done through Grav's GPM system, as well as manually.
|
||||
|
||||
## GPM Update (Preferred)
|
||||
|
||||
The simplest way to update this plugin is via the [Grav Package Manager (GPM)](http://learn.getgrav.org/advanced/grav-gpm). You can do this with this by navigating to the root directory of your Grav install using your system's Terminal (also called command line) and typing the following:
|
||||
|
||||
bin/gpm update assets
|
||||
|
||||
This command will check your Grav install to see if your Assets plugin is due for an update. If a newer release is found, you will be asked whether or not you wish to update. To continue, type `y` and hit enter. The plugin will automatically update and clear Grav's cache.
|
||||
|
||||
## Manual Update
|
||||
|
||||
Manually updating Assets is pretty simple. Here is what you will need to do to get this done:
|
||||
|
||||
* Delete the `your/site/user/plugins/assets` directory.
|
||||
* Download the new version of the Assets plugin from either [GitHub](https://github.com/getgrav/grav-plugin-assets) or [GetGrav.org](http://getgrav.org/downloads/plugins#extras).
|
||||
* Unzip the zip file in `your/site/user/plugins` and rename the resulting folder to `assets`.
|
||||
* Clear the Grav cache. The simplest way to do this is by going to the root Grav directory in terminal and typing `bin/grav clear-cache`.
|
||||
|
||||
> Note: Any changes you have made to any of the files listed under this directory will also be removed and replaced by the new set. Any files located elsewhere (for example a YAML settings file placed in `user/config/plugins`) will remain intact.
|
||||
174
plugins/assets/assets.php
Normal file
174
plugins/assets/assets.php
Normal file
|
|
@ -0,0 +1,174 @@
|
|||
<?php
|
||||
namespace Grav\Plugin;
|
||||
|
||||
use \Grav\Common\Plugin;
|
||||
use RocketTheme\Toolbox\Event\Event;
|
||||
|
||||
class AssetsPlugin extends Plugin
|
||||
{
|
||||
protected $assets;
|
||||
|
||||
/**
|
||||
* @return array
|
||||
*/
|
||||
public static function getSubscribedEvents()
|
||||
{
|
||||
return [
|
||||
'onPageContentRaw' => ['onPageContentRaw', 0],
|
||||
'onPageInitialized' => ['onPageInitialized', -10],
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* Find inline assets in the following format:
|
||||
*
|
||||
* {assets:inline_css}
|
||||
* h1 {color: red !important;}
|
||||
* {/assets}
|
||||
*
|
||||
* {assets:css order:5}
|
||||
* //cdnjs.cloudflare.com/ajax/libs/1140/2.0/1140.css
|
||||
* //cdnjs.cloudflare.com/ajax/libs/1140/2.0/1141.css
|
||||
* //cdnjs.cloudflare.com/ajax/libs/1140/2.0/1142.css
|
||||
* {/assets}
|
||||
*
|
||||
* {assets:js}
|
||||
* //cdnjs.cloudflare.com/ajax/libs/angularFire/0.5.0/angularfire.min.js
|
||||
* {/assets}
|
||||
*
|
||||
* {assets:inline_js}
|
||||
* function initialize() {
|
||||
* var mapCanvas = document.getElementById('map_canvas');
|
||||
* var mapOptions = {
|
||||
* center: new google.maps.LatLng(44.5403, -78.5463),
|
||||
* zoom: 8,
|
||||
* mapTypeId: google.maps.MapTypeId.ROADMAP
|
||||
* }
|
||||
* var map = new google.maps.Map(mapCanvas, mapOptions);
|
||||
* }
|
||||
* {/assets}
|
||||
*
|
||||
* @param Event $e
|
||||
*/
|
||||
public function onPageContentRaw(Event $e)
|
||||
{
|
||||
if ($this->isAdmin()) {
|
||||
$this->active = false;
|
||||
return;
|
||||
}
|
||||
|
||||
$page = $e['page'];
|
||||
|
||||
$config = $this->mergeConfig($page);
|
||||
|
||||
if ($config->get('enabled')) {
|
||||
$content = $e['page']->getRawContent();
|
||||
|
||||
preg_match_all('/(?:<p>)?{assets(?:\:(.+?))?(?: order:(.+?))?}\s?(.*?)\s?{\/assets}(?:<\/p>)?(?:\n)?/smi', $content, $matches);
|
||||
|
||||
$count = count($matches[0]);
|
||||
if ($count) {
|
||||
for ($x=0; $x<$count; $x++) {
|
||||
$action = $matches[1][$x] ?: null;
|
||||
$order = $matches[2][$x] ?: null;
|
||||
|
||||
$data_string = trim(strip_tags($matches[3][$x], '<link><script>'));
|
||||
$data = explode("\n", $data_string);
|
||||
$content = str_replace($matches[0][$x], '', $content);
|
||||
|
||||
// if not a full URL try to find a page and use it's full path
|
||||
if (in_array($action, ['css','js'])) {
|
||||
foreach ($data as $key => $value) {
|
||||
if (!$this->isValidUrl($value)) {
|
||||
$path_parts = pathinfo($value);
|
||||
if ($path_parts['dirname'] == '.') {
|
||||
$asset_page = $page;
|
||||
} else {
|
||||
$asset_page = $this->grav['pages']->dispatch($path_parts['dirname'], true);
|
||||
}
|
||||
|
||||
if ($asset_page) {
|
||||
$path = str_replace(GRAV_ROOT, '', $asset_page->path());
|
||||
$data[$key] = $path . '/' . $path_parts['basename'];
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if ($action == 'css' || $action == 'js' || $action == null) {
|
||||
foreach ($data as $entry) {
|
||||
// $this->grav['assets']->add($entry, $order);
|
||||
$this->assets[$action] []= [$entry, $order];
|
||||
}
|
||||
} elseif ($action == 'inline_css' || $action == 'inline_js') {
|
||||
// $this->grav['assets']->addInlineCss($matches[3][$x]);
|
||||
$this->assets[$action] []= $matches[3][$x];
|
||||
}
|
||||
}
|
||||
|
||||
$e['page']->setRawContent($content);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public function onPageInitialized()
|
||||
{
|
||||
if ($this->isAdmin()) {
|
||||
return;
|
||||
}
|
||||
|
||||
$page = $this->grav['page'];
|
||||
$assets = $this->grav['assets'];
|
||||
$cache = $this->grav['cache'];
|
||||
|
||||
// Initialize all page content up front before Twig happens
|
||||
if (isset($page->header()->content['items'])) {
|
||||
foreach ($page->collection() as $item) {
|
||||
$item->content();
|
||||
}
|
||||
} else {
|
||||
$page->content();
|
||||
}
|
||||
|
||||
// Get and set the cache as required
|
||||
$cache_id = md5('assets'.$page->path().$cache->getKey());
|
||||
if (empty($this->assets)) {
|
||||
$this->assets = $cache->fetch($cache_id);
|
||||
} else {
|
||||
$cache->save($cache_id, $this->assets);
|
||||
}
|
||||
|
||||
// if we actually have data now, add it to asset manager
|
||||
if (!empty($this->assets)) {
|
||||
foreach ($this->assets as $type => $asset) {
|
||||
foreach ($asset as $item) {
|
||||
if (is_array($item)) {
|
||||
$assets->add($item[0], $item[1]);
|
||||
} else {
|
||||
if ($type == 'inline_css') {
|
||||
$assets->addInlineCss($item);
|
||||
} elseif ($type == 'inline_js') {
|
||||
$assets->addInlineJs($item);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @param $url
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
protected function isValidUrl($url)
|
||||
{
|
||||
$regex = '/^(?:(https?|ftp|telnet):)?\/\/((?:[a-z0-9@:.-]|%[0-9A-F]{2}){3,})(?::(\d+))?((?:\/(?:[a-z0-9-._~!$&\'\(\)\*\+\,\;\=\:\@]|%[0-9A-F]{2})*)*)(?:\?((?:[a-z0-9-._~!$&\'\(\)\*\+\,\;\=\:\/?@]|%[0-9A-F]{2})*))?(?:#((?:[a-z0-9-._~!$&\'\(\)\*\+\,\;\=\:\/?@]|%[0-9A-F]{2})*))?/';
|
||||
if (preg_match($regex, $url)) {
|
||||
return true;
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
1
plugins/assets/assets.yaml
Normal file
1
plugins/assets/assets.yaml
Normal file
|
|
@ -0,0 +1 @@
|
|||
enabled: true
|
||||
BIN
plugins/assets/assets/readme_1.png
Normal file
BIN
plugins/assets/assets/readme_1.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 41 KiB |
27
plugins/assets/blueprints.yaml
Normal file
27
plugins/assets/blueprints.yaml
Normal file
|
|
@ -0,0 +1,27 @@
|
|||
name: Assets
|
||||
version: 2.0.1
|
||||
description: "This plugin provides a convenient way to add CSS and JS assets directly from your pages."
|
||||
icon: list-alt
|
||||
author:
|
||||
name: Team Grav
|
||||
email: devs@getgrav.org
|
||||
url: http://getgrav.org
|
||||
homepage: https://github.com/getgrav/grav-plugin-assets
|
||||
demo: http://learn.getgrav.org
|
||||
keywords: assets, javascript, css, inline
|
||||
bugs: https://github.com/getgrav/grav-plugin-assets/issues
|
||||
license: MIT
|
||||
|
||||
form:
|
||||
validation: strict
|
||||
fields:
|
||||
enabled:
|
||||
type: toggle
|
||||
label: Plugin status
|
||||
highlight: 1
|
||||
default: 0
|
||||
options:
|
||||
1: Enabled
|
||||
0: Disabled
|
||||
validate:
|
||||
type: bool
|
||||
15
plugins/assets/hebe.json
Normal file
15
plugins/assets/hebe.json
Normal file
|
|
@ -0,0 +1,15 @@
|
|||
{
|
||||
"project":"grav-plugin-assets",
|
||||
"platforms":{
|
||||
"grav":{
|
||||
"nodes":{
|
||||
"plugin":[
|
||||
{
|
||||
"source":"/",
|
||||
"destination":"/user/plugins/assets"
|
||||
}
|
||||
]
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue