views:

22

answers:

1

Hi All,

In our application we have different themes and each theme has its own default content in the following structure:

ROWS
  COLUMNS
     CONTENT
        HTML DATA 1
     CONTENT
        HTML DATA 2

There could be multiple rows, column and content elements. We need to store this data in a file (manually) and then read & dump it into database. We tried with XML but it seems not feasible even with CDATA.

Other options we have are:

a. Store in simple HTML document and use Hpricot for retrieval

b. Use YAML for storing at retrieval

Please let me know if which way is better or any other better alternative.

Thanks,

Imran

+1  A: 

Ok, so I'm not quite clear on what you are trying to store for the theme. For general theming type applications, you should checkout liquid (http://www.liquidmarkup.org/) or mustache http://github.com/defunkt/mustache.

For storing arbitrary structures that don't need to be queried over in a SQL database, you can use yaml or JSON. My preference is for JSON as it is somewhat faster, simpler, and basically gets the job done.

I'd caution against using one HTML document to store all the info if you need to query it like an XML document as it would be relatively easy to screw up the file accidentally in the course of normal theming (for instance if you have a class that indicates one of the columns or rows and you transform the document based on that, you might get unexpected results if that class is accidentally used for styling one of the blocks of HTML).

You should also not use Hpricot as it is essentially unmaintained and deprecated in favor of Nokogiri.

Ben Hughes
Ben, Thanks for the detailed response. The themes are not for the application itself, but the for the Pages the application allows to create. You can call them Page Templates. Every template have its own default content, and this is what I wish to store in a file and don't want to store in database.Just to confirm, should I go with JSON for the data storage and retrieval?
Imran
Any any resources for working with JSON in RoR?
Imran
Actually, in this case, you should check out Jekyll (http://github.com/mojombo/jekyll). JSON is essentially trivial to work with as it maps directly to ruby hashes, strings, numbers, and arrays. The documentation on the JSON gem is more than enough (and its interface is also emulated by YAJL, which is faster)
Ben Hughes
And if I were you, I'd still store the page templates in the database as this gives you flexibility in how you use them.
Ben Hughes
I agree. Actually we have two types of page templates a) System Templates b) Custom Template (user specific). For former we are storing the contents in database and for the latter we want to use to some file storage so that we can easily move it (the user specific data) around to some other server. Please advise.
Imran
What would be the simplest and easiest fetch stored HTML (considering its structure too)?
Imran