2009-11-25 44 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 
相關問題