So we have users who can define their own templates. However. It's turning out that these templates can live on the same page for a short time, which means the css in template 1 that targets h1
would also affect any h1
s in template 2.
Now, if I were writing the CSS, it would be trivial to change code like this:
h1 {
font-family: 'Comic Sans';
}
to this:
#template-1 h1{
font-family: 'Comic Sans';
}
What I'd like to do, however, is read in all of the CSS, and prepend the template ID to each CSS declaration as I've outlined above. Each template has a slug, so we'll wrap the template in a div with the slug as an ID.
Is there a simple way to prefix selectors with an ID in rails, without using a CSS regex? And if so, are there any gotchas I should be aware of when adding said prefix?
EDIT:
SCSS seems like the way to go. So how do I process something stored in the DB as scss?