Example #1
0
 /**
  * Initialize class and forge a Sprockets Instance
  */
 public function __construct()
 {
     !\Package::loaded('sprockets') and \Package::load('sprockets');
     // When in console mode, DOCROOT is the path to the project root, not the public/
     $config = array('asset_compile_dir' => DOCROOT . 'public/assets/', 'force_minify' => true);
     static::$sprockets = \Sprockets::forge('default', $config);
 }
Example #2
0
 /**
  * Test the Sprockets package with a separate file for each compiler and directive, non-minified and minified
  */
 public function test_sprockets()
 {
     for ($i = 0; $i < count($this->config); $i++) {
         $sprockets = Sprockets::forge('Test_Sprockets' . $i, $this->config[$i]);
         $js = array();
         $css = array();
         # require directive for Sprockets::js
         $js[] = $sprockets->js('test-require-js.js');
         $js[] = $sprockets->js('test-require-coffee.coffee');
         # require_directory for Sprockets::js
         $js[] = $sprockets->js('test-require_directory-js.js');
         $js[] = $sprockets->js('test-require_directory-coffee.coffee');
         # require_tree for Sprockets::js
         $js[] = $sprockets->js('test-require_tree-js.js');
         $js[] = $sprockets->js('test-require_tree-coffee.coffee');
         # all directives for Sprockets::js
         $js[] = $sprockets->js('test-all-directives-js.js');
         $js[] = $sprockets->js('test-all-directives-coffee.coffee');
         # require directive for Sprockets::css
         $css[] = $sprockets->css('test-require-css.css');
         $css[] = $sprockets->css('test-require-scss.scss');
         $css[] = $sprockets->css('test-require-less.less');
         # require_directory directive for Sprockets::css
         $css[] = $sprockets->css('test-require_directory-css.css');
         $css[] = $sprockets->css('test-require_directory-scss.scss');
         $css[] = $sprockets->css('test-require_directory-less.less');
         # require_tree directive for Sprockets::css
         $css[] = $sprockets->css('test-require_tree-css.css');
         $css[] = $sprockets->css('test-require_tree-scss.scss');
         $css[] = $sprockets->css('test-require_tree-less.less');
         # all directives for Sprockets::css
         $css[] = $sprockets->css('test-all-directives-css.css');
         $css[] = $sprockets->css('test-all-directives-scss.scss');
         $css[] = $sprockets->css('test-all-directives-less.less');
         foreach ($js as $js) {
             $doc = new \DOMDocument();
             $doc->loadHTML($js);
             $node = $doc->getElementsByTagName("script");
             foreach ($node as $node) {
                 $file = $node->getAttribute("src");
             }
             $file = str_replace(\Uri::base(false), "", $file);
             $this->assertFileExists(DOCROOT . $file);
         }
         foreach ($css as $css) {
             $doc = new \DOMDocument();
             $doc->loadHTML($css);
             $node = $doc->getElementsByTagName("link");
             foreach ($node as $node) {
                 $file = $node->getAttribute("href");
             }
             $file = str_replace(\Uri::base(false), "", $file);
             $this->assertFileExists(DOCROOT . $file);
         }
     }
 }