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

发布于 2024-09-28 15:15:18 字数 383 浏览 1 评论 0原文

在我们的应用程序中,我们有不同的主题,每个主题都有自己的默认内容,结构如下:

ROWS
  COLUMNS
     CONTENT
        HTML DATA 1
     CONTENT
        HTML DATA 2

可能有多个行、列和内容元素。我们需要将这些数据存储在文件中(手动),然后读取和读取。将其转储到数据库中。我们尝试使用 XML,但即使使用 CDATA 似乎也不可行。

我们还有其他选择

:存储在简单的 HTML 文档中并使用 Hpricot 进行检索

b.在检索时使用 YAML 进行存储

请告诉我哪种方式更好或有其他更好的替代方案。

谢谢,

伊姆兰

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

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

苏璃陌 2024-10-05 15:15:18

好的,所以我不太清楚您要为主题存储什么。对于一般主题类型的应用程序,您应该查看 Liquid (http://www.liquidmarkup.org/) 或 Mustache http:// /github.com/defunkt/mustache

要在 SQL 数据库中存储不需要查询的任意结构,可以使用 yaml 或 JSON。我更喜欢 JSON,因为它更快、更简单,并且基本上可以完成工作。

如果您需要像 XML 文档一样查询它,我会警告不要使用一个 HTML 文档来存储所有信息,因为在正常主题化过程中相对容易意外地搞砸该文件(例如,如果您有一个类指示其中一列或行,并且您基于此转换文档,如果该类被意外用于 HTML 块之一的样式设计,您可能会得到意外的结果)。

您也不应该使用 Hpricot,因为它基本上没有维护,并且已被 Nokogiri 取代。

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文