Exemplo n.º 1
0
/**
 * @param null $collection
 * @param callable $definition
 * @return SimpleAsset\Manager|SimpleAsset\Collection
 */
function AssetManager($collection = null, Closure $definition = null)
{
    static $instance;
    if (!$instance instanceof Manager) {
        $instance = new Manager();
    }
    if ($collection) {
        if ($definition) {
            $instance->define($collection, $definition);
        } else {
            return $instance->getCollection($collection);
        }
    }
    return $instance;
}
Exemplo n.º 2
0
 public function testSmashWithUrlRewriter()
 {
     $manager = new Manager();
     $manager->setPublicRoot(__DIR__ . '/resources');
     $manager->define('test', function () {
         $this->style('/lesstest.less');
     });
     $s = new Smasher($manager, __DIR__ . '/workdir', 1);
     $urlRewriter = new UrlRewriter('http://example.com');
     $s->smash($urlRewriter);
     $this->assertTrue(file_exists(__DIR__ . '/workdir/test.css'));
     $content = file_get_contents(__DIR__ . '/workdir/test.css');
     $this->assertTrue(strpos($content, 'http://example.com') !== false);
     @unlink(__DIR__ . '/workdir/test.css');
 }
Exemplo n.º 3
0
 public function testRuntimeCollectionProxy()
 {
     Manager::registerGlobalFunction();
     AssetManager()->style('/foo.css');
     $assets = AssetManager()->getRuntimeCollection()->getAssets('style');
     $this->assertEquals(1, sizeof($assets));
 }
Exemplo n.º 4
0
 public function testImport()
 {
     $manager = new Manager();
     $manager->define('test', function () {
         $this->import('default', 'embedded');
         $this->style('/foo.css');
     });
     $manager->define('default', function () {
         $this->style('/default.css');
         $this->script('/default.js');
     });
     $manager->define('embedded', function () {
         $this->embeddedScript('var default = true;');
         $this->embeddedStyle('default { }');
     });
     $assets = $manager->getCollection('test')->getAssets();
     $this->assertEquals(2, count($assets['style']));
     $this->assertEquals(1, count($assets['script']));
     $this->assertEquals(1, count($assets['embeddedStyle']));
     $this->assertEquals(1, count($assets['embeddedScript']));
     $expectedAssets = ['style' => ['/default.css', '/foo.css'], 'script' => ['/default.js'], 'embeddedStyle' => ['default { }'], 'embeddedScript' => ['var default = true;']];
     foreach ($expectedAssets as $type => $typeAssets) {
         for ($c = 0; $c < count($assets); $c++) {
             $actualAsset = $assets[$type][$c];
             switch (get_class($actualAsset)) {
                 case 'SimpleAsset\\Style':
                 case 'SimpleAsset\\Script':
                     $this->assertEquals($typeAssets[$c], $actualAsset->getSrc());
                     break;
                 case 'SimpleAsset\\EmbeddedScript':
                     $this->assertEquals($typeAssets[$c], $actualAsset->getScript());
                     break;
                 case 'SimpleAsset\\EmbeddedStyle':
                     $this->assertEquals($typeAssets[$c], $actualAsset->getStyle());
                     break;
             }
         }
     }
 }
Exemplo n.º 5
0
 public function testRuntimeCollection()
 {
     $manager = new Manager();
     $manager->style('/foo.css');
     $manager->script('/foo.js');
     $manager->embeddedScript('var foo = false;');
     $manager->embeddedStyle('a { color: black; }');
     $output = $manager->renderScriptAssets();
     $expectedOutput = '<script type="text/javascript" src="/foo.js"></script>';
     $this->assertTrue(strpos($output, $expectedOutput) !== false);
     $expectedOutput = '<script type="text/javascript">' . "\n" . 'var foo = false;' . "\n" . '</script>';
     $this->assertTrue(strpos($output, $expectedOutput) !== false);
     $output = $manager->renderStyleAssets();
     $expectedOutput = '<link rel="stylesheet" type="text/css" href="/foo.css" media="all"/>';
     $this->assertTrue(strpos($output, $expectedOutput) !== false);
     $expectedOutput = '<style type="text/css">' . "\n" . 'a { color: black; }' . "\n" . '</style>';
     $this->assertTrue(strpos($output, $expectedOutput) !== false);
 }