开发者

RoR: Storing HTML in a File for Later Use

开发者 https://www.devze.com 2023-01-21 00:19 出处:网络
In our application we have different themes and each theme has its own default content in the following structure:

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


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.

0

精彩评论

暂无评论...
验证码 换一张
取 消