User constant declarations (and Macros) in style sheets

I agree with you Werner. Simple constants that get replaced 
with the strings they represent. So you just define a series 
of constants at the start of a style sheet. 

The browser could then pre-process these user-defined 
constants, (similar to the C preprocessing of #define 
CONST_VAL declarations), and replace all instances of the 
constant with the appropriately defined value. 

This is just a simple matter of string replacement - ie 
replacing the constant name with it's defined string value, 
throughout the style sheet. Anything else would make things 
far more complicated than necessary. 

The next step beyond this could be macro-substitution - 
defining a property macro-name, that will get expanded into 
series of property declarations the user declares for that 
particular macro name. It's still only string substitution - 
nothing to hard about that, but makes writing and changing 
style sheets a bit more easier and quicker.

So for a style sheet macro definition, something like:

MACRO
      fav_rule {
      color: white;
      background-color: blue;
      border: 1px solid green;
      margin: 3px 5px;
      }
      
      another_macro_rule {
      color: red;
      background-color: yellow;
      border: 3px dashed aqua;
      margin: 5px 7px;
      padding: 3px;
      }

MACRO_END

 /* start of usual style sheet rules */

 p, h1, h2, h3 <fav_rule>

 which expands to:

 p, h1, h2, h3 {
  color: white;
  background-color: blue;
  border: 1px solid green;
  margin: 3px 5px;
 }

Kind Regards - Keith Roberts


On Mon, 25 Apr 2005, Werner Donné wrote:

> To: w3cstyle@karsites.net
> From: Werner Donné <werner.donne@re.be>
> Subject: Re: User constant declarations in style sheets
> 
> I'm in favour of constants, because the only symbolic values
> we have today are relative values such as "em". Imagine you
> want to keep your text in phase. It would then be natural to
> express heights in terms of the leading, which would be itself
> derived from the font size with a factor. At the moment this
> factor would have to be repeated all over the style sheet.
> 
> I would not introduce variables because then you also need something
> to make them vary, i.e. some sort of assignment. This would create
> a different language. Constants, on the other hand, can be replaced
> by their value.
> 
> Werner.

Received on Monday, 25 April 2005 15:46:26 UTC