im-richard / Scaffold

Extend, combine and compress CSS
http://github.com/IAMRichardT/Scaffold/wiki
161 stars 19 forks source link

calc()? #27

Open pdclark opened 14 years ago

pdclark commented 14 years ago

Is there a syntax like calc() for doing math with variables in the new version?

anthonyshort commented 14 years ago

I'm looking at finding a way to implement this without having to use eval which could open up some security holes. I was possibly thinking of doing it with css functions:

Height: add(12,34);

Maybe.

pdclark commented 14 years ago

How about this method? : http://www.gamedev.net/community/forums/topic.asp?topic_id=436613

Looks like he's not using eval, plus the input is restricted to the scope of the created function. Add to that a regex that strips anything that's not a decimal or math operator, and it seems like that'd be pretty locked down.

If you want to go all-out crazy, this stack overflow thread ( http://stackoverflow.com/questions/2841304/solving-a-math-problem-expression-which-is-a-string-in-php ) pointed out that there's a PHP implementation of Excel ( http://phpexcel.codeplex.com/ ) that includes a formula parser that might be worth looking at. That would get you all the Excel functions like CEILING, ROUND, etc.