[Nitro] Dynamic CSS

George Moschovitis george.moschovitis at gmail.com
Fri Sep 16 09:57:30 EDT 2005


Hello all,

I just added a small but useful feature to Nitro: Dynamic css or CSS
Templates. What this means is that you can use Nitro's advanced
templating mechanism to build your templates:

for example:

<?r
  mygreen = '#0f0'
  bgcol = '#ff'
?>

.myclass {
  background: #{mygreen}
}

.another {
  color: #{mygreen}
}

or even:

<?r %w{ myclass another help }.each do |klass| ?>
.#{klass} {
  color: #{mygreen}
}
<?r end ?>

of course you can use <% .. %> instead of <?r .. ?>

This feature is really useful to avoid messy css files and/or easily
changing colors in css files.

At the moment the implementation is rather simple. You have to define
which templates to 'precompile' in run.rb:

ie

Compiler.precompile 'css/style.css'

will transform the file "#{template_root}/css/style.csst" into
"#{public_root}/css/style.css"

this way the generated css is served by Lighttpd/Apache. The template
is compiled only if the source file is modified.

Can anyone think of a better interface or better name than precompile?


Thanks in advance,
George.

-- 
http://www.gmosx.com
http://www.navel.gr
http://www.nitrohq.com




More information about the Nitro-general mailing list