Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Nette 2.1@rc compatibility

  • Loading branch information...
commit c007d5a331b2c0abb5fc629c24e588fdd800f4b8 1 parent ba1d85b
@ondrs ondrs authored fprochazka committed
View
21 README.md
@@ -45,16 +45,12 @@ Template:
Example with Nette Framework extension used
-------------------------------------------
-Extension is registered in bootstrap.php:
-
-```php
-$webloaderExtension = new \WebLoader\Nette\Extension();
-$webloaderExtension->install($configurator);
-```
-
-Configuration in config.neon:
+Configuration in `app/config/config.neon`:
```html
+extensions:
+ webloader: WebLoader\Nette\Extension
+
services:
wlCssFilter: WebLoader\Filter\CssUrlsFilter(%wwwDir%)
lessFilter: WebLoader\Filter\LessFilter
@@ -79,7 +75,14 @@ webloader:
- web.js
```
-BasePresenter.php:
+For older versions of Nette, you have to register the extension in `app/bootstrap.php`:
+
+```php
+$webloaderExtension = new \WebLoader\Nette\Extension();
+$webloaderExtension->install($configurator);
+```
+
+Usage in `app/presenters/BasePresenter.php`:
```php
public function createComponentCss()
View
2  WebLoader/IFileCollection.php
@@ -3,8 +3,6 @@
namespace WebLoader;
/**
- * IFileCollection
- *
* @author Jan Marek
*/
interface IFileCollection
View
27 WebLoader/Nette/Extension.php
@@ -2,10 +2,25 @@
namespace WebLoader\Nette;
+use Nette\Configurator;
+use Nette\DI\Compiler;
+use Nette\DI\CompilerExtension;
+use Nette\DI\Config\Helpers;
+use Nette\DI\ContainerBuilder;
+use Nette\Utils\Finder;
+
+if (!class_exists('Nette\DI\CompilerExtension')) {
+ class_alias('Nette\Config\CompilerExtension', 'Nette\DI\CompilerExtension');
+ class_alias('Nette\Config\Compiler', 'Nette\DI\Compiler');
+ class_alias('Nette\Config\Helpers', 'Nette\DI\Config\Helpers');
+ class_alias('Nette\Config\Configurator', 'Nette\Configurator');
+}
+
+
/**
* @author Jan Marek
*/
-class Extension extends \Nette\Config\CompilerExtension
+class Extension extends CompilerExtension
{
const EXTENSION_NAME = 'webloader';
@@ -65,7 +80,7 @@ public function loadConfiguration()
}
}
- private function addWebLoader(\Nette\DI\ContainerBuilder $builder, $name, $config)
+ private function addWebLoader(ContainerBuilder $builder, $name, $config)
{
$filesServiceName = $this->prefix($name . 'Files');
@@ -76,7 +91,7 @@ private function addWebLoader(\Nette\DI\ContainerBuilder $builder, $name, $confi
foreach ($config['files'] as $file) {
// finder support
if (is_array($file) && isset($file['files']) && (isset($file['in']) || isset($file['from']))) {
- $finder = \Nette\Utils\Finder::findFiles($file['files']);
+ $finder = Finder::findFiles($file['files']);
if (isset($file['exclude'])) {
$finder->exclude($file['exclude']);
@@ -119,11 +134,11 @@ private function addWebLoader(\Nette\DI\ContainerBuilder $builder, $name, $confi
// todo css media
}
- public function install(\Nette\Config\Configurator $configurator)
+ public function install(Configurator $configurator)
{
$self = $this;
- $configurator->onCompile[] = function ($configurator, $compiler) use ($self) {
- $compiler->addExtension($self::EXTENSION_NAME, $self);
+ $configurator->onCompile[] = function ($configurator, Compiler $compiler) use ($self) {
+ $compiler->addExtension($self::EXTENSION_NAME, $self);
};
}
View
2  composer.json
@@ -16,7 +16,7 @@
}
},
"require": {
- "nette/nette": "~2.0"
+ "nette/nette": "~2.0@rc"
},
"suggest": {
"leafo/lessphp": "Lessphp is a composer for LESS written in PHP."
View
12 tests/Nette/ExtensionTest.php
@@ -17,7 +17,7 @@ private function prepareContainer($class, $configFiles)
unlink((string) $file);
}
- $configurator = new \Nette\Config\Configurator();
+ $configurator = new \Nette\Configurator();
$configurator->setTempDirectory($tempDir);
foreach ($configFiles as $file) {
@@ -41,13 +41,13 @@ private function prepareContainer($class, $configFiles)
public function testJsCompilerService()
{
$this->prepareContainer('JsCompilerServiceContainer', array(__DIR__ . '/../fixtures/extension.neon'));
- $this->assertInstanceOf('WebLoader\Compiler', $this->container->webloader->jsDefaultCompiler);
+ $this->assertInstanceOf('WebLoader\Compiler', $this->container->getService('webloader.jsDefaultCompiler'));
}
public function testExcludeFiles()
{
$this->prepareContainer('ExcludeFilesContainer', array(__DIR__ . '/../fixtures/extension.neon'));
- $files = $this->container->webloader->jsExcludeCompiler->getFileCollection()->getFiles();
+ $files = $this->container->getService('webloader.jsExcludeCompiler')->getFileCollection()->getFiles();
$this->assertTrue(in_array(realpath(__DIR__ . '/../fixtures/a.txt'), $files));
$this->assertFalse(in_array(realpath(__DIR__ . '/../fixtures/dir/one.js'), $files));
@@ -59,7 +59,7 @@ public function testJoinFilesOn()
__DIR__ . '/../fixtures/extension.neon',
__DIR__ . '/../fixtures/extensionJoinFilesTrue.neon',
));
- $this->assertTrue($this->container->webloader->jsDefaultCompiler->getJoinFiles());
+ $this->assertTrue($this->container->getService('webloader.jsDefaultCompiler')->getJoinFiles());
}
public function testJoinFilesOff()
@@ -68,7 +68,7 @@ public function testJoinFilesOff()
__DIR__ . '/../fixtures/extension.neon',
__DIR__ . '/../fixtures/extensionJoinFilesFalse.neon',
));
- $this->assertFalse($this->container->webloader->jsDefaultCompiler->getJoinFiles());
+ $this->assertFalse($this->container->getService('webloader.jsDefaultCompiler')->getJoinFiles());
}
public function testJoinFilesOffInOneService()
@@ -76,7 +76,7 @@ public function testJoinFilesOffInOneService()
$this->prepareContainer('JoinFilesOffInOneServiceContainer', array(
__DIR__ . '/../fixtures/extension.neon',
));
- $this->assertFalse($this->container->webloader->cssJoinOffCompiler->getJoinFiles());
+ $this->assertFalse($this->container->getService('webloader.cssJoinOffCompiler')->getJoinFiles());
}
}
Please sign in to comment.
Something went wrong with that request. Please try again.