Module: MicroformatsHelper::Helpers
- Defined in:
- lib/microformats_helper/helpers.rb
Instance Method Summary collapse
-
#hcard(values, escape = false) ⇒ Object
Options.
-
#hreview_aggregate(values, escape = false) ⇒ Object
Built according to www.google.com/support/webmasters/bin/answer.py?answer=146645 Currently only intended to be read by machines as the displayed information makes little sense without knowledge of its semantical context (ie. the class attributes).
Instance Method Details
#hcard(values, escape = false) ⇒ Object
Options
All fields are optional but the name, you are required to provide at least one of the names below.
Name
-
fn
- Formal Name: should be used when no other name is provided -
given
- Given Name -
family
- Family Name -
additional
- Additional Name: goes between given and family names -
prefix
- Honorific Prefix: for titles like Dr. or Sir -
suffix
- Honorific Suffix: for titles like M.D. or Jr -
org
- Organization name
Address
-
street
- Street Address -
locality
- The city or similar -
region
- The state, county or similar -
postal_code
- ZIP number -
country
- The country
Contact
-
tel
- Provide a hash with the phone types and numbers -
url
- Add a link to a site in the name -
email
- Add a link to a mailto: address
40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 |
# File 'lib/microformats_helper/helpers.rb', line 40 def hcard(values, escape = false) # support for additional HTML options, e.g. id = (values[:html] || {}) # support for more regional divider styles to seperate "locality" and "region" fields values[:divider] ||= " - " # support for additional classes if classes = values[:class] classes << " vcard" else classes = "vcard" end # Figure out the name. Either FN or combination of family, additional, given. unless fn = values[:fn] fn = "" if prefix = values[:prefix] fn += content_tag("span", prefix, {:class => "honorific-prefix"}, escape) end if org = values[:org] fn += " " + content_tag("span", org, {:class => "org"}, escape) end if given = values[:given] fn += " " + content_tag("span", given, {:class => "given-name"}, escape) end if additional = values[:additional] fn += " " + content_tag("span", additional, {:class => 'additional-name'}, escape) end if family = values[:family] fn += " " + content_tag("span", family, {:class => "family-name"}, escape) end if suffix = values[:suffix] fn += ", " + content_tag("span", suffix, {:class => "honorific-suffix"}, escape) end end # Create link or span. Support passing url_for options. if url = values[:url] container_fn = link_to(fn, url, .update(:class=>"fn n url"), escape) else container_fn = "\n" + content_tag("span", fn, {:class => "fn n"}, escape) + "\n" end adr = "" if street = values[:street] address = true adr += content_tag("span", street, {:class => "street-address"}, escape) end if locality = values[:locality] address = true adr += " " + content_tag("span", locality, {:class => "locality"}, escape) end if region = values[:region] address = true adr += values[:divider] + content_tag("span", region, {:class => "region"}, escape) end if postal_code = values[:postal_code] address = true adr += " " + content_tag("span", postal_code, {:class => "postal-code"}, escape) end if country = values[:country] address = true adr += " " + content_tag("span", country, {:class => "country"}, escape) end span_adr = (address == true) ? "\n" + content_tag("span", adr, {:class => "adr"}, escape) + "\n" : "" if email = values[:email] span_email = "\n" + link_to(email, "mailto:#{email}", {:class => "email"}, escape) + "\n" else span_email = "" end if tel = values[:tel] tel_values = "" tel.sort.reverse.each do |k,v| tel_values += content_tag("span", "#{k.capitalize}: ", {:class => "tel-label-#{k} type"}, escape) + content_tag("span", v, {:class => "value"}, escape) + "\n" end span_tel = "\n" + content_tag("span", tel_values, {:class => "tel"}, escape) + "\n" else span_tel = "" end content_tag("span", container_fn + span_adr + span_email + span_tel, .update(:class => classes), escape) end |
#hreview_aggregate(values, escape = false) ⇒ Object
Built according to www.google.com/support/webmasters/bin/answer.py?answer=146645 Currently only intended to be read by machines as the displayed information makes little sense without knowledge of its semantical context (ie. the class attributes).
Parameters
-
values
: a (nested) hash, see below -
escape
: passed to content_tag, defaults to false
Values
The following keys within the values
hash are supported:
-
html
: additional html attributes to pass to the container content_tag element -
class
: additional css class for the container content_tag element -
fn
: the name of reviewed item -
rating
: hash with keysaverage
,best
andworst
, the latter two beingsemantically optional. Corresponding values are integers
-
count
: Integer. The number of aggregated reviews -
votes
: Integer. People who commented without writing a review. Think Facebook likes.
Example
hreview_aggregate(:fn => “John Doe’s Pizza”, :count => 3, :rating => { :average => 4, :best => 10 } )
> <span class=“hreview-aggregate”>
<span class="item">
<span class="fn">John Doe's Pizza</span>
</span>
<span class="rating">
<span class="average">4</span>
<span class="best">10</span>
</span>
<span class="count">3</span>
</span>
162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 |
# File 'lib/microformats_helper/helpers.rb', line 162 def hreview_aggregate(values, escape = false) values.symbolize_keys! # support for additional HTML options, e.g. id = (values[:html] || {}) # support for additional classes if classes = values[:class] classes << " hreview-aggregate" else classes = "hreview-aggregate" end fn = "" if values[:fn] # <span class="item"> # <span class="fn">Marios Pizza</span> # </span> fn += content_tag("span", content_tag("span", values[:fn], {:class => "fn"}, escape), {:class => "item"}, escape) end = "" if values[:rating] # <span class="rating"> # <span class="average">9</span> # <span class="best">10</span> # </span> average = content_tag("span", values[:rating][:average], {:class => "average"}, escape) if values[:rating][:average] best = content_tag("span", values[:rating][:best], {:class => "best"}, escape) if values[:rating][:best] worst = content_tag("span", values[:rating][:worst], {:class => "worst"}, escape) if values[:rating][:worst] += content_tag("span", [average, best, worst].join("\n"), {:class => "rating"}, escape) end count = "" if values[:count] # <span class="count">42</span> count += content_tag("span", values[:count], {:class => "count"}, escape) end votes = "" if values[:votes] # <span class="votes">4711</span> votes += content_tag("span", values[:votes], {:class => "votes"}, escape) end # glue everything together content_tag("span", [fn, , count, votes].join("\n"), .update(:class => classes), escape) end |