Beispiel #1
0
<?php

// Parse the package.json file to get the version.
$package = json_decode(file_get_contents('package.json'));
define('VERSION', $package->version);
define('SPROCKETIZED', './public/js/tmp.' . VERSION . '.js');
define('PRODUCTION', './public/js/jsbin-' . VERSION . '.js');
// sprocketize the code in to jsbin.VERSION.js
require_once 'vendor/sprockets/sprocket.php';
echo "Sprocketizing...\n";
$filePath = './public/js/jsbin.js';
// prepare sprocket
$sprocket = new Sprocket($filePath, array('contentType' => '', 'baseUri' => '../public/js', 'baseFolder' => array('./public/js/vendor', './public/js/vendor/codemirror2'), 'assetFolder' => '..', 'debugMode' => true, 'autoRender' => false));
// concat complete
echo "Rendering...\n";
$js = $sprocket->render(true);
// write concat to js dir
echo "Writing concatenated file...\n";
file_put_contents(SPROCKETIZED, $js);
// google compile in to jsbin.VERSION.js
echo "Google compiler compressing...\n";
system('java -jar "./vendor/compiler.jar" --js="' . SPROCKETIZED . '" --js_output_file="' . PRODUCTION . '" --warning_level=QUIET');
unlink(SPROCKETIZED);
echo "Compressed: " . PRODUCTION . "\nFile size: " . filesize(PRODUCTION) . " bytes.\n";
Beispiel #2
0
<?php

require_once 'config.php';
require_once 'lib/sprockets/sprocket.php';
// get path from request
$filePath = preg_replace('/\\?.*/', '', $_SERVER['REQUEST_URI']);
// prepare sprocket
$sprocket = new Sprocket($filePath, array('contentType' => 'application/x-javascript', 'baseUri' => '../js', 'baseFolder' => '/js', 'assetFolder' => '..', 'debugMode' => OFFLINE ? true : false, 'autoRender' => false));
// change base folder based on extension
switch ($sprocket->fileExt) {
    case 'css':
        $sprocket->setContentType('text/css')->setBaseFolder('/css');
        break;
    default:
    case 'js':
        $sprocket->setBaseFolder(array('./js/vendor', './js/vendor/codemirror'));
        break;
}
// having to hack the source path to get it work properly.
$sprocket->filePath = '.' . str_replace(VERSION . '/', '', $sprocket->filePath);
// tada!
$sprocket->render();
 /**
  * Builds an HTML Textarea (multi-line text field)
  *
  * <textarea name="$name">$content</textarea>
  *
  * @param string The name of the textarea tag
  * @param string The content of the textarea (defaults to empty)
  * @return Sprocket the Sprocket textarea tag
  */
 public static function TextArea($name, $content = '')
 {
     $textarea = new Sprocket('textarea');
     $textarea->forceInline();
     $textarea->name = $name;
     $textarea->add($content);
     return $textarea;
 }
Beispiel #4
0
 /**
  * Magic Method that appends a new Sprocket to this one.
  * 
  * Takes the name of the method and creates a new sprocket of that
  * tag name.  ($div->p() would create a new <p> tag under $div, 
  * assuming $div is a Sprocket.)
  * 
  * Takes the parameter and appends it to the new Sprocket.  
  * ($div->p('This is a test'); would add the text "This is a test" to 
  * the new <p> tag.)
  * 
  * Then, appends the new sprocket to this Sprocket.
  * 
  * Finally, returns a reference to the new Sprocket, so you can 
  * fluidly chain these.  $sprocket->div('This is a bold ')->b('example');
  *
  * @param string name of the tag to append (the called method)
  * @param mixed Data to add  (the parameter on the called method)
  * @return refernce to the newly appended sprocket, for fluid notation
  */
 public function __call($name, $values)
 {
     // this is the default tag constructor
     $new_tag = new Sprocket($name);
     // pass the values to the tag
     $new_tag->addArray($values);
     $this->add($new_tag);
     return $new_tag;
 }