asset_compress
asset_compress copied to clipboard
Merge theme config files
Problem
There doesn't seem to be a way to merge multiple ini config files into a single file that is used to build. A feature like this would be useful specifically for merging theme config into an application's build config. This would be useful with CMS type applications (i.e., Croogo) that use CakePHP theming.
Bare bones example
Here's a real world example of what I'd like to do.
Config/asset_compress.ini
[css]
paths[] = WEBROOT/css/
cachePath = WEBROOT/asset_cache
[styles.css]
files[] = normalize.css
files[] = bootstrap.css
files[] = base.css
View/Themed/SomeTheme/Config/asset_compress.ini
[styles.css]
files[] = styles.css
files[] = navigation.css
The desired result here would be that the configuration would be merged and the final configuration would look something like this:
[css]
paths[] = WEBROOT/css/
cachePath = WEBROOT/asset_cache
[styles.css]
theme = true
files[] = normalize.css
files[] = bootstrap.css
files[] = base.css
files[] = theme:css/styles.css
files[] = theme:css/navigation.css
Decoupling
Splitting ini config files like this would decouple the application's config from the defined themes, whereas a current solution might be to use theme:css/navigation.css
couples the application config to the existence of that css file in the theme.
Merging
Since a Theme isn't a standalone package, like a Plugin would be, an incomplete ini file like the one above doesn't seem like a problem. Themes seem like they would be application-aware, so bringing in application config like cachePath
also doesn't feel wrong.
RFC
I'd like to hear ideas of how this should be accomplished so I can submit a PR, or if there's anything wrong with what I'm proposing. I'm thinking all that might need to be done is merging (and prepending theme:
to files) it during AssetConfig::buildFromIniFile
. Perhaps requiring a new mergeThemeConfig
option to the [General]
section should be added for this functionality.
I'm not super aware of the internals of AssetCompress so there are probably things I'm missing here.
How would AssetCompress know which themes to scan/build?
Should theme files ve able to define new filters/override filters? Or only define new targets?
Good questions. Perhaps it can create a merged build for each theme, prefixing the build file and serving the theme build if a theme is active when the helper tries to serve it. This would allow runtime themes to still have complete builds.
I don't think theme configs should do anything but add files to builds. The application is responsible for filters in the same way the application is responsible for actually building the assets.