Skip to content

Commit

Permalink
Update README.md
Browse files Browse the repository at this point in the history
  • Loading branch information
Machy8 authored Oct 14, 2017
1 parent 93c6787 commit acb93b5
Showing 1 changed file with 89 additions and 7 deletions.
96 changes: 89 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,15 +9,13 @@
- If you use Nette Framework - v2.3+

## Installation
**1 - Download the Web loader using composer:**
```
composer require machy8/webloader
```

**2 - Usage:**

*Typical:*
## Examples:

**Typical:**
```php
$webloader = \WebLoader\Compiler;
$webloader->addJsFilter('minifier', function(string $code) {
Expand All @@ -36,8 +34,92 @@ $webloader->createJsCollection('homepage')
'minifier'
]);

echo $webloader->render()->js('homepage', ['async' => TRUE]);
echo $webloader->getFilesCollectionRender()->js('homepage', ['async' => TRUE]);
```

*Nette framework:*
- TODO
**Nette framework:**

Configuration file
````YAML
extensions:
webloader: WebLoader\Bridges\Nette\WebLoaderExtension

webloader:
outputDir: path/to/webtemp
filesCollections:
critical:
cssFiles:
- path/to/file.css
cssLoadContent: TRUE
jsFiles:
- path/to/file.js

jsFilters:
- minify
jsLoadContent: TRUE

homepage:
cssFiles:
- path/to/file.css

jsFiles:
- path/to/file.js

cssFilters:
- urlFilter

filesCollectionsContainers:
homepage:
cssCollections:
- critical
- homepage

jsCollections:
- critical
- homepage
````

Presenter
````PHP

/**
* @var Compiler
*/
private $webLoader;


public function __construct(\WebLoader\Compiler $compiler)
{
$this->webLoader = $compiler;
}


public function beforeRender()
{
$this->webloader
->addCssFilter('urlFilter', function(string $code, string $file) {
$filter = \WebLoader\Filters\CssUrlFilter('path/to/webtemp');
return $filter->filter($code, $file);
})

->addJsFilter('minify', function(string $code) {
$closureCompiler = new \GoogleClosureCompiler\Compiler;
$response = $closureCompiler->setJsCode($code)->compile();

if ($response) {
return $response->getCompiledCode();
}

return $code;
});

$this->template->setParameters([
'webloaderContainersRender' => $this->webLoader->getFilesCollectionsContainerRender()->selectContainer('homepage')
]);
}
````

````LATTE
{$webloaderContainerRender->css()|noescape}
{$webloaderContainerRender->js()|noescape}
````

0 comments on commit acb93b5

Please sign in to comment.