0

我必须创建一个报告,并且为了做一些着色和表格,我决定使用 HTML。有什么宝石可以用来做这件事吗?我想避免自己编写标签。

4

2 回答 2

2

您可以查看Markaby,它可以让您通过 Ruby DSL 生成 HTML。

官方文档中的一个例子:

  require 'markaby'

  mab = Markaby::Builder.new
  mab.html do
    head { title "Boats.com" }
    body do
      h1 "Boats.com has great deals"
      ul do
        li "$49 for a canoe"
        li "$39 for a raft"
        li "$29 for a huge boot that floats and can fit 5 people"
      end
    end
  end
  puts mab.to_s

或者,您可以查看许多可用的模板引擎之一。例如:

于 2009-11-25T12:03:14.873 回答
1

查看html-table gem。

sudo gem install html-table

require 'html/table'
include HTML
report=[["Customer1",2042.3],["Customer2",12345.6],["Customer3",4711.0]]
table=Table.new(report)
puts table.html
<table>
   <tr>
      <td>Customer1</td>
      <td>2042.3</td>
   </tr>
   <tr>
      <td>Customer2</td>
      <td>12345.6</td>
   </tr>
   <tr>
      <td>Customer3</td>
      <td>4711.0</td>
   </tr>
</table>

我也将RedCloth用于类似的东西。

require 'redcloth'
RedCloth.new("|{background:#ddd}. Cell with background|Normal|").to_html
于 2009-11-25T12:16:22.250 回答