Adding CSS rules from a template helper

Does anyone have an example of building a CSS sheet from an extension?

I’d like a template helper to add CSS rules. In other words, I want

<%= my_helper "foo" %>

to emit HTML like <div id=“foo”> in-place, but also add a style rule for #foo to a CSS file.

I’m sure I can muddle through writing my own extension that adds a CSS asset, but I’m also sure I’ll have a lot of fun getting the ordering of hooks right.

Not sure I understand your question (the HTML example seams to be missing), but you should be able to add a CSS sheet with this:

http://middlemanapp.com/basics/asset-pipeline/#sprockets-import-path

(Thanks, fixed the formatting.)

I wish to dynamically generate the CSS, though. I suppose I can write many .css files and add them each to Sprockets, but was hoping to find a more elegant way.

I suppose a dynamic page ( http://middlemanapp.com/basics/dynamic-pages/ ) could be css just as easily as it can be html. Try making a dynamic template with an css extension and put a variable with the css code inside it.

The template could be provided by the extension ( see How do I create a dynamic page when the template is in an extension? )