Exemplo n.º 1
0
 public function getChildren(AssetFactory $factory, $content, $loadPath = null)
 {
     $children = array();
     $includePaths = $this->includePaths;
     if (null !== $loadPath && !in_array($loadPath, $includePaths)) {
         array_unshift($includePaths, $loadPath);
     }
     if (empty($includePaths)) {
         return $children;
     }
     foreach (CssUtils::extractImports($content) as $reference) {
         if ('.css' === substr($reference, -4)) {
             continue;
         }
         // the reference may or may not have an extension or be a partial
         if (pathinfo($reference, PATHINFO_EXTENSION)) {
             $needles = array($reference, $this->partialize($reference));
         } else {
             $needles = array($reference . '.scss', $this->partialize($reference) . '.scss');
         }
         foreach ($includePaths as $includePath) {
             foreach ($needles as $needle) {
                 if (file_exists($file = $includePath . '/' . $needle)) {
                     $child = $factory->createAsset($file, array(), array('root' => $includePath));
                     $children[] = $child;
                     $child->load();
                     $children = array_merge($children, $this->getChildren($factory, $child->getContent(), $includePath));
                 }
             }
         }
     }
     return $children;
 }
Exemplo n.º 2
0
    public function testExtractImports()
    {
        // These don't work yet (todo):
        // @import url("fineprint.css") print;
        // @import url("bluish.css") projection, tv;
        // @import url('landscape.css') screen and (orientation:landscape);
        $content = <<<CSS
@import 'custom.css';
@import "common.css" screen, projection;
body { background: url(../images/bg.gif); }
CSS;
        $expected = array('common.css', 'custom.css');
        $actual = CssUtils::extractImports($content);
        $this->assertEquals($expected, array_intersect($expected, $actual), '::extractImports() returns all expected URLs');
        $this->assertEquals(array(), array_diff($actual, $expected), '::extractImports() does not return unexpected URLs');
    }
Exemplo n.º 3
0
 public function getChildren(AssetFactory $factory, $content, $loadPath = null)
 {
     $sc = new \scssc();
     $sc->addImportPath($loadPath);
     foreach ($this->importPaths as $path) {
         $sc->addImportPath($path);
     }
     $children = array();
     foreach (CssUtils::extractImports($content) as $match) {
         $file = $sc->findImport($match);
         if ($file) {
             $children[] = $child = $factory->createAsset($file, array(), array('root' => $loadPath));
             $child->load();
             $children = array_merge($children, $this->getChildren($factory, $child->getContent(), $loadPath));
         }
     }
     return $children;
 }
Exemplo n.º 4
0
 public function getChildren(AssetFactory $factory, $content, $loadPath = null)
 {
     $loadPaths = $this->loadPaths;
     if ($loadPath) {
         array_unshift($loadPaths, $loadPath);
     }
     if (!$loadPaths) {
         return array();
     }
     $children = array();
     foreach (CssUtils::extractImports($content) as $reference) {
         if ('.css' === substr($reference, -4)) {
             // skip normal css imports
             // todo: skip imports with media queries
             continue;
         }
         // the reference may or may not have an extension or be a partial
         if (pathinfo($reference, PATHINFO_EXTENSION)) {
             $needles = array($reference, self::partialize($reference));
         } else {
             $needles = array($reference . '.scss', $reference . '.sass', self::partialize($reference) . '.scss', self::partialize($reference) . '.sass');
         }
         foreach ($loadPaths as $loadPath) {
             foreach ($needles as $needle) {
                 if (file_exists($file = $loadPath . '/' . $needle)) {
                     $coll = $factory->createAsset($file, array(), array('root' => $loadPath));
                     foreach ($coll as $leaf) {
                         /** @var $leaf AssetInterface */
                         $leaf->ensureFilter($this);
                         $children[] = $leaf;
                         goto next_reference;
                     }
                 }
             }
         }
         next_reference:
     }
     return $children;
 }