edit this page Custom Processors

Post processors are used to process assets before they're compiled. Each processor is mapped to one or more file extension (e.g. LESS to .less). Which processors are used on the asset and their order is determined by the asset's file extensions.

Here's a list of the processors provided by default and their mapping to file extensions:

Engine Extensions Engine
LESS .less oyejorge/less.php

To add a post processors to Duct, simple update the Post-processors section of the config.php file located in the app/config/packages/torann/duct directory of the Laravel application.

Custom Post Processor

A post processor extends from AbstractProcessor class and should implement render method.

namespace YourProcessors\CoffeeScriptParser;

class CoffeeScriptParser extends \Torann\Duct\Processors\AbstractProcessor
{
    function render($context)
    {
        // Get content
        $coffee = file_get_contents($context->path);

        // Return parsed CoffeeScript.
        return CoffeeScript\Compiler::compile($coffee, [
            'filename' => $context->path
        ]);
    }
}

Now simple add or change the post processor in the app/config/packages/torann/duct/config.php file to reflect your new processor.

/*
 |----------------------------------
 | Post-processors
 |----------------------------------
 */

'postprocessors' => [
    'application/javascript' => '\\YourProcessors\\CoffeeScriptParser',
],