I'm building a site in Rails 3.2. Its been 3 years since I've touched Rails or Ruby, so I'm rusty on both, plus the last time I used rails is was Rails 2.3. Needless to say, please excuse any "simple" questions below.
Here are the specs
- Multi Tennant CMS/Store Site
- Each "Store" (aka sub-domain) can have its own look, feel, etc. through CSS customizations
- The customizations can be performed in a UI within the app allowing the user to change basic variables of Bootstrap (i.e.
@textColor
,@bodyBackground
, etc.)
- The customizations can be performed in a UI within the app allowing the user to change basic variables of Bootstrap (i.e.
- I'm using the
less-rails-bootstrap
gem to the Twitter Bootstrap look/feel, etc.
Here are the challenges
- I need to be able to dynamically output the variables for the CSS into a file that gets mixed in to Bootstrap so the variables are picked up to create the final CSS
- When a user changes a variable for the CSS, the existing style is basically invalidated. I need the full CSS recompiled and written back out to disk, memory stream, or some other location where I can get my hands on it (remember this is using
less
) - I need different CSS to spit out per sub-domain. Any suggestions on how to approach this?
Further complicating the matter...
...given that I essentially will have to find some way to compile the CSS on the fly, that means I have to include GEMS I typically would not in a production environment. Performance will be very important. Is there a way to isolate this? Once the CSS has been invalidated and regenerated, I could take the content and either write it out to disk or store is in some memcached/redis/etc. instance for performance.
Any comments, even if just to point me in a general direction would be appreciated.
Thanks!
Here is the solution I finally landed on:
bootstrap-sass
instead https://github.com/thomas-mcdonald/bootstrap-sassMade the following changes to my
application.rb
file to ensure that the:asset
group is always included despite the environment:Used the concepts provided by Manuel Meure (Thank you Manuel!) of Kraut Computing found at http://www.krautcomputing.com/blog/2012/03/27/how-to-compile-custom-sass-stylesheets-dynamically-during-runtime/ .
In my model (lets call it "Site"), I have a snippet of code that looks like this:
I hope this helps. I know its a deviation from the original post, but its deviated because this seemed to be the most attainable solution to the problem.
If I haven't answered a specific question you have, feel free to comment so I can expand where possible.
Thanks!