レポートを作成する必要があり、いくつかの色付けと表を作成するために、HTML を使用することにしました。これを行うために使用できる宝石はありますか? 自分でタグを書く必要は避けたいです。
2315 次
2 に答える
2
Ruby DSL を介して HTML を生成できるMarkabyを見ることができます。
公式ドキュメントの例:
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
または、利用可能な多くのテンプレート エンジンの 1 つを調べることもできます。例えば:
- RDiscount/Markdown (編集時に Stack Overflow で使用されるマークアップ)
- ハムル
- RedCloth (例については、Jonas の回答を参照してください)
于 2009-11-25T12:03:14.873 に答える
1
html-tablegemをチェックしてください。
sudo gem installhtml-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 に答える