eRuby and CSS

J

John Joyce

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?
 
A

Alex Young

John said:
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.
 
J

John Joyce

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!
 
A

Andrew Stewart

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 Stewart
 
K

khaines

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!

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 Haines
 
B

Brian Candler

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.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads


Members online

No members online now.

Forum statistics

Threads
473,770
Messages
2,569,586
Members
45,096
Latest member
ThurmanCre

Latest Threads

Top