Esempio n. 1
0
 /**
  * Prints the HTML for CSS resources
  *
  * @param string $collectionName the name of the collection
  *
  * @return string the result of the collection
  **/
 public function outputCss($collectionName = null)
 {
     $collection = $this->collection($collectionName);
     if ($collection->getJoin()) {
         $filename = $collection->getTargetPath();
         if (file_exists($filename)) {
             $time = 0;
             foreach ($collection->getResources() as $resource) {
                 $tmp = filemtime($resource->getRealTargetPath());
                 if ($tmp > $time) {
                     $time = $tmp;
                 }
             }
             // If created
             if (filemtime($filename) > $time) {
                 $collection->setTargetUri($collection->getTargetUri() . '?' . filemtime($filename));
                 return Tag::stylesheetLink($collection->getTargetUri());
             }
         }
         // Else CREATE
         $res = parent::outputCss($collectionName);
         return $res;
     }
     return parent::outputCss($collectionName);
 }
Esempio n. 2
0
 /**
  * {@inheritdoc}
  */
 public function addJs($path, $local = true, $filter = null, $attributes = null)
 {
     foreach ($this->getJs()->getResources() as $resource) {
         if ($resource->getPath() === $path) {
             return $this;
         }
     }
     return parent::addJs($path, $local, $filter, $attributes);
 }
Esempio n. 3
0
 /**
  * Tests custom filters
  *
  * @issue   1198
  * @author  Volodymyr Kolesnykov <*****@*****.**>
  * @since   2013-09-15
  */
 public function testAssetsFilterChainCustomFilterWithCssmin()
 {
     $this->specify("The chaining a custom filter with cssmin does not return the correct results", function () {
         $fileName = $this->tester->getNewFileName('assets_', 'css');
         $assets = new Manager();
         $assets->useImplicitOutput(false);
         $css = $assets->collection('css');
         $css->setTargetPath(PATH_CACHE . $fileName);
         $css->addCss(PATH_DATA . 'assets/1198.css');
         $css->addFilter(new UppercaseFilter());
         $css->addFilter(new TrimFilter());
         $css->join(true);
         $assets->outputCss('css');
         $expected = 'A{TEXT-DECORATION:NONE;}B{FONT-WEIGHT:BOLD;}';
         $actual = file_get_contents(PATH_CACHE . $fileName);
         $this->tester->cleanFile(PATH_CACHE, $fileName);
         expect($actual)->equals($expected);
     });
 }
Esempio n. 4
0
 /**
  * Print output Js
  *
  * @param string $name
  */
 public function outputJs($name = null)
 {
     parent::outputJs($name);
     if ($name == null) {
         echo implode("", $this->jsDeclaration);
     } else {
         if (method_exists($this->_collections["{$name}"], "outputJs")) {
             $this->_collections["{$name}"]->outputJs();
         }
     }
 }
Esempio n. 5
0
 /**
  *
  * @param \Phalcon\DI $di
  */
 public function registerServices($di)
 {
     Admin::instance();
     require __DIR__ . '/../../../../phad/phad.php';
     $di['phadConfig'] = function () {
         $config = (require __DIR__ . '/../../../../phad-config.php');
         return new Config($config);
     };
     $di['view'] = function () {
         $view = new ViewEngine();
         $view->setViewsDir(__DIR__ . '/Views/');
         $view->setLayoutsDir('Layouts/');
         $view->setPartialsDir('Partials/');
         return $view;
     };
     $di['viewSimple'] = function () {
         $view = new Simple();
         $view->setViewsDir(__DIR__ . '/Views/');
         return $view;
     };
     $di['flashSession'] = function () {
         $flashClasses = ['error' => 'alert alert-danger', 'success' => 'alert alert-success', 'notice' => 'alert alert-info', 'warning' => 'alert alert-warning'];
         return new FlashSession($flashClasses);
     };
     $di['session'] = function () {
         $session = new Session();
         $session->start();
         return $session;
     };
     $di['phadAuth'] = function () {
         return new Auth();
     };
     $di['assets'] = function () use($di) {
         $options = ['sourceBasePath' => __DIR__ . '/Assets/', 'targetBasePath' => __DIR__ . '/../../../../public/backend-assets/'];
         $assets = new AssetsManager($options);
         $assets->collection('backend_css')->setTargetPath('final.css')->setTargetUri('backend-assets/final.css')->addCss('bootstrap/css/bootstrap.min.css')->addCss('css/styles.css')->join(true)->addFilter(new AssetsNullFilter());
         $assets->collection('backend_js')->setTargetPath('final.js')->setTargetUri('backend-assets/final.js')->addJs('bootstrap/js/bootstrap.min.js')->addJs('js/custom.js')->join(true)->addFilter(new AssetsNullFilter());
         return $assets;
     };
 }
