I'm creating an app where users can edit their own CSS (in SCSS syntax). That works fine, however, I eventually want these CSS files to be "programmable" so that users that don't know CSS can still edit them in a basic manner. How?
If I can mark certain things as editable, I don't have to make an impossible database schema. For example I have a scss file called style.scss:
// @type color $header_bg_color: #555; // @type image $header_image: "http://someurl.com/image.jpg";
Then I can do this:
SomeParser.parse(contents of style.scss here)
This will return a hash or something similar of variables:
{:header_bg_color => {:type => "color", :value => "#555"}, :header_image => {:type => "image", :value => "http://someurl.com/image.jpg"} }
I can use the above hash to create a form which the novice user can use to change the data and submit. I believe I know how to do the GET and POST part.
What would be the best way to create / configure my own parser so that I could read the comments and extract the "variables" from this? And then, update the text file easily again?
Another possible way is something like this:
o = SomeParser.new(contents of style.scss here) o.header_bg_color #returns "#555" o.header_image = "http://anotherurl.com/image2.jpg" # "updates" or replaces the old header image variable with the new one o.render # returns the text with the new values
Thanks in advance!