{"id":21913493,"url":"https://github.com/vendethiel/sprockets-php","last_synced_at":"2025-06-22T08:37:35.614Z","repository":{"id":3567379,"uuid":"4629377","full_name":"vendethiel/Sprockets-PHP","owner":"vendethiel","description":"Sprockets for PHP","archived":false,"fork":false,"pushed_at":"2018-02-23T12:22:38.000Z","size":2978,"stargazers_count":49,"open_issues_count":10,"forks_count":4,"subscribers_count":8,"default_branch":"master","last_synced_at":"2025-04-27T04:33:25.419Z","etag":null,"topics":["asset-pipeline","php","sprockets","sprockets-php"],"latest_commit_sha":null,"homepage":null,"language":"PHP","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/vendethiel.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2012-06-11T19:53:47.000Z","updated_at":"2025-03-20T14:13:48.000Z","dependencies_parsed_at":"2022-08-23T13:50:51.710Z","dependency_job_id":null,"html_url":"https://github.com/vendethiel/Sprockets-PHP","commit_stats":null,"previous_names":[],"tags_count":23,"template":false,"template_full_name":null,"purl":"pkg:github/vendethiel/Sprockets-PHP","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/vendethiel%2FSprockets-PHP","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/vendethiel%2FSprockets-PHP/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/vendethiel%2FSprockets-PHP/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/vendethiel%2FSprockets-PHP/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/vendethiel","download_url":"https://codeload.github.com/vendethiel/Sprockets-PHP/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/vendethiel%2FSprockets-PHP/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":261263429,"owners_count":23132555,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["asset-pipeline","php","sprockets","sprockets-php"],"created_at":"2024-11-28T18:17:15.433Z","updated_at":"2025-06-22T08:37:30.600Z","avatar_url":"https://github.com/vendethiel.png","language":"PHP","funding_links":[],"categories":[],"sub_categories":[],"readme":"Sprockets-PHP\n===============\n\n# What is Sprockets-PHP\n\nSprockets-PHP is a port of Sprockets, the well-known Asset Manager for Rails.\nSprockets-PHP allows you to manage your assets by taking care of preprocessors, dependencies, minification and caching.\nThe Asset Pipeline will read your main file (usually \"application.js\" or \"application.css\"), read directives, and apply filters for all the files.\nThis is an example usage\n\n`application.js`\n```js\n/**\n * (see the \"directive syntax\" section below)\n *= require jquery\n *= require lib/form\n *= require lib/inputs/{text,password}\n *= require_directory lib/loaders\n */\n```\n\n`lib/form/index.js.coffee`\n```coffee\nclass @Form\n  @Inputs = {}\n  constructor: -\u003e\n//= require /base-input\n```\n\n`/lib/form/base-input.js.coffee`\n```js\nclass @Form.BaseInput\n```\n\n`lib/inputs/text.js.coffee`\n```coffee\nclass @Form.Inputs.Text extends @Form.BaseInput\n  @type: 'Text'\n```\n\n`lib/inputs/password.js.ls`\n```ls\nclass @Form.Inputs.Password extends @Form.BaseInput\n  @type = 'Password'\n  -\u003e console.log \u003c[base password]\u003e\n```\n\nIt's primarily meant to deal with JS and CSS but can as well be used for HTML (HAML, Twig, Slim...).\nYou can add your own filters in a very flexible way (see below).\n\n# How can I use it ?!\n\nYou have to create an instance of `Sprockets\\Pipeline`.\nThe argument is the array of \"base paths\" from where the Pipeline has to search files.\n\nIf you want to call directly the Pipeline, you can then do `$pipeline($asset_type)`.\nFor example `$pipeline('css');`.\nThe framework will load `application.css` in one of the base paths.\nThis file must contain \"directives\", like Sprockets's one.\n\n```php\n// require your autoloader\n...\n\n// read paths.json - see below\n// you can of course pass a normal array !\n$paths = str_replace('%template%', 'MyTemplate', file_get_contents('paths.json'));\n$paths = json_decode($paths, true);\n\n// create a pipeline\n$pipeline = new Sprockets\\Pipeline($paths);\n\n// finds `application.css` in the paths\necho $pipeline('css');\n\n// uses `layout.css`\necho $pipeline('css', 'layout');\n\n// same as the first example, but will cache it into a file\n$cache = new Sprockets\\Cache($pipeline, 'css', $vars = array(), $options = array());\n// $options you can pass :\n// `minify` whether you want to minify the output or not\n// - `.js` : Minified through [Esmangle](https://github.com/Constellation/esmangle)\n// - `.css` : Minified through [Clean-CSS](https://github.com/GoalSmashers/clean-css)\n$content = $cache-\u003egetContent();\n$filename = (string) $cache;\n//or\n$filename = $cache-\u003egetFilename();\n```\n\n## Asset Paths\n\nThe asset paths are divided by \"modules\" to be as flexible as it can :\n\n```json\n{\n  \"template\": {\n    \"directories\": [\n      \"app/themes/%template%/assets/\",\n      \"app/themes/_shared/assets/\",\n      \"lib/assets/\",\n      \"vendor/assets/\"\n    ],\n    \"prefixes\": {\n      \"js\": \"javascripts\",\n      \"css\": \"stylesheets\",\n      \"img\": \"images\",\n      \"font\": \"fonts\"\n    }\n  },\n  \"external\": {\n    \"directories\": [\n      \"vendor/bower/\",\n      \"vendor/components/\"\n    ]\n  }\n}\n```\n\nYou 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).\n\nFor example, if we run `$pipeline('js')`, the pipeline will try to find the following files :\n - `app/themes/%template%/assets/javascripts/application.js` (`%template%` being replaced in the example above)\n - `app/themes/_shared/assets/javascripts/application.js`\n - `lib/assets/javascripts/application.js`\n - `vendor/assets/javascripts/application.js`\n - `vendor/bower/application.js`\n - `vendor/components/application.js`\n\nThis 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`\n\nOnly the \"meaningful\" extension matters (using a whitelist).\n```js\n/**\n * for example\n *= require datatables/js/jquery.dataTables\n * will find correctly the file named\n * \"vendor/bower/datatables/js/jquery.dataTables.js.coffee\"\n * and the \"coffee\" filter will be correctly applied.\n */\n```\n\n## Options\nHere are the options and their default values :\n```php\n      'NODE_PATH' =\u003e 'node',\n      'NPM_PATH' =\u003e __DIR__ . '/../../node_modules/',\n      'CACHE_DIRECTORY' =\u003e 'cache/',\n```\n\nJust pass them along in paths.\n\n## Caching\nSomething 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.\n\n## Directive Syntax\nThere are three supported syntaxs at this moment.\n\n```php\n//= only for js\n#= only for js\n/**\n *= for any\n */\n```\n\n## Supported Directives\nThe directives disponibles are : `require`, `require_directory`, `require_tree` and `depends_on`\n\n### require\nRequires a file directly, from the relative path OR one of the base path.\nYou can also give a directory name, if this directory has a file named \"index.$type\" (here, \"index.css\") in.\nThis directive supports bracket expansion.\n\n### require_directory\nRequires each file of the directory. Not recursive.\n\n### require_tree\nRecursively requires each file of the directory tree.\n\n### depends_on\nAdds the file to the dependencies, even if the file isn't included.\nFor example, in application.css\n\n```php\n//= depends_on image.png\n//= depends_on layout\n```\n\nIf this file change, the whole stylesheet (and the dependencies) will be recompiled\n (this is meant for inlining of some preprocessors).\n\n## Filters\nThe available filters are :\n\nLanguages :\n - .php : [PHP](http://php.net)\n\nJavaScript :\n - .ls : [LiveScript](http://livescript.org)\n - .coffee : [CoffeeScript](http://coffeescript.org) (through [coffeescript-php](github.com/alxlit/coffeescript-php))\n\nStylesheet :\n - .styl : [Stylus](http://learnboost.github.io/stylus/)\n - .sass .scss : [Sass](http://sass-lang.com/) (through [PHPSass](http://phpsass.com/))\n - .less : [Less](http://lesscss.org) (through [lessphp](http://leafo.net/lessphp/))\n\nHtml :\n - .haml : [Haml](http://haml.info) (through [MtHaml](https://github.com/arnaud-lb/MtHaml/), upon which you can build a Twig version, for example)\n\n\nAdding filter is very easy (to create a `.twig` filter or a `.md`, for example). Just add it to the pipeline :\n```php\n$pipeline-\u003eregisterFilter('md', 'My\\Markdown\\Parser');\n```\n\nYou must implement an interface like `\\Sprockets\\Filter\\Interface` :\n```php\ninterface Interface\n{\n\t/**\n\t * @return string processed $content\n\t */\n\tpublic function __invoke($content, $file, $dir, $vars);\n}\n```\n\nYou can also inherit `Sprockets\\Filter\\Base` which gives you access to :\n - `$this-\u003epipeline` current pipeline instance\n - `$this-\u003eprocessNode()` passing an argument array, auto-quoted, like this : `array('modulename/bin/mod', '-c', $file))`\n   Note that the first argument gets the `NODE_MODULES_PATH` prepended automatically.\n\n# Running Tests\n\nTo run the tests you need to first install the dependencies. You do this\nvia composer with the following command:\n\n    php composer.phar install\n\nOnce that is done you just need to run the \"index.php\" file in the test\ndirectory. The easiest way to do this is to use the built-in PHP\nwebserver.\n\n    cd test\n    php -S localhost:5000\n\nThen in your web browser visit:\n\n    http://localhost:5000/index.php\n\nAlternatively you can just run the tests from the command line although\nthe output will contain a few HTML tags:\n\n    cd test\n    php index.php\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fvendethiel%2Fsprockets-php","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fvendethiel%2Fsprockets-php","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fvendethiel%2Fsprockets-php/lists"}