search
top

Check ma sprockets!

Ever since i heard of Sprockets on Twitter i wanted to use it in my apps. Unfortunatly i am not into Ruby.

Sprockets is a Ruby library that preprocesses and concatenates JavaScript source files. It takes any number of source files and preprocesses them line-by-line in order to build a single concatenation. – getsprockets.org

I wanted to port it to PHP or find clever ways to use it in CakePHP (shell?). But before you start something like this you should check if there isn’t already a project and so i found PHPSprockets from Stuart Loxton. PHP Sprocket is a port of Sprockets. Cool.. so the meat of sprockets is already available :)

PHP Sprockets currently acts as a transparent proxy as default and caches results. Because of this you do not have to initialize any classes in your app and sprocket stays separate.

Thanks to GitHub i just forked the project and began pimping Stuarts class.
Here are the major differences from the orignal port:

  • The main class file has been renamed to “Sprocket”
  • Commands are now classes. It is easy to extend Sprocket with new commands.
  • Instead of YML this fork uses INI files for providing constants.
  • Easy to extend due more abstraction, setters and a array based option interface
  • Seperate render stage (with autoRender option to mimic the original render-on-construct).
  • Also works with other files, like CSS and whatever you want to concat.. (see demo)
  • Selective minification for JS and CSS out of the box. Just add “minify” (see demo files)
  • Fully documented sourcecode

I also added a demo and there is more info about my rewrite in the repo readme.
Enjoy! – http://github.com/m3nt0r/php-sprockets

One Response to “Check ma sprockets!”

  1. [...] To solve this problem I wrote a small PHP script that will parse a Javascript file looking for the ‘require’ comment block and recursively parse each included file. Instead of concatenating each script it outputs an appropriate <script> tag. The scripts parses your application in a depth first recursive manner. Some of the code was inspired by Kjell’s version of PHP Sprockets [...]

Leave a Reply

top