diff --git a/classes/Handlebars.php b/classes/Handlebars.php index 01c708b..0dbcd46 100644 --- a/classes/Handlebars.php +++ b/classes/Handlebars.php @@ -1,4 +1,8 @@ roots()->templates() . DIRECTORY_SEPARATOR . $filename . '.' .option('bnomei.handlebars.extension.output'); + return kirby()->roots()->cache() . DIRECTORY_SEPARATOR . + 'bnomei' . DIRECTORY_SEPARATOR . 'handlebars' . DIRECTORY_SEPARATOR . 'lnc' . DIRECTORY_SEPARATOR . + $filename . '.' .option('bnomei.handlebars.extension.output'); } private static $templates = []; @@ -195,7 +201,6 @@ public static function r($name, array $data = [], $root = null, $file = null): s return ''; } - if (!$result || $loadTemplate['needsUpdate']) { // NOTE: since LightnCandy returns a Closure and // these can not be packed into a var as string @@ -204,7 +209,7 @@ public static function r($name, array $data = [], $root = null, $file = null): s $result = snippet('handlebars/render', [ 'precompiledTemplate' => $php, 'data' => $data, - ]); + ], true); if ($renderCacheId) { $renderCache->set($renderCacheId, $result); diff --git a/composer.json b/composer.json index e341471..bd16fb2 100644 --- a/composer.json +++ b/composer.json @@ -45,14 +45,15 @@ ], "require": { "php": ">=7.1.0", - "zordius/lightncandy": "1.2.2", - "getkirby/cms": "^3.0.0-RC-2.0" + "getkirby/cms": "^3.0.0-RC-2.0", + "zordius/lightncandy": "1.2.2" }, "conflict": { "getkirby/kirby": "<3.0" }, "scripts": { "zip": [ + "touch kirby3-handlebars.zip", "rm kirby3-handlebars.zip", "composer install --no-dev", "composer remove getkirby/cms", diff --git a/composer.lock b/composer.lock index c988a5e..fd041eb 100644 --- a/composer.lock +++ b/composer.lock @@ -4,7 +4,7 @@ "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies", "This file is @generated automatically" ], - "content-hash": "36458a7992314e111caeca6f8b61a994", + "content-hash": "5d8c212d0c907e8a63b6fcf7539834c2", "packages": [ { "name": "claviska/simpleimage", @@ -45,177 +45,18 @@ "description": "A PHP class that makes working with images as simple as possible.", "time": "2017-09-12T09:03:56+00:00" }, - { - "name": "defuse/php-encryption", - "version": "v2.2.1", - "source": { - "type": "git", - "url": "https://github.com/defuse/php-encryption.git", - "reference": "0f407c43b953d571421e0020ba92082ed5fb7620" - }, - "dist": { - "type": "zip", - "url": "https://api.github.com/repos/defuse/php-encryption/zipball/0f407c43b953d571421e0020ba92082ed5fb7620", - "reference": "0f407c43b953d571421e0020ba92082ed5fb7620", - "shasum": "" - }, - "require": { - "ext-openssl": "*", - "paragonie/random_compat": ">= 2", - "php": ">=5.4.0" - }, - "require-dev": { - "nikic/php-parser": "^2.0|^3.0|^4.0", - "phpunit/phpunit": "^4|^5" - }, - "bin": [ - "bin/generate-defuse-key" - ], - "type": "library", - "autoload": { - "psr-4": { - "Defuse\\Crypto\\": "src" - } - }, - "notification-url": "https://packagist.org/downloads/", - "license": [ - "MIT" - ], - "authors": [ - { - "name": "Taylor Hornby", - "email": "taylor@defuse.ca", - "homepage": "https://defuse.ca/" - }, - { - "name": "Scott Arciszewski", - "email": "info@paragonie.com", - "homepage": "https://paragonie.com" - } - ], - "description": "Secure PHP Encryption Library", - "keywords": [ - "aes", - "authenticated encryption", - "cipher", - "crypto", - "cryptography", - "encrypt", - "encryption", - "openssl", - "security", - "symmetric key cryptography" - ], - "time": "2018-07-24T23:27:56+00:00" - }, - { - "name": "erusev/parsedown", - "version": "1.8.0-beta-5", - "source": { - "type": "git", - "url": "https://github.com/erusev/parsedown.git", - "reference": "c26a2ee4bf8ba0270daab7da0353f2525ca6564a" - }, - "dist": { - "type": "zip", - "url": "https://api.github.com/repos/erusev/parsedown/zipball/c26a2ee4bf8ba0270daab7da0353f2525ca6564a", - "reference": "c26a2ee4bf8ba0270daab7da0353f2525ca6564a", - "shasum": "" - }, - "require": { - "ext-mbstring": "*", - "php": ">=5.3.0" - }, - "require-dev": { - "phpunit/phpunit": "^4.8.35" - }, - "type": "library", - "autoload": { - "psr-0": { - "Parsedown": "" - } - }, - "notification-url": "https://packagist.org/downloads/", - "license": [ - "MIT" - ], - "authors": [ - { - "name": "Emanuil Rusev", - "email": "hello@erusev.com", - "homepage": "http://erusev.com" - } - ], - "description": "Parser for Markdown.", - "homepage": "http://parsedown.org", - "keywords": [ - "markdown", - "parser" - ], - "time": "2018-06-11T18:15:32+00:00" - }, - { - "name": "erusev/parsedown-extra", - "version": "0.8.0-beta-1", - "source": { - "type": "git", - "url": "https://github.com/erusev/parsedown-extra.git", - "reference": "e756b1bf8642ab1091403e902b0503f1cec7527d" - }, - "dist": { - "type": "zip", - "url": "https://api.github.com/repos/erusev/parsedown-extra/zipball/e756b1bf8642ab1091403e902b0503f1cec7527d", - "reference": "e756b1bf8642ab1091403e902b0503f1cec7527d", - "shasum": "" - }, - "require": { - "erusev/parsedown": "^1.8.0|^1.8.0-beta-4", - "ext-dom": "*", - "ext-mbstring": "*", - "php": ">=5.3.6" - }, - "require-dev": { - "phpunit/phpunit": "^4.8.35" - }, - "type": "library", - "autoload": { - "psr-0": { - "ParsedownExtra": "" - } - }, - "notification-url": "https://packagist.org/downloads/", - "license": [ - "MIT" - ], - "authors": [ - { - "name": "Emanuil Rusev", - "email": "hello@erusev.com", - "homepage": "http://erusev.com" - } - ], - "description": "An extension of Parsedown that adds support for Markdown Extra.", - "homepage": "https://github.com/erusev/parsedown-extra", - "keywords": [ - "markdown", - "markdown extra", - "parsedown", - "parser" - ], - "time": "2018-05-08T21:54:32+00:00" - }, { "name": "filp/whoops", - "version": "2.2.0", + "version": "2.3.1", "source": { "type": "git", "url": "https://github.com/filp/whoops.git", - "reference": "181c4502d8f34db7aed7bfe88d4f87875b8e947a" + "reference": "bc0fd11bc455cc20ee4b5edabc63ebbf859324c7" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/filp/whoops/zipball/181c4502d8f34db7aed7bfe88d4f87875b8e947a", - "reference": "181c4502d8f34db7aed7bfe88d4f87875b8e947a", + "url": "https://api.github.com/repos/filp/whoops/zipball/bc0fd11bc455cc20ee4b5edabc63ebbf859324c7", + "reference": "bc0fd11bc455cc20ee4b5edabc63ebbf859324c7", "shasum": "" }, "require": { @@ -234,7 +75,7 @@ "type": "library", "extra": { "branch-alias": { - "dev-master": "2.1-dev" + "dev-master": "2.2-dev" } }, "autoload": { @@ -263,20 +104,20 @@ "throwable", "whoops" ], - "time": "2018-03-03T17:56:25+00:00" + "time": "2018-10-23T09:00:00+00:00" }, { "name": "getkirby/cms", - "version": "dev-master", + "version": "3.0.0-RC-4.0", "source": { "type": "git", "url": "https://github.com/k-next/kirby.git", - "reference": "e4c9f4d2dab9d145544aca59903199f146c3211b" + "reference": "4fef488a4a1b9644f8b89df227829fc1b6f9d108" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/k-next/kirby/zipball/e4c9f4d2dab9d145544aca59903199f146c3211b", - "reference": "e4c9f4d2dab9d145544aca59903199f146c3211b", + "url": "https://api.github.com/repos/k-next/kirby/zipball/4fef488a4a1b9644f8b89df227829fc1b6f9d108", + "reference": "4fef488a4a1b9644f8b89df227829fc1b6f9d108", "shasum": "" }, "archive": { @@ -311,26 +152,31 @@ }, "require": { "claviska/simpleimage": "3.3.*", - "defuse/php-encryption": "2.2.*", - "erusev/parsedown-extra": "0.8.*", + "ext-ctype": "*", "ext-mbstring": "*", - "filp/whoops": "2.2.*", + "filp/whoops": "2.3.*", + "getkirby/composer-installer": "*", "michelf/php-smartypants": "1.8.*", "mustangostang/spyc": "0.6.*", "php": ">=7.1.0", "phpmailer/phpmailer": "6.0.*", - "true/punycode": "2.1.*" + "true/punycode": "2.1.*", + "zendframework/zend-escaper": "2.6.*" }, "require-dev": { "friendsofphp/php-cs-fixer": "^2.11.1", + "phpstan/phpstan": "^0.10.7", "phpunit/phpunit": "^6.0" }, - "type": "library", + "type": "kirby-cms", "autoload": { "files": [ "config/helpers.php", "config/aliases.php" ], + "classmap": [ + "dependencies/" + ], "psr-4": { "Kirby\\": "src/" } @@ -341,6 +187,9 @@ } }, "scripts": { + "analyze": [ + "./vendor/bin/phpstan analyse src" + ], "test": [ "./vendor/bin/phpunit --stderr --coverage-html=tests/coverage" ], @@ -351,13 +200,13 @@ "./scripts/build" ], "fix": [ - "./vendor/bin/php-cs-fixer fix ./src/" + "./vendor/bin/php-cs-fixer fix ." ] }, "authors": [ { - "name": "Bastian Allgeier", - "email": "bastian@getkirby.com", + "name": "Kirby Team", + "email": "support@getkirby.com", "homepage": "https://getkirby.com" } ], @@ -373,7 +222,45 @@ "forum": "https://forum.getkirby.com", "source": "https://github.com/getkirby/kirby" }, - "time": "2018-07-31T15:39:35+00:00" + "time": "2019-01-07T16:07:18+00:00" + }, + { + "name": "getkirby/composer-installer", + "version": "1.0.1", + "source": { + "type": "git", + "url": "https://github.com/k-next/composer-installer.git", + "reference": "dc0e38c4f0fc04875c1a523d82364a44f436cbf4" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/k-next/composer-installer/zipball/dc0e38c4f0fc04875c1a523d82364a44f436cbf4", + "reference": "dc0e38c4f0fc04875c1a523d82364a44f436cbf4", + "shasum": "" + }, + "require": { + "composer-plugin-api": "^1.0" + }, + "require-dev": { + "composer/composer": "^1.3", + "phpunit/phpunit": "^6.0" + }, + "type": "composer-plugin", + "extra": { + "class": "Kirby\\ComposerInstaller\\Plugin" + }, + "autoload": { + "psr-4": { + "Kirby\\ComposerInstaller\\": "src/" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "description": "Kirby's custom Composer installer for the Kirby CMS", + "homepage": "https://getkirby.com", + "time": "2018-12-19T10:01:45+00:00" }, { "name": "league/color-extractor", @@ -529,63 +416,18 @@ ], "time": "2017-02-24T16:06:33+00:00" }, - { - "name": "paragonie/random_compat", - "version": "v9.99.99", - "source": { - "type": "git", - "url": "https://github.com/paragonie/random_compat.git", - "reference": "84b4dfb120c6f9b4ff7b3685f9b8f1aa365a0c95" - }, - "dist": { - "type": "zip", - "url": "https://api.github.com/repos/paragonie/random_compat/zipball/84b4dfb120c6f9b4ff7b3685f9b8f1aa365a0c95", - "reference": "84b4dfb120c6f9b4ff7b3685f9b8f1aa365a0c95", - "shasum": "" - }, - "require": { - "php": "^7" - }, - "require-dev": { - "phpunit/phpunit": "4.*|5.*", - "vimeo/psalm": "^1" - }, - "suggest": { - "ext-libsodium": "Provides a modern crypto API that can be used to generate random bytes." - }, - "type": "library", - "notification-url": "https://packagist.org/downloads/", - "license": [ - "MIT" - ], - "authors": [ - { - "name": "Paragon Initiative Enterprises", - "email": "security@paragonie.com", - "homepage": "https://paragonie.com" - } - ], - "description": "PHP 5.x polyfill for random_bytes() and random_int() from PHP 7", - "keywords": [ - "csprng", - "polyfill", - "pseudorandom", - "random" - ], - "time": "2018-07-02T15:55:56+00:00" - }, { "name": "phpmailer/phpmailer", - "version": "v6.0.5", + "version": "v6.0.6", "source": { "type": "git", "url": "https://github.com/PHPMailer/PHPMailer.git", - "reference": "cb3ea134d4d3729e7857737d5f320cce9caf4d32" + "reference": "8190d73eb5def11a43cfb020b7f36db65330698c" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/PHPMailer/PHPMailer/zipball/cb3ea134d4d3729e7857737d5f320cce9caf4d32", - "reference": "cb3ea134d4d3729e7857737d5f320cce9caf4d32", + "url": "https://api.github.com/repos/PHPMailer/PHPMailer/zipball/8190d73eb5def11a43cfb020b7f36db65330698c", + "reference": "8190d73eb5def11a43cfb020b7f36db65330698c", "shasum": "" }, "require": { @@ -638,20 +480,20 @@ } ], "description": "PHPMailer is a full-featured email creation and transfer class for PHP", - "time": "2018-03-27T13:49:45+00:00" + "time": "2018-11-16T00:41:32+00:00" }, { "name": "psr/log", - "version": "1.0.2", + "version": "1.1.0", "source": { "type": "git", "url": "https://github.com/php-fig/log.git", - "reference": "4ebe3a8bf773a19edfe0a84b6585ba3d401b724d" + "reference": "6c001f1daafa3a3ac1d8ff69ee4db8e799a654dd" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/php-fig/log/zipball/4ebe3a8bf773a19edfe0a84b6585ba3d401b724d", - "reference": "4ebe3a8bf773a19edfe0a84b6585ba3d401b724d", + "url": "https://api.github.com/repos/php-fig/log/zipball/6c001f1daafa3a3ac1d8ff69ee4db8e799a654dd", + "reference": "6c001f1daafa3a3ac1d8ff69ee4db8e799a654dd", "shasum": "" }, "require": { @@ -685,20 +527,20 @@ "psr", "psr-3" ], - "time": "2016-10-10T12:19:37+00:00" + "time": "2018-11-20T15:27:04+00:00" }, { "name": "symfony/polyfill-mbstring", - "version": "v1.8.0", + "version": "v1.10.0", "source": { "type": "git", "url": "https://github.com/symfony/polyfill-mbstring.git", - "reference": "3296adf6a6454a050679cde90f95350ad604b171" + "reference": "c79c051f5b3a46be09205c73b80b346e4153e494" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/symfony/polyfill-mbstring/zipball/3296adf6a6454a050679cde90f95350ad604b171", - "reference": "3296adf6a6454a050679cde90f95350ad604b171", + "url": "https://api.github.com/repos/symfony/polyfill-mbstring/zipball/c79c051f5b3a46be09205c73b80b346e4153e494", + "reference": "c79c051f5b3a46be09205c73b80b346e4153e494", "shasum": "" }, "require": { @@ -710,7 +552,7 @@ "type": "library", "extra": { "branch-alias": { - "dev-master": "1.8-dev" + "dev-master": "1.9-dev" } }, "autoload": { @@ -744,7 +586,7 @@ "portable", "shim" ], - "time": "2018-04-26T10:06:28+00:00" + "time": "2018-09-21T13:07:52+00:00" }, { "name": "true/punycode", @@ -792,6 +634,51 @@ ], "time": "2016-11-16T10:37:54+00:00" }, + { + "name": "zendframework/zend-escaper", + "version": "2.6.0", + "source": { + "type": "git", + "url": "https://github.com/zendframework/zend-escaper.git", + "reference": "31d8aafae982f9568287cb4dce987e6aff8fd074" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/zendframework/zend-escaper/zipball/31d8aafae982f9568287cb4dce987e6aff8fd074", + "reference": "31d8aafae982f9568287cb4dce987e6aff8fd074", + "shasum": "" + }, + "require": { + "php": "^5.6 || ^7.0" + }, + "require-dev": { + "phpunit/phpunit": "^5.7.27 || ^6.5.8 || ^7.1.2", + "zendframework/zend-coding-standard": "~1.0.0" + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-master": "2.6.x-dev", + "dev-develop": "2.7.x-dev" + } + }, + "autoload": { + "psr-4": { + "Zend\\Escaper\\": "src/" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "BSD-3-Clause" + ], + "description": "Securely and safely escape HTML, HTML attributes, JavaScript, CSS, and URLs", + "keywords": [ + "ZendFramework", + "escaper", + "zf" + ], + "time": "2018-04-25T15:48:53+00:00" + }, { "name": "zordius/lightncandy", "version": "v1.2.2", @@ -846,20 +733,15 @@ } ], "packages-dev": [], - "aliases": [ - { - "alias": "3.0.0", - "alias_normalized": "3.0.0.0", - "version": "9999999-dev", - "package": "getkirby/cms" - } - ], - "minimum-stability": "beta", + "aliases": [], + "minimum-stability": "stable", "stability-flags": { - "getkirby/cms": 20 + "getkirby/cms": 5 }, "prefer-stable": false, "prefer-lowest": false, - "platform": [], + "platform": { + "php": ">=7.1.0" + }, "platform-dev": [] } diff --git a/config.php b/config.php old mode 100644 new mode 100755 index 57bc1b7..9207843 --- a/config.php +++ b/config.php @@ -3,7 +3,7 @@ Kirby::plugin('bnomei/handlebars', [ 'options' => [ 'component' => false, - 'escape' => false, // => FLAG_NOESCAPE aka {{{ }}} are default + 'no-escape' => true, // => FLAG_NOESCAPE aka {{{ }}} are not needed 'dir.templates' => function () { return kirby()->roots()->templates(); @@ -21,6 +21,7 @@ 'cache.render' => true, // creates a plugin cache called 'render' 'cache.files' => true, // creates a plugin cache called 'files' + 'cache.lnc' => true, // creates a plugin cache called 'lnc' ], 'components' => [ 'template' => function (Kirby\Cms\App $kirby, string $name, string $type = 'html') { diff --git a/readme.md b/readme.md old mode 100644 new mode 100755 index c36002e..82da0ea --- a/readme.md +++ b/readme.md @@ -79,11 +79,10 @@ return function ($site, $page, $kirby) { - default: `false` if `true` all templating will be handled by this plugin. -**escape** -- default: `false` +**no-escape** +- default: `true` By default data sent to template [will NOT be escaped](https://zordius.github.io/HandlebarsCookbook/LC-FLAG_NOESCAPE.html). This way your templates can render data formated as html. You can use Kirbys Field Methods `$field->kirbytext()`, `$field->html()` or the `Kirby\Toolkit\Str`-Class functions to escape your text properly. -Alternatively you can set it to `true` and use `{{{ var }}}` [triple mustaches](https://handlebarsjs.com/expressions.html). - +Alternatively you can set it to `false` and use `{{{ var }}}` [triple mustaches](https://handlebarsjs.com/expressions.html). **dir.templates** - default: callback returning `kirby()->roots()->templates()` diff --git a/snippets/handlebars.php b/snippets/handlebars.php old mode 100644 new mode 100755 index ada2549..aafff2a --- a/snippets/handlebars.php +++ b/snippets/handlebars.php @@ -1,6 +1,6 @@