This post originated from an RSS feed registered with Ruby Buzz
by Jeremy Voorhis.
Original Post: Making it better
Feed Title: JVoorhis
Feed URL: http://feeds.feedburner.com/jvoorhis
Feed Description: JVoorhis is a Rubyist in northeast Ohio. He rambles about Ruby on Rails, development practices, other frameworks such as Django, and on other days he is just full of snark.
module ApplicationHelper
# Renders an xhtml doctype declaration for the document's prolog. Defaults to xhtml transitional.
# <tt>xhtml_doctype :strict</tt>
def xhtml_doctype( doctype=:transitional )
doctype = :transitional unless [:transitional, :strict, :frameset].include? doctype
case doctype
when :transitional
'<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">'
when :strict
'<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">'
when :frameset
'<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Frameset//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-frameset.dtd">'
end
end
# Displays an html tag, complete with xhtml namespace and language. Accepts language as an option, but defaults to English.
# <tt>html_tag :lang => 'de'</tt>
def html_tag( options={} )
options[:lang] ||= 'en'
lang = options.delete( :lang )
"<html xmlns=\"http://www.w3.org/1999/xhtml\" lang=\"#{lang}\" xml:lang=\"#{lang}\" #{options.map { |k,v| "#{k}=\"#{v}\"" }.join( ' ' )}>"
end
# End html tag.
def end_html_tag; "</html>" end
end
I plan to release this and some other small http/html-related gems as a plugin soon, so keep an eye out.