2009-11-25 61 views

回答

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 

或者你可以看看现有的许多模板引擎之一。例如:

+0

在另一个答案中,Jonas建议将RedCloth添加到模板引擎列表中。 – hallski 2009-11-25 12:32:31

+0

我发现马克比最容易处理。谢谢! – Geo 2009-11-25 12:52:25

1

退房的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 
相关问题