Download the PHP package vendethiel/sprockets-php without Composer
On this page you can find all versions of the php package vendethiel/sprockets-php. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download vendethiel/sprockets-php
More information about vendethiel/sprockets-php
Files in vendethiel/sprockets-php
Package sprockets-php
Short Description Sprockets-PHP is Sprockets (Rails Asset Pipeline) for PHP
License
Informations about the package sprockets-php
Sprockets-PHP
What is Sprockets-PHP
Sprockets-PHP is a port of Sprockets, the well-known Asset Manager for Rails. Sprockets-PHP allows you to manage your assets by taking care of preprocessors, dependencies, minification and caching. The Asset Pipeline will read your main file (usually "application.js" or "application.css"), read directives, and apply filters for all the files. This is an example usage
application.js
lib/form/index.js.coffee
/lib/form/base-input.js.coffee
lib/inputs/text.js.coffee
lib/inputs/password.js.ls
It's primarily meant to deal with JS and CSS but can as well be used for HTML (HAML, Twig, Slim...). You can add your own filters in a very flexible way (see below).
How can I use it ?!
You have to create an instance of Sprockets\Pipeline
.
The argument is the array of "base paths" from where the Pipeline has to search files.
If you want to call directly the Pipeline, you can then do $pipeline($asset_type)
.
For example $pipeline('css');
.
The framework will load application.css
in one of the base paths.
This file must contain "directives", like Sprockets's one.
Asset Paths
The asset paths are divided by "modules" to be as flexible as it can :
You have 2 keys in each modules : the directories
, which list directories where the Pipeline must search files, and prefixes
, which will append the path for the extension to the directory (ie a js
file will get javascripts/
appended to its paths).
For example, if we run $pipeline('js')
, the pipeline will try to find the following files :
app/themes/%template%/assets/javascripts/application.js
(%template%
being replaced in the example above)app/themes/_shared/assets/javascripts/application.js
lib/assets/javascripts/application.js
vendor/assets/javascripts/application.js
vendor/bower/application.js
vendor/components/application.js
This example file, allowing to use a Rails-like javascripts/
directory for js file gracefully, also supports //= require jquery/jquery
to find vendor/bower/jquery/jquery.js
Only the "meaningful" extension matters (using a whitelist).
Options
Here are the options and their default values :
Just pass them along in paths.
Caching
Something to note : even if you're not using Sprockets\Cache
, the asset pipeline will keep a file list cache in your cache directory, to speed up path lookups.
Directive Syntax
There are three supported syntaxs at this moment.
Supported Directives
The directives disponibles are : require
, require_directory
, require_tree
and depends_on
require
Requires a file directly, from the relative path OR one of the base path. You can also give a directory name, if this directory has a file named "index.$type" (here, "index.css") in. This directive supports bracket expansion.
require_directory
Requires each file of the directory. Not recursive.
require_tree
Recursively requires each file of the directory tree.
depends_on
Adds the file to the dependencies, even if the file isn't included. For example, in application.css
If this file change, the whole stylesheet (and the dependencies) will be recompiled (this is meant for inlining of some preprocessors).
Filters
The available filters are :
Languages :
- .php : PHP
JavaScript :
- .ls : LiveScript
- .coffee : CoffeeScript (through coffeescript-php)
Stylesheet :
Html :
Adding filter is very easy (to create a .twig
filter or a .md
, for example). Just add it to the pipeline :
You must implement an interface like \Sprockets\Filter\Interface
:
You can also inherit Sprockets\Filter\Base
which gives you access to :
$this->pipeline
current pipeline instance$this->processNode()
passing an argument array, auto-quoted, like this :array('modulename/bin/mod', '-c', $file))
Note that the first argument gets theNODE_MODULES_PATH
prepended automatically.
Running Tests
To run the tests you need to first install the dependencies. You do this via composer with the following command:
php composer.phar install
Once that is done you just need to run the "index.php" file in the test directory. The easiest way to do this is to use the built-in PHP webserver.
cd test
php -S localhost:5000
Then in your web browser visit:
http://localhost:5000/index.php
Alternatively you can just run the tests from the command line although the output will contain a few HTML tags:
cd test
php index.php
All versions of sprockets-php with dependencies
leafo/lessphp Version 0.4.0
richthegeek/phpsass Version 2012-06-27