eRuby and CSS

Does eRuby parse CSS ?
I’d like to be able to create style sheets that use variables for
repeated values like colors and borders.
I’m curious if eRuby currently has this functionality or not.
Is there some method to use the css link in an xhtml document to
parse the style sheet before sending it to the user-agent?
I know it can be done with css embedded into pages, Blogger does this
with its PHP templating, but that is something I’d rather not do.
Or is this just more trouble than it’s worth?

John J. wrote:

Does eRuby parse CSS ?
I don’t think that’s quite the question you want to ask. eRuby parses
eruby templates to produce text files. Those text files can be pretty
much anything (CSS included).

I’d like to be able to create style sheets that use variables for
repeated values like colors and borders.
I’m curious if eRuby currently has this functionality or not.
Is there some method to use the css link in an xhtml document to parse
the style sheet before sending it to the user-agent?
I know it can be done with css embedded into pages, Blogger does this
with its PHP templating, but that is something I’d rather not do.
Or is this just more trouble than it’s worth?

Take a look at http://rcss.rubyforge.org/ - I think it does what you’re
looking for. It’s for Rails, but it should be good education even if
you can’t use it directly.

Thanks!

On 22 Mar 2007, at 15:16, John J. wrote:

I basically want to have a CSS preprocessor, server-side of course.
(I’d actually like CSS3 to be finished and widespread, but that’s
like watching rocks grow)
This looks interesting. Perhaps.
It’s on the right track with variables to substitute in for
commonly used values. That’s one of the big things lacking in CSS
now. But it doesn’t seem as simple as it should/could be.

You might be interested in css_dryer, a plugin for Rails which
supports variables and nesting. There’s no unusual syntax and the
nesting makes the stylesheet a lot DRYer.

http://blog.airbladesoftware.com/2006/12/11/cssdryer-dry-up-your-css

Regards,
Andy S.

On Fri, 23 Mar 2007, John J. wrote:

action_view/helpers/asset_tag_helper.rb
stylesheet_link_tag(*source)
piped through ERb?
Need to sit down with it later!

I have a DSL for CSS that makes variable substitution and so much more
really easy, by writing ruby code that, for the most part, looks a lot
like the CSS that is generated by it.

font_color = ‘#001382
border_style = ‘3 px ridge #a0e0b0
Media.screen {
body {
font {
size 15.px
color font_color
family :verdana
}
background_color ‘#ececff

Id.header {
border border_style
padding 1.em
}
}

It supports the full range of CSS1…3 selectors as well as intelligent
caching of the generated CSS – given conditional logic such as a check
to
see if the browser is an IE version prior to IE7, one can have it
generate
different CSS, and those different versions of the generated CSS will be
cached.

This is written for use with the IOWA web framework, but I could be
convinced to release this as a standalone microproject that also
included
support as a rails plugin or whatever might be necessary for other
frameworks.

Kirk H.

I basically want to have a CSS preprocessor, server-side of course.
(I’d actually like CSS3 to be finished and widespread, but that’s
like watching rocks grow)
This looks interesting. Perhaps.
It’s on the right track with variables to substitute in for commonly
used values. That’s one of the big things lacking in CSS now. But it
doesn’t seem as simple as it should/could be.

But perhaps the best approach is building my own ERb solution and
using something with Rails API AssetTagHelper from rails/actionpack/
action_view/helpers/asset_tag_helper.rb
stylesheet_link_tag(*source)
piped through ERb?
Need to sit down with it later!

On Thu, Mar 22, 2007 at 02:21:18PM +0900, John J. wrote:

Does eRuby parse CSS ?

eRuby doesn’t parse anything really, apart from extracting <% … %>
tags.

There’s nothing to stop you writing CSS files that have snippets of
<%= … %> embedded in them.

As it happens, I’ve just been generating Cisco IOS configuration files
using
erb within Rails.

!
interface FastEthernet 0/0
ip address <%= lan_ipaddr %> <%= lan_netmask %>

Regards,

Brian.