2017 © Pedro Peláez
 

library plates-asset-cache

Caching and compression for Plates template assets (JavaScript and CSS).

image

odan/plates-asset-cache

Caching and compression for Plates template assets (JavaScript and CSS).

  • Friday, November 17, 2017
  • by odan
  • Repository
  • 1 Watchers
  • 3 Stars
  • 2,344 Installations
  • PHP
  • 1 Dependents
  • 0 Suggesters
  • 1 Forks
  • 0 Open issues
  • 15 Versions
  • 0 % Grown

The README.md

Plates Assets Cache Extension

Caching and compression for Plates template assets (JavaScript and CSS)., (*1)

Latest Version on Packagist Software License Build Status Code Coverage Quality Score Total Downloads, (*2)

Installation

composer require odan/plates-asset-cache

Requirements

  • PHP 7.3+ or 8.0+

Configuration

use League\Plates\Engine;
use Odan\PlatesAsset\AssetEngine;
use Odan\PlatesAsset\PlatesAssetExtension;
use Symfony\Component\Cache\Adapter\FilesystemAdapter;

$engine = new Engine('/path/with/html/templates');

$options = [
    // Public assets cache directory
    'path' => '/var/www/example.com/htdocs/public/assets/cache',

    // Public cache directory permissions (octal)
    // You need to prefix mode with a zero (0)
    // Use -1 to disable chmod
    'path_chmod' => 0750,

    // The public url base path
    'url_base_path' => 'assets/cache/',

    // Internal cache settings
    //
    // The main cache directory
    // Use '' (empty string) to disable the internal cache
    'cache_path' => '/var/www/example.com/htdocs/temp',

    // Used as the subdirectory of the cache_path directory,
    // where cache items will be stored
    'cache_name' => 'assets-cache',

    // The lifetime (in seconds) for cache items
    // With a value 0 causing items to be stored indefinitely
    'cache_lifetime' => 0,

    // Enable JavaScript and CSS compression
    // 1 = on, 0 = off
    'minify' => 1
];

// Register asset extension
$engine->loadExtension(new PlatesAssetExtension(new AssetEngine($engine, $options)));

Usage

The page template

Template file: index.php, (*3)


<!DOCTYPE html>
<html lang="en">
    <head>
        <meta charset="utf-8">
        <base href="<?= $baseUrl; ?>" />
        <title>Demo</title>
        <?= $this->assets(['default.css', 'print.css'], ['inline' => true]); ?>
    </head>
    <body>
    <!-- content -->

    <!-- JavaScript assets -->
    <?= $this->assets(['mylib.js', 'page.js']); ?>
    </body>
</html>

Render a template

$engine = new League\Plates\Engine('/path/to/templates');

echo $engine->render('index', ['baseUrl' => '']);

The result

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="utf-8">
    <base href="" />
    <title>Demo</title>
    <style></style>
<style>@media print{.noprint{display:none}.navbar{visibility:hidden;display:none}.container{width:99%}.table{table-layout:fixed;width:99%;max-width:99%}}</style></head>
<body>



</body>
</html>

Parameters

  1. Parameter: $assets
Name Type Default Required Description
files array [] yes All assets (files) to be delivered to the browser. Plates Folders (myalias::myfile.js) are also supported.
  1. Parameter: $options
Name Type Default Required Description
inline bool false no Defines whether the browser downloads the assets inline or via URL.
minify bool true no Specifies whether JS/CSS compression is enabled or disabled.
name string file no Defines the output file name within the URL.

Slim 4 integration

For this example we use the PHP-DI package., (*4)

Add the container definition:, (*5)

<?php

use League\Plates\Engine;
use Odan\PlatesAsset\PlatesAssetExtension;
use Psr\Container\ContainerInterface;
use Slim\App;

// ...

return [
    // ...

    Engine::class => function (ContainerInterface $container) {
        $settings = $container->get('settings');
        $viewPath = $settings['plates']['path'];

        $engine = new Engine($viewPath);

        // The public url base path
        $baseUrl = $container->get(App::class)->getBasePath();
        $engine->addData(['baseUrl' => $baseUrl]);

        $options['url_base_path'] = $basePath;

        $engine->loadExtension(new PlatesAssetExtension(new AssetEngine($engine, $options)));

        return $engine;
    },
];

