0
我必须创建一个报告,并且为了做一些着色和表格,我决定使用HTML。有没有我可以用来做这件事的宝石?我想避免自己写标签。我可以使用什么gem来生成脱机使用的HTML文件?
我必须创建一个报告,并且为了做一些着色和表格,我决定使用HTML。有没有我可以用来做这件事的宝石?我想避免自己写标签。我可以使用什么gem来生成脱机使用的HTML文件?
你可以看看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
或者你可以看看现有的许多模板引擎之一。例如:
退房的html-table宝石。
sudo的创业板安装HTML表
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
在另一个答案中,Jonas建议将RedCloth添加到模板引擎列表中。 – hallski 2009-11-25 12:32:31
我发现马克比最容易处理。谢谢! – Geo 2009-11-25 12:52:25