tags:

views:

863

answers:

8

I have a legacy application that I needed to implement a configuration page for to change text colors, fonts, etc.

This applications output is also replicated with a PHP web application, where the fonts, colors, etc. are configured in a style sheet.

I've not worked with CSS previously.

Is there a programatic way to modify the CSS and save it without resorting to string parsing or regex?

The application is VB6, but I could write a .net tool that would do the css manipulation if that was the only way.

+2  A: 

It looks like someone's already done a VB.NET CSS parser which is F/OSS, so you could probably adapt it to your needs if you're comfortable with the license.

http://vbcssparser.sourceforge.net/

theraccoonbear
+3  A: 

You don't need to edit the existing one. You could have a new one that overrides the other -- you include this one after the other in your HTML. That's what the "Cascading" means.

Lou Franco
I do need to overwrite.
rathkopf
A: 

Depending on how technically oriented your CSS editors are going to be, you could do it very simply by loading the whole thing up into a TextEdit field to let them edit it - then write it back to the file.

Parsing and creating an interface for all the possibilities of CSS would be an astronomical pain. :-)

Ron

Ron Savage
A: 

One hack is to create a PHP script that all output is passed through, which then replaces certain parts of CSS with configurable alternatives. If you use .htaccess you can make all output go through the script.

Bemmu
A: 

the best way i can think of solving this problem is creating an application that will get some values ( through the URL query ) and generate the appropriate css output based on a css templates

A: 

Check this out, it uses ASP.NET and C#.

Anders
A: 

In my work with the IE control (shadocvw.dll), it has an interesting ability to let you easily manage the CSS of a page and show the effects of modified CSS on a page in realtime. I've never dealt with the details of such implementations myself, but I recommend that as a possible solution worth looking at. Seeing as pretty much everyone is on IE 6 or later nowadays, you can skip the explanations about handling those who only have IE 5,4,3 or 2 installed.

coderGeek
A: 

Maybe the problem's solution, which is most simple for the programmer and a user is to edit css via html form, maybe. I suppose, to create css-file, which would be "default" or "standart" for this application, and just to read it, for example, by perl script, edit in html and to write it down. Here is just the simple example.

In css-file we have string like:

border-color: #008a77;

we have to to read this string, split it up, and send to a file, which will write it down. Get something like this in Perl:

tr/ / /s;
($vari, $value) = split(/:/, _$);
# # While you read file, you can just at the time to put this into html form
echo($vari.":<input type = text name = ".$vari." value = ".$value.">");

And here it is, you've got just simple html-form-data, you just shoul overwrite your css-file with new data like this:

...
print $vari[i].": ".$value.";\n";
...

and voila - you've got programmatical way of changing css. Ofcourse, you have to make it more universal, and more close to your particular problem.

Alexey Shatygin