cypresslab/compass-elephant-bundle
composer require cypresslab/compass-elephant-bundle
config/bundles.php:
return [
// ...
MatteoSister\CompassElephantBundle\MatteoSisterCompassElephantBundle::class => ['all' => true],
];
config/packages/matteo_sister_compass_elephant.yaml
matteo_sister_compass_elephant:
projects:
- '%kernel.project_dir%/path/to/compass/project'
output_dir: '%kernel.project_dir%/web/css'
.scss files in the configured Compass project directory. The bundle will automatically compile them to CSS on every request (or cache the compiled output if configured).config/packages/matteo_sister_compass_elephant.yaml.scss files, config.rb) is correctly referenced in projects.output_dir points to a writable directory (e.g., web/css).php bin/console cache:clear
.scss file (e.g., styles.scss) with:
@import "partials/header";
body { background: #fff; }
output_dir.ls -la %kernel.project_dir%/web/css
Project Organization
src/Compass/)./src/Compass/
/project1/
config.rb
styles.scss
partials/
/project2/
...
config/packages/matteo_sister_compass_elephant.yaml:
matteo_sister_compass_elephant:
projects:
- '%kernel.project_dir%/src/Compass/project1'
- '%kernel.project_dir%/src/Compass/project2'
output_dir: '%kernel.project_dir%/web/build/css'
Asset Management
asset() helper to reference compiled CSS:
<link rel="stylesheet" href="{{ asset('build/css/styles.css') }}">
MatteoSisterCompassElephantBundle service to fetch the output path:
$compass = $container->get('matteo_sister_compass_elephant');
$cssPath = $compass->getOutputPath('project1', 'styles.css');
Development vs. Production
# config/packages/matteo_sister_compass_elephant.yaml
matteo_sister_compass_elephant:
auto_recompile: false # Disable auto-compilation
Pre-compile manually:
php bin/console matteo-sister:compass:compile
Sprite Generation
config.rb in your Compass project:
# config.rb
sprite_dir = 'images/sprites'
sprite_image_path = '../web/images/sprites.png'
sprite_image_width = 2048
sprite_image_height = 2048
@import "sprites";
.icon { background: sprite-url('icon-name'); }
Integration with Webpack Encore
web/build/.Custom Compass Configurations
config.rb per project by naming it config.local.rb and placing it in the project root. The bundle will use this file if it exists.Event-Driven Compilation
compass.elephant.compile event to trigger custom logic:
// src/EventListener/CompassCompileListener.php
namespace App\EventListener;
use MatteoSister\CompassElephantBundle\Event\CompileEvent;
use Symfony\Component\EventDispatcher\EventSubscriberInterface;
class CompassCompileListener implements EventSubscriberInterface
{
public static function getSubscribedEvents()
{
return [
'compass.elephant.compile' => 'onCompile',
];
}
public function onCompile(CompileEvent $event)
{
// Log or notify when a project compiles
\Log::info(sprintf('Compiling %s', $event->getProject()));
}
}
Caching Strategies
matteo_sister_compass_elephant:
cache_dir: '%kernel.cache_dir%/compass'
php bin/console cache:clear --env=prod
Multi-Environment Configs
# config/packages/dev/matteo_sister_compass_elephant.yaml
matteo_sister_compass_elephant:
auto_recompile: true
log_level: debug
Outdated Compass Version
composer.json:
"compass": "^1.0"
Permission Issues
output_dir. Ensure the web server user (e.g., www-data) has permissions:
chmod -R 775 %kernel.project_dir%/web/css
chown -R www-data:www-data %kernel.project_dir%/web/css
Auto-Compilation Overhead
auto_recompile: false in production and pre-compile assets.Missing Dependencies
PATH:
ruby -v # Should show Ruby 2.x
node -v # Should show Node.js 10.x+
sudo apt-get install ruby nodejs # Debian/Ubuntu
Stale Cache Issues
rm -rf %kernel.cache_dir%/compass
php bin/console cache:clear
Symfony 4+ Compatibility
composer.json:
"autoload": {
"psr-4": {
"MatteoSister\\CompassElephantBundle\\": "vendor/cypresslab/compass-elephant-bundle"
}
}
Enable Verbose Logging
Configure in config/packages/matteo_sister_compass_elephant.yaml:
matteo_sister_compass_elephant:
log_level: debug
Check logs in var/log/dev.log.
Check Compass Output Run Compass manually to debug:
compass compile --no-line-comments --force
Validate Config.rb
Ensure config.rb is valid Ruby. Test it with:
ruby -c config.rb
Symfony Debug Toolbar Use the Profiler to inspect Compass events and compilation status.
Custom Compilation Commands
Extend the bundle’s compiler by implementing MatteoSister\CompassElephantBundle\Compiler\CompilerInterface and register it as a service.
Pre/Post-Compile Hooks
Use the compass.elephant.pre_compile and compass.elephant.post_compile events to add logic before/after compilation.
Custom Asset Helpers Create
How can I help you explore Laravel packages today?