我必须创建一个报告,为了做一些着色和表格,我决定使用HTML。有没有什么宝石可以用来做这件事?我想避免自己写标签。
发布于 2009-11-25 20:03:15
您可以看看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-25 20:16:22
看看html-table的精华。
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
https://stackoverflow.com/questions/1796459
复制相似问题