Render the template and write content to the response stream:, (*6)

$response->withHeader('Content-Type', 'text/html; charset=utf-8');

$response->getBody()->write($this->engine->render($name, $viewData));

return $response;

License

The MIT License (MIT). Please see License File for more information., (*7)

The Versions

17/11 2017

dev-master

9999999-dev http://github.com/odan/plates-asset-cache

Caching and compression for Plates template assets (JavaScript and CSS).

  Sources   Download

MIT

The Requires

 

The Development Requires

css cache javascript assets minify plates

17/11 2017

1.0.0

1.0.0.0 http://github.com/odan/plates-asset-cache

Caching and compression for Plates template assets (JavaScript and CSS).

  Sources   Download

MIT

The Requires

 

The Development Requires

css cache javascript assets minify plates

26/04 2017

0.3.5

0.3.5.0 http://github.com/odan/plates-asset-cache

Caching and compression for Plates template assets (JavaScript and CSS).

  Sources   Download

MIT

The Requires

 

The Development Requires

css cache javascript assets minify plates

25/04 2017

0.3.4

0.3.4.0 http://github.com/odan/plates-asset-cache

Caching and compression for Plates template assets (JavaScript and CSS).

  Sources   Download

MIT

The Requires

 

The Development Requires

css cache javascript assets minify plates

21/02 2017

v0.3.3

0.3.3.0 http://github.com/odan/plates-asset-cache

Caching and compression for Plates template assets (JavaScript and CSS).

  Sources   Download

MIT

The Requires

 

The Development Requires

css cache javascript assets minify plates

12/02 2017

0.3.2

0.3.2.0 http://github.com/odan/plates-asset-cache

Caching and compression for Plates template assets (JavaScript and CSS).

  Sources   Download

MIT

The Requires

 

The Development Requires

css cache javascript assets minify plates

08/02 2017

0.3.1

0.3.1.0 http://github.com/odan/plates-asset-cache

Caching and compression for Plates template assets (JavaScript and CSS).

  Sources   Download

MIT

The Requires

 

The Development Requires

css cache javascript assets minify plates

06/02 2017

0.3.0

0.3.0.0 http://github.com/odan/plates-asset-cache

Caching and compression for Plates template assets (JavaScript and CSS).

  Sources   Download

MIT

The Requires

 

The Development Requires

css cache javascript assets minify plates

02/02 2017

0.2.0

0.2.0.0 http://github.com/odan/plates-asset-cache

Caching and compression for Plates template assets (JavaScript and CSS).

  Sources   Download

MIT

The Requires

 

The Development Requires

css cache javascript assets minify plates

28/12 2016

0.1.5

0.1.5.0 http://github.com/odan/plates-asset-cache

Caching and compression for Plates template assets (JavaScript and CSS).

  Sources   Download

MIT

The Requires

 

The Development Requires

css cache javascript assets minify plates

05/12 2016

dev-analysis-8jJwWJ

dev-analysis-8jJwWJ http://github.com/odan/plates-asset-cache

Caching and compression for Plates template assets (JavaScript and CSS).

  Sources   Download

MIT

The Requires

 

The Development Requires

css cache javascript assets minify plates

09/07 2016

0.1.4

0.1.4.0 http://github.com/odan/plates-asset-cache

Caching and compression for Plates template assets (JavaScript and CSS).

  Sources   Download

MIT

The Requires

 

The Development Requires

css cache javascript assets minify plates

28/02 2016

0.1.3

0.1.3.0 http://github.com/odan/plates-asset-cache

Caching and compression for Plates template assets (JavaScript and CSS).

  Sources   Download

MIT

The Requires

 

The Development Requires

css cache javascript assets minify plates

19/02 2016

0.1.2

0.1.2.0 http://github.com/odan/plates-asset-cache

Caching and compression for Plates template assets (JavaScript and CSS).

  Sources   Download

MIT

The Requires

 

The Development Requires

css cache javascript assets minify plates

06/09 2015

0.1.1

0.1.1.0 http://github.com/odan/plates-asset-cache

Caching and compression for Plates template assets (JavaScript and CSS).

  Sources   Download

MIT

The Requires

 

The Development Requires

css cache javascript assets minify plates