Esempio n. 6
0
 public function loadAssets($assets, $isAdmin = false)
 {
     $prefix = $isAdmin ? 'admin-' : '';
     if (isset($this->_loadedThemes[$prefix])) {
         return $this;
     }
     $this->_loadedThemes[$prefix] = true;
     $assetsOptions = $this->config['options']['assets_options'];
     $applyFilter = $assetsOptions['apply_filter'];
     // The base path, usually the public directory
     $basePath = $assetsOptions['base_path'];
     // The assets dir inside base path
     $resourcePath = '/' . $assetsOptions['assets_dir'] . '/';
     $compiledPath = '/' . $assetsOptions['compiled_dir'] . '/';
     foreach ($assets as $collectionName => $resources) {
         $resourceType = substr($collectionName, strrpos($collectionName, '-') + 1);
         $collectionName = $prefix . $collectionName;
         $collection = $this->assets->collection($collectionName);
         $collection->setSourcePath($basePath);
         $contentHash = '';
         switch ($resourceType) {
             case 'css':
                 foreach ($resources as $item) {
                     $isLocal = !isHttpUrl($item);
                     $resource = new Css($isLocal ? $resourcePath . $item : $item, $isLocal);
                     $applyFilter and $contentHash = $resource->concatenateHash($contentHash);
                     $collection->add($resource);
                 }
                 $applyFilter and $collection->addFilter(new Cssmin());
                 break;
             case 'js':
                 foreach ($resources as $item) {
                     $isLocal = !isHttpUrl($item);
                     $resource = new Js($isLocal ? $resourcePath . $item : $item, $isLocal);
                     $applyFilter and $contentHash = $resource->concatenateHash($contentHash);
                     $collection->add($resource);
                 }
                 $applyFilter and $collection->addFilter(new Jsmin());
                 break;
         }
         $targetUri = $compiledPath . substr($collectionName, 0, -1 - strlen($resourceType));
         $contentHash and $targetUri .= '.' . $contentHash;
         $targetUri .= '.' . $resourceType;
         $collection->setTargetPath($basePath . $targetUri)->setTargetUri(url($targetUri));
     }
     return $this;
 }
Esempio n. 7
0
 /**
  * Prints the HTML for CSS resources.
  *
  * @param string $collectionName the name of the collection
  *
  * @return string
  **/
 public function outputCss($collectionName = self::DEFAULT_COLLECTION_CSS)
 {
     $remote = $this->_config->application->assets->get('remote');
     $collection = $this->collection($collectionName);
     if (!$remote && $collection->getJoin()) {
         $local = $this->_config->application->assets->get('local');
         $lifetime = $this->_config->application->assets->get('lifetime', 0);
         $filepath = $local . self::GENERATED_STORAGE_PATH . ($filename = $filename = $this->getCollectionFileName($collection, self::FILENAME_PATTERN_CSS));
         $collection->setTargetPath($filepath)->setTargetUri($filepath);
         if ($this->_cache->exists($filename)) {
             return Tag::stylesheetLink($collection->getTargetUri());
         }
         $res = parent::outputCss($collectionName);
         $this->_cache->save($filename, true, $lifetime);
         return $res;
     }
     return parent::outputCss($collectionName);
 }
Esempio n. 8
0
 public function outputInlineJs($collectionName = null)
 {
     return parent::outputInlineJs($collectionName);
 }
Esempio n. 9
0
 /**
  *
  * @param type $options
  */
 protected function initAssets($options = [])
 {
     $this->_di->setShared('assets', function () {
         $assets = new AssetsManager();
         $assets->collection('headerCss');
         $assets->collection('headerJs');
         $assets->collection('footerJs');
         return $assets;
     });
 }
Esempio n. 10
0
 public function exists($id)
 {
     return parent::exists($id);
 }
Esempio n. 11
0
/**
 * The FactoryDefault Dependency Injector automatically register the right services providing a full stack framework
 */
