Sha256: 7b7d7d454005015488d19bc96a2815c3f59f0bbc2cfff2bef1b2e0772cdda194

Contents?: true

Size: 994 Bytes

Versions: 1

Compression:

Stored size: 994 Bytes

Contents

class Microformats::Address
  def street(str, opts = {})
    content_tag(opts[:tag] || :span, str, :class => 'street-address', :itemprop => 'street-address')
  end

  def city(str, opts = {})
    content_tag(opts[:tag] || :span, str, :class => 'locality', :itemprop => 'locality')
  end

  def state(str, opts = {})
    content_tag(opts[:tag] || :span, str, :class => 'region', :itemprop => 'region')
  end

  def zip(str, opts = {})
    content_tag(opts[:tag] || :span, str, :class => 'postal-code', :itemprop => 'postal-code')
  end
  alias_method :postal_code, :zip

  def country(str, opts = {})
    content_tag(opts[:tag] || :span, str, :class => 'country-name', :itemprop => 'country-name')
  end

  def content_tag(tag, content, opts={})
    attrs = opts.inject([]) do |out, tuple|
      k,v = tuple
      out << "#{k}='#{v}'"
    end
    attr_string = attrs.sort.join(' ')
    open_tag = attr_string == '' ? tag : "#{tag} #{attr_string}"
    "<#{open_tag}>#{content}</#{tag}>"
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
microformats-0.1 lib/address.rb