2017 © Pedro PelĆ”ez
 

library assets

Support mtime for assets on development machine.

image

h4kuna/assets

Support mtime for assets on development machine.

  • Thursday, September 28, 2017
  • by h4kuna
  • Repository
  • 1 Watchers
  • 4 Stars
  • 621 Installations
  • PHP
  • 0 Dependents
  • 0 Suggesters
  • 1 Forks
  • 0 Open issues
  • 7 Versions
  • 15 % Grown

The README.md

Abandoned

try 68publishers/asset, (*1)

Build Status Downloads this Month Latest stable Coverage Status, (*2)

If you need the browser to automatically invalid it's cache, use this extension., (*3)

Install via composer:, (*4)

$ composer require h4kuna/assets

Changelog

  • 1.1.0 nothing required, update nette 3.0
  • 1.0.0 supports PHP 7.1+ (strict types)
  • 0.1.4 0.1.5 newer versions support PHP of version 5.6 and higher
  • 0.1.3 supports PHP 5.3

How to use

For first step you only need to register the extension, other parameters are optional. You have available the new filter asset automatically., (*5)

extensions:
    assets: h4kuna\Assets\DI\AssetsExtension

assets:
    # required nothing

    # optional
    wwwDir: %wwwDir%
    debugMode: %debugMode%
    tempDir: %tempDir%
    wwwTempDir: %wwwDir%/temp # here is place where move assets from 3rd library (from vendor/ etc.)
    externalAssets:
        - %appDir%/../vendor/nette/nette.js # save to %wwwTempDir%/nette.js
        'ext/nette2.4.js': %appDir%/../vendor/nette/nette.js # save to %wwwTempDir%/ext/nette2.4.js

        # download from external source, this is experimental!
        - http://example.com/foo.js # save to %wwwTempDir%/foo.js
        'sha256-secure-token': http://example.com/foo.js # check if is right file

Advantages:

  • $basePath is not needed
  • path is relative to your wwwDir
  • cache is built when new file found, or if you remove %tempDir%/cache/_assets
  • behavior is the same in production and development environment
<link rel="stylesheet" href="{='css/main.css'|asset}">
<script src="{='js/main.js'|asset}"></script>

Example output: ?file mtime., (*6)

<link rel="stylesheet" href="/css/main.css?123456">
<script src="/js/main.js?456789"></script>

Printing absolute path to the template can be anabled using double slash:, (*7)

<link rel="stylesheet" href="{='//css/main.css'|asset}">

Assets

Here is an object that can have dependency anything and collect css and js files for render to template., (*8)

/* @var $assets \h4kuna\Assets\Assets */
$assets->addJs('ext/nette2.4.js', ['async' => TRUE]);
echo (string) $assets->renderJs();

render this, (*9)

<script src="/temp/ext/nette2.4.js?456789" async></script>

Custom cache builder - advanced usege

This creates the cache in the compile time. By default, assets cache is build on the fly:, (*10)

assetsExtension:
    cacheBuilder: \CacheBuilder

Use prepared interface:, (*11)

class CacheBuilder implements \h4kuna\Assets\DI\ICacheBuilder
{
    public function create(\h4kuna\Assets\CacheAssets $cache, $wwwDir)
    {
        $finder = Nette\Utils\Finder::findFiles('*')->in($wwwDir . '/config');
        foreach ($finder as $file) {
            /* @var $file \SplFileInfo */
            $cache->load(self::replaceSlashOnWindows($file));
        }
    }


    private static function replaceSlashOnWindows(SplFileInfo $file)
    {
        static $isWindows;
        if ($isWindows === NULL) {
            $isWindows = strtoupper(substr(PHP_OS, 0, 3)) === 'WIN';
        }

        if ($isWindows) {
            return str_replace('\\', '/', $file->getPathname());
        }
        return $file->getPathname();
    }
}

The Versions

28/09 2017

dev-master

9999999-dev https://github.com/h4kuna/assets

Support mtime for assets on development machine.

  Sources   Download

MIT

The Requires

 

The Development Requires

by Milan Matějček

28/09 2017

0.1.5

0.1.5.0 https://github.com/h4kuna/assets

Support mtime for assets on development machine.

  Sources   Download

MIT

The Requires

 

The Development Requires

by Milan Matějček

10/06 2017

0.1.4

0.1.4.0 https://github.com/h4kuna/assets

Support mtime for assets on development machine.

  Sources   Download

MIT

The Requires

 

The Development Requires

by Milan Matějček

24/04 2017

0.1.3

0.1.3.0 https://github.com/h4kuna/assets

Support mtime for assets on development machine.

  Sources   Download

MIT

The Requires

 

The Development Requires

by Milan Matějček

19/04 2017

0.1.2

0.1.2.0 https://github.com/h4kuna/assets

Support mtime for assets on development machine.

  Sources   Download

MIT

The Requires

 

The Development Requires

by Milan Matějček

18/04 2017

0.1.1

0.1.1.0 https://github.com/h4kuna/assets

Support mtime for assets on development machine.

  Sources   Download

MIT

The Requires

 

The Development Requires

by Milan Matějček

18/04 2017

0.1.0

0.1.0.0 https://github.com/h4kuna/assets

Support mtime for assets on development machine.

  Sources   Download

MIT

The Requires

 

The Development Requires

by Milan Matějček