class String
def tag(t = :p, p = {})
props = ""
p.each { |key,val|
props += " " + key.to_s + '="' + val.to_s + '"'
}
return "<" + t.to_s + props + ">" + self + "</" + t.to_s + ">"
end
end
Des öfteren hat mich der Codeschnipsel, bei der Generierung von Html weiter gebracht.
Ein paar Beispiele:
Links:
"Google".tag(:a, { :href => "http://www.google.de/" })
=> <a href="http://www.google.de/">Google</a>
"Absatz".tag(:p)
=> <p>Absatz</p>
...