$di = new FactoryDefault();
$di->set('router', function () {
    $router = new Router();
    $router->setUriSource(Router::URI_SOURCE_SERVER_REQUEST_URI);
    return $router;
});
$di->set('flash', function () {
    $flash = new flash();
    $flash->setCssclasses(array('success' => 'alert alert-success', 'warning' => 'alert alert-warning', 'error' => 'alert alert-danger'));
    return $flash;
});
$di->set('assets', function () use($config) {
    $manager = new Manager();
    foreach ($config->vendorAssets as $k => $v) {
        if ($k == 'css') {
            foreach ($v as $alias => $file) {
                $manager->collection('css')->addCss($file);
            }
        } else {
            foreach ($v as $alias => $file) {
                $manager->collection('js')->addJs($file);
            }
        }
    }
    $manager->collection('js')->setPrefix('/public/vendor')->setLocal(true);
    $manager->collection('css')->setPrefix('/public/vendor')->setLocal(true);
    return $manager;
});
Esempio n. 12
0
    return $session;
};
/**
 * Setting up the view component
 */
$di['view'] = function () {
    $view = new View();
    $view->registerEngines(array(".volt" => function ($view, $di) {
        $volt = new VoltEngine($view, $di);
        $volt->setOptions(array("compiledPath" => __DIR__ . '/../cache/volt/', "compiledSeparator" => "-"));
        return $volt;
    }));
    return $view;
};
$di['assets'] = function () {
    $assets = new AssetsManager();
    $assets->addJs('//ajax.googleapis.com/ajax/libs/jquery/1.9.1/jquery.min.js', false)->addJs('//netdna.bootstrapcdn.com/bootstrap/3.0.3/js/bootstrap.min.js', false);
    $assets->addCss('css/bootstrap.min.css')->addCss('css/style.css');
    return $assets;
};
$di['router'] = function () {
    //Use the annotations router
    $router = new Router(false);
    //Read the resources from file
    require __DIR__ . '/routes.php';
    return $router;
};
$di['modelsManager'] = function () {
    $eventsManager = new EventsManager();
    $modelsManager = new ModelsManager();
    $modelsManager->setEventsManager($eventsManager);
Esempio n. 13
0
 public function __construct($options = null)
 {
     parent::__construct($options);
     $this->set('inline-css', new Collection());
     $this->set('inline-js', new Collection());
 }
Esempio n. 14
0
 public function collection($name)
 {
     $collection = parent::collection($name);
     $collection->setSourcePath($this->getBasePath() . $this->getAssetsDir());
     $collection->setPrefix($this->getBasePath() . $this->getAssetsDir());
     return $collection;
 }
Esempio n. 15
0
    $view = new View();
    $view->setViewsDir(APP_PATH . '/views/');
    $view->registerEngines(array('.volt' => function ($view, $di) {
        $volt = new Volt($view, $di);
        $volt->setOptions(array('compiledPath' => APP_PATH . '/cache/volt/', 'compiledSeparator' => '_'));
        return $volt;
    }));
    return $view;
};
$di['url'] = function () {
    $url = new UrlResolver();
    $url->setBaseUri('/dasshy/');
    return $url;
};
$di['assets'] = function () {
    $assets = new AssetsManager();
    $assets->addJs('//ajax.googleapis.com/ajax/libs/jquery/1.9.1/jquery.min.js', false)->addJs('//netdna.bootstrapcdn.com/twitter-bootstrap/2.3.1/js/bootstrap.min.js', false);
    return $assets;
};
/**
 * Flash service with custom CSS classes
 */
$di['flash'] = function () {
    return new Flash(array('error' => 'alert alert-error', 'success' => 'alert alert-success', 'notice' => 'alert alert-info'));
};
/**
 * Flash service with custom CSS classes
 */
$di['flashDirect'] = function () {
    return new FlashDirect(array('error' => 'alert alert-error', 'success' => 'alert alert-success', 'notice' => 'alert alert-info'));
};
Esempio n. 16
0
 public function requireJs($path, $local = true, $filter = true, $attributes = null)
 {
     if (!array_key_exists($path, $this->stackJs)) {
         $this->stackJs[$path] = array('local' => $local, 'filter' => $filter, 'attributes' => $attributes);
         parent::addJs($path, $local, $filter, $attributes);
     }
 }