Enabling Users to Write DB-Stored CSS for Custom Layouts

I am currently creating a web application (on top of Ruby on Rails) that will allow users to create their own areas (personal blog pages) and wonders what are the best ways to do this?

I think Liquid for templating would be fine, but how would you handle the design? My goal was to have a DB field associated with each block called "style" that will store a custom stylesheet, is this a better approach?

I have tried this so far with the "sanitize_css" method, but it just removes the "#stylebox" tags, which means nothing is displayed.

Any ideas?

Thanks.

+4
source share
4 answers

I would honestly allow the use of theme elements on your page, and then save each of these style rules as a field (or conglomerate them into one giant field) in a database. Forced confirmation that they donโ€™t use any kind of funny business (if they are intended only for certain div , they donโ€™t need to use any curly braces.)

Then create CSS on the fly.

Cause? If you want to show ads on your site and allow them to simply load all their CSS, they can easily turn off visibility in the advertising div.

I think it is โ€œsaferโ€ to control what they are allowed for the topic; I am sure that more advanced users will be checked. But do you really want to be the next MySpace ?; -)

0
source

I am also currently working on an almost similar requirement like you. I am also trying to create a CMS for users to add pages, style them, etc.

My approach is as follows

Each user will have their own subdomain. (I use before_filter to get the subdomain of current users and load his / her site)

About style, I prefer to have a stylesheet as a physical file. Given that your method will have great flexibility in editing the stylesheet, I don't like the idea of โ€‹โ€‹having the stylesheet code on top of my page. Insted, I allow users to upload their styles (Using a paper clip)

So, when the site loads, I get the css paths from the database and load the stylesheet from the path.

Later I plan to read the file and upload it to the text box so that users can edit their stylesheets and override the existing file when saving;

For layouts I also use liquid

amuses

Sameera

+3
source

if there is too much code, then serialize the data and save it as text in db. That would be much better, I think.

0
source

If you allow areas for users to have full control over their CSS, I would probably avoid the database altogether and use a structured file system approach. You can create a subdomain or folder for each user containing main.css. It also allows you to scale well, as functions grow for your user (pictures, etc.).

With that said, as Robbie said, you might consider restricting which styles the user can and cannot control. Otherwise, you are likely to find things that quickly get out of hand. For this approach, you probably want to use a database to store property values โ€‹โ€‹of elements that can be changed.

0
source

All Articles