Install the Bundle
composer require asoc/compassomator-bundle
Ensure Ruby and Compass (gem install compass) are installed globally.
Configure Bundles
For each bundle, create a Resources/config.rb with:
css_dir = "public/css"
sass_dir = "sass"
Place SCSS files in Resources/sass/ and ensure Resources/public/css/ is in .gitignore.
Reference CSS in Twig Use Assetic to include generated CSS:
{% stylesheets '@BundleName/Resources/public/css/foo.css' %}
<link rel="stylesheet" href="{{ asset_url }}">
{% endstylesheets %}
Compile Once Run the compiler:
php app/console compassomator:compile
Then dump Assetic assets:
php app/console assetic:dump
Use @BundleName notation in SCSS to reference assets from other bundles:
@import '@AnotherBundle/sass/variables.scss';
background-image: bundle-public('@AnotherBundle/images/hero.jpg');
The bundle-public function resolves paths dynamically.
Development Workflow
compassomator:watch for live CSS updates:
php app/console compassomator:watch
manage_assetic: false:
php app/console assetic:dump --watch
CI/CD Pipeline
php app/console compassomator:compile && php app/console assetic:dump --no-debug
app/cache/compassomator for performance.Bundle Isolation
config.rb defines its own sass_dir and css_dir, ensuring modularity.@BundleName prefixes.Assetic Integration
web/bundles/ (default) or override in config.yml:
assetic:
assets:
YourBundle_css:
inputs:
- '@YourBundle/Resources/public/css/foo.css'
filters: [cssrewrite]
Dynamic Imports
Use bundle-public for dynamic asset paths in SCSS:
.icon {
background-image: bundle-public('@IconBundle/images/#{ $icon-name }.png');
}
Environment-Specific Configs
Override config.rb per environment (e.g., Resources/config_dev.rb) and reference it in compassomator:compile:
php app/console compassomator:compile --env=dev --config=config_dev.rb
Custom Compass Importers
Extend the bundle’s importer logic by subclassing CompassomatorImporter (see src/ASoC/CompassomatorBundle/Importer/CompassomatorImporter.php).
Cache Conflicts
cache:clear triggers compassomator:compile, which may cause delays. Disable auto-compile in config.yml:
asoc_compassomator:
auto_compile_on_cache_clear: false
Path Resolution Failures
@BundleName notation matches the exact bundle namespace (case-sensitive).bundle-public paths use forward slashes (/), even on Windows.Assetic Mismatches
assetic:dump, check:
output path in config.yml matches the bundle’s css_dir.stylesheets paths.Ruby/Gem Dependencies
PATH isn’t set. Use bundle exec or set COMPASS_BIN in config.rb:
COMPASS_BIN = '/usr/local/bin/compass'
Logs and Cache
php app/console compassomator:logs
app/cache/compassomator/compass.log.Dry Runs Test path resolution with:
php app/console compassomator:compile --dry-run
Compass Config Validation
Validate config.rb syntax:
compass validate Resources/config.rb
Custom Importers
Override the importer to support additional notations (e.g., @ThemeName):
// src/ASoC/CompassomatorBundle/Importer/CustomImporter.php
class CustomImporter extends CompassomatorImporter {
public function resolve($path) {
// Add custom logic here
return parent::resolve($path);
}
}
Register it in services.yml:
asoc_compassomator.importer:
class: ASoC\CompassomatorBundle\Importer\CustomImporter
Post-Compile Hooks Extend the compiler to run additional tasks (e.g., CSS linting):
// src/ASoC/CompassomatorBundle/DependencyInjection/Compiler/PostCompilePass.php
class PostCompilePass implements CompilerPassInterface {
public function process(ContainerBuilder $container) {
$definition = $container->findDefinition('asoc_compassomator.compiler');
$definition->addMethodCall('addPostCompileCallback', [[$this, 'lintCss']]);
}
}
Environment Variables
Use environment variables in config.rb for dynamic paths:
css_dir = ENV['CSS_DIR'] || "public/css"
compassomator:watch with --no-assetic for rapid iteration, then manually run assetic:dump once stable.composer.json:
"autoload": {
"psr-4": {
"ASoC\\CompassomatorBundle\\": "vendor/asoc/compassomator-bundle/src"
}
}
app/cache/compassomator as a volume to persist compiled CSS across container restarts.How can I help you explore Laravel packages today?