The Artima Developer Community
Sponsored Link

Ruby Buzz Forum
Making it better

0 replies on 1 page.

Welcome Guest
  Sign In

Go back to the topic listing  Back to Topic List Click to reply to this topic  Reply to this Topic Click to search messages in this forum  Search Forum Click for a threaded view of the topic  Threaded View   
Previous Topic   Next Topic
Flat View: This topic has 0 replies on 1 page
Jeremy Voorhis

Posts: 212
Nickname: jvoorhis
Registered: Oct, 2005

Jeremy Voorhis is a Rubyist in northeast Ohio.
Making it better Posted: Dec 2, 2005 3:44 PM
Reply to this message Reply

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.
Latest Ruby Buzz Posts
Latest Ruby Buzz Posts by Jeremy Voorhis
Latest Posts From JVoorhis

Advertisement

It’s even easier like this:

in app/views/layouts/application.rhtml:
<%= xhtml_doctype :strict %>
<%= html_tag :lang => Globalize::Locale.active.language.iso_639_1 %>
<%= @content_for_layout %>
<%= end_html_tag %>
and in app/helpers/application_helper.rb:
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.

Read: Making it better

Topic: New Toy Previous Topic   Next Topic Topic: I Thought Process::detach Was My Friend

Sponsored Links



Google
  Web Artima.com   

Copyright © 1996-2019 Artima, Inc. All Rights Reserved. - Privacy Policy - Terms of Use