Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

User-defined themes in a rails app: how to store the assets

I am building an application that should allow user to upload their themes to display the data in a custom way. Each theme should include all the necessary assets such as html template (using Liquid), css files, javascripts and images. The result should be very similar to what Shopify allow to do to their customers.

I am struggling to find the best way for the users to submit their themes and for the application to serve them back. Specifically, what are the best practices:

  • To serve them back to the visitors. While serving the html/liquid files seems to be easy enough using a custom store, I am confused on how to reference and serve 1) images required by the themes, 2) css files required by the themes, 3) images required by the css file
  • To consequentely store the different asset types (e.g., database vs uploaded file and folder structure for the uploaded files)
  • Possibility for the users to edit the uploaded templates through a web interface

Thanks in advance.

like image 813
Topo Avatar asked Jan 01 '12 09:01

Topo


1 Answers

The asset pipeline is primarily designed for serving fixed assets that are pre-compiled at deploy time. There is quite a lot of overhead in doing this, and I don't think it's suitable for serving dynamically editable content.

To attack this problem I would make a list of matrix of all the asset types on the system (user and static) and what the options are for each.

Next to each write possible storage options, e.g. filesystem raw, filesystem pipeline, database. Then work out the pros and cons for each approach, and the approximate complexity of each.

I don't think using the pipeline for this would be a best-practice unless you are really, really concerned about front-end performance; it would be a lot of work to get it going.

A mix of database/filesystem would probably be optimal.

like image 56
Richard Hulse Avatar answered Nov 07 '22 19:11

Richard Hulse