简体   繁体   English

RoR:将HTML存储在文件中以备后用

[英]RoR: Storing HTML in a File for Later Use

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. 我们尝试使用XML,但即使使用CDATA也似乎不可行。

Other options we have are: 我们还有其他选择:

a. 一种。 Store in simple HTML document and use Hpricot for retrieval 存储在简单的HTML文档中,并使用Hpricot进行检索

b. b。 Use YAML for storing at retrieval 使用YAML在检索时进行存储

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 . 对于一般主题类型的应用程序,您应该检出液体(http://www.liquidmarkup.org/)或胡须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. 为了存储不需要在SQL数据库中查询的任意结构,可以使用yaml或JSON。 My preference is for JSON as it is somewhat faster, simpler, and basically gets the job done. 我更喜欢JSON,因为它速度更快,更简单,并且基本上可以完成工作。

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). 如果您需要像XML文档一样查询它,我不建议使用一个HTML文档来存储所有信息,因为在正常主题化过程中意外地将文件搞砸相对容易(例如,如果您有一个类(表示列或行之一),并据此对文档进行转换,如果该类意外用于样式化HTML块之一,则可能会得到意外的结果)。

You should also not use Hpricot as it is essentially unmaintained and deprecated in favor of Nokogiri. 您也不应使用Hpricot,因为它基本上是未维护的,已被Nokogiri弃用。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM