microformats_helper 0.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
data/LICENSE ADDED
@@ -0,0 +1,24 @@
1
+
2
+ LICENSE
3
+
4
+ The MIT License
5
+
6
+ Copyright (c) 2008 Ricardo Shiota Yasuda.
7
+
8
+ Permission is hereby granted, free of charge, to any person obtaining a copy
9
+ of this software and associated documentation files (the "Software"), to deal
10
+ in the Software without restriction, including without limitation the rights
11
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
12
+ copies of the Software, and to permit persons to whom the Software is
13
+ furnished to do so, subject to the following conditions:
14
+
15
+ The above copyright notice and this permission notice shall be included in
16
+ all copies or substantial portions of the Software.
17
+
18
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
19
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
20
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
21
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
22
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
23
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
24
+ THE SOFTWARE.
data/README ADDED
@@ -0,0 +1,60 @@
1
+ =Microformats Helper
2
+
3
+ Microformats Helper is a plugin for generating content-rich tags in HTML files, following Microformats standards. For more information about Microformats, check its website (http://microformats.org).
4
+
5
+ Currently only hCard and hReview microformats are available.
6
+
7
+ ==Options
8
+
9
+ All fields are optional but the name, you are required to provide at least one of the names below.
10
+
11
+ ===Name
12
+
13
+ * +fn+ - Formal Name: should be used when no other name is provided
14
+ * +given+ - Given Name
15
+ * +family+ - Family Name
16
+ * +additional+ - Additional Name: goes between given and family names
17
+ * +prefix+ - Honorific Prefix: for titles like Dr. or Sir
18
+ * +suffix+ - Honorific Suffix: for titles like M.D. or Jr
19
+
20
+ ===Address
21
+
22
+ * +street+ - Street Address
23
+ * +locality+ - The city or similar
24
+ * +region+ - The state, county or similar
25
+ * +postal-code+ - ZIP number
26
+ * +country+ - The country
27
+
28
+ ===Contact
29
+
30
+ * +tel+ - Provide the phone number
31
+ * +url+ - Add a link to a site in the name
32
+ * +email+ - Add a link to a mailto: address
33
+
34
+
35
+ ==Usage
36
+
37
+ In your views:
38
+
39
+ <%= hcard :fn => "Ricardo Yasuda" %>
40
+
41
+ The output is:
42
+
43
+ <span class="vcard">
44
+ <span class="fn n">Ricardo Yasuda</span>
45
+ </span>
46
+
47
+ A more complicated example:
48
+
49
+ <%= hcard :given => "Ricardo", :family => "Yasuda", :url => "http://blog.shadowmaru.org", :country => "Brazil" %>
50
+
51
+ The output is:
52
+
53
+ <span class="vcard">
54
+ <a href="http:blog.shadowmaru.org" class="fn n url">
55
+ <span class="given-name">Ricardo</span> <span class="family-name">Yasuda</span>
56
+ </a>
57
+ <div class="adr">
58
+ <span class="country-name">Brazil</span>
59
+ </div>
60
+ </span>
data/README.rdoc ADDED
@@ -0,0 +1,75 @@
1
+ =Microformats Helper
2
+
3
+ Microformats Helper is a plugin for generating content-rich tags in HTML files, following Microformats standards. For more information about Microformats, check its website (http://microformats.org).
4
+
5
+ Currently only hCard and hReview microformats are available.
6
+
7
+ ==Options
8
+
9
+ All fields are optional but the name, you are required to provide at least one of the names below.
10
+
11
+ ===Name
12
+
13
+ * +fn+ - Formal Name: should be used when no other name is provided
14
+ * +given+ - Given Name
15
+ * +family+ - Family Name
16
+ * +additional+ - Additional Name: goes between given and family names
17
+ * +prefix+ - Honorific Prefix: for titles like Dr. or Sir
18
+ * +suffix+ - Honorific Suffix: for titles like M.D. or Jr
19
+ * +org+ - Organization name
20
+
21
+ ===Address
22
+
23
+ * +street+ - Street Address
24
+ * +locality+ - The city or similar
25
+ * +region+ - The state, county or similar
26
+ * +postal_code+ - ZIP number
27
+ * +country+ - The country
28
+
29
+ ===Contact
30
+
31
+ * +tel+ - Provide a hash with the phone types and numbers
32
+ * +url+ - Add a link to a site in the name
33
+ * +email+ - Add a link to a mailto: address
34
+
35
+
36
+ ==Usage
37
+
38
+ In your views:
39
+
40
+ <%= hcard :fn => "Ricardo Yasuda" %>
41
+
42
+ The output is:
43
+
44
+ <span class="vcard">
45
+ <span class="fn n">Ricardo Yasuda</span>
46
+ </span>
47
+
48
+ A more complicated example:
49
+
50
+ <%= hcard :given => "Ricardo", :family => "Yasuda", :url => "http://blog.shadowmaru.org", :country => "Brazil" %>
51
+
52
+ The output is:
53
+
54
+ <span class="vcard">
55
+ <a href="http:blog.shadowmaru.org" class="fn n url">
56
+ <span class="given-name">Ricardo</span> <span class="family-name">Yasuda</span>
57
+ </a>
58
+ <span class="adr">
59
+ <span class="country-name">Brazil</span>
60
+ </span>
61
+ </span>
62
+
63
+ An example with telephone numbers:
64
+
65
+ <%= hcard(:fn => "John Doe", :tel => { "fax" => "544-5544", "home" => "555-5555" }) %>
66
+
67
+ The output is:
68
+
69
+ <span class="vcard">
70
+ <span class="fn n">John Doe</span>
71
+ <span class="tel">
72
+ <span class="tel-label-fax type">Fax: </span><span class="value">544-5544</span>
73
+ <span class="tel-label-home type">Home: </span><span class="value">555-5555</span>
74
+ </span>
75
+ </span>
@@ -0,0 +1,10 @@
1
+ require 'microformats_helper/helpers'
2
+ require 'active_support'
3
+
4
+ if ActiveSupport.respond_to?(:on_load)
5
+ ActiveSupport.on_load(:action_view) do
6
+ include MicroformatsHelper::Helpers
7
+ end
8
+ else
9
+ ActionView::Base.send :include, MicroformatsHelper::Helpers
10
+ end
@@ -0,0 +1,208 @@
1
+ # Microformats Helper is a plugin for generating content-rich tags in HTML files, following Microformats standards. For more information about Microformats, check its website (http://microformats.org).
2
+ #
3
+ # Currently only the hCard and hreview-aggregated microformat is available.
4
+ #
5
+ # Author:: Ricardo Shiota Yasuda (contributions by Carsten Zimmermann)
6
+ # Copyright:: Copyright (c) 2008 Ricardo Shiota Yasuda
7
+ # License:: MIT License (http://www.opensource.org/licenses/mit-license.php)
8
+ #
9
+
10
+
11
+ module MicroformatsHelper
12
+ module Helpers
13
+ # ==Options
14
+ #
15
+ # All fields are optional but the name, you are required to provide at least one of the names below.
16
+ #
17
+ # ===Name
18
+ #
19
+ # * +fn+ - Formal Name: should be used when no other name is provided
20
+ # * +given+ - Given Name
21
+ # * +family+ - Family Name
22
+ # * +additional+ - Additional Name: goes between given and family names
23
+ # * +prefix+ - Honorific Prefix: for titles like Dr. or Sir
24
+ # * +suffix+ - Honorific Suffix: for titles like M.D. or Jr
25
+ # * +org+ - Organization name
26
+ #
27
+ # ===Address
28
+ #
29
+ # * +street+ - Street Address
30
+ # * +locality+ - The city or similar
31
+ # * +region+ - The state, county or similar
32
+ # * +postal_code+ - ZIP number
33
+ # * +country+ - The country
34
+ #
35
+ # ===Contact
36
+ #
37
+ # * +tel+ - Provide a hash with the phone types and numbers
38
+ # * +url+ - Add a link to a site in the name
39
+ # * +email+ - Add a link to a mailto: address
40
+ def hcard(values, escape = false)
41
+
42
+ # support for additional HTML options, e.g. id
43
+ html_options = (values[:html] || {})
44
+
45
+ # support for additional classes
46
+ if classes = values[:class]
47
+ classes << " vcard"
48
+ else
49
+ classes = "vcard"
50
+ end
51
+
52
+ # Figure out the name. Either FN or combination of family, additional, given.
53
+ unless fn = values[:fn]
54
+ fn = ""
55
+ if prefix = values[:prefix]
56
+ fn += content_tag("span", prefix, {:class => "honorific-prefix"}, escape)
57
+ end
58
+ if org = values[:org]
59
+ fn += " " + content_tag("span", org, {:class => "org"}, escape)
60
+ end
61
+ if given = values[:given]
62
+ fn += " " + content_tag("span", given, {:class => "given-name"}, escape)
63
+ end
64
+ if additional = values[:additional]
65
+ fn += " " + content_tag("span", additional, {:class => 'additional-name'}, escape)
66
+ end
67
+ if family = values[:family]
68
+ fn += " " + content_tag("span", family, {:class => "family-name"}, escape)
69
+ end
70
+ if suffix = values[:suffix]
71
+ fn += ", " + content_tag("span", suffix, {:class => "honorific-suffix"}, escape)
72
+ end
73
+ end
74
+
75
+
76
+ # Create link or span. Support passing url_for options.
77
+ if url = values[:url]
78
+ container_fn = link_to(fn, url, html_options.update(:class=>"fn n url"), escape)
79
+ else
80
+ container_fn = "\n" + content_tag("span", fn, {:class => "fn n"}, escape) + "\n"
81
+ end
82
+
83
+ adr = ""
84
+ if street = values[:street]
85
+ address = true
86
+ adr += content_tag("span", street, {:class => "street-address"}, escape)
87
+ end
88
+ if locality = values[:locality]
89
+ address = true
90
+ adr += " " + content_tag("span", locality, {:class => "locality"}, escape)
91
+ end
92
+ if region = values[:region]
93
+ address = true
94
+ adr += " - " + content_tag("span", region, {:class => "region"}, escape)
95
+ end
96
+ if postal_code = values[:postal_code]
97
+ address = true
98
+ adr += " " + content_tag("span", postal_code, {:class => "postal-code"}, escape)
99
+ end
100
+ if country = values[:country]
101
+ address = true
102
+ adr += " " + content_tag("span", country, {:class => "country"}, escape)
103
+ end
104
+ span_adr = (address == true) ? "\n" + content_tag("span", adr, {:class => "adr"}, escape) + "\n" : ""
105
+
106
+ if email = values[:email]
107
+ span_email = "\n" + link_to(email, "mailto:#{email}", {:class => "email"}, escape) + "\n"
108
+ else
109
+ span_email = ""
110
+ end
111
+
112
+ if tel = values[:tel]
113
+ tel_values = ""
114
+ tel.sort.reverse.each do |k,v|
115
+ tel_values += content_tag("span", "#{k.capitalize}: ", {:class => "tel-label-#{k} type"}, escape) + content_tag("span", v, {:class => "value"}, escape) + "\n"
116
+ end
117
+ span_tel = "\n" + content_tag("span", tel_values, {:class => "tel"}, escape) + "\n"
118
+ else
119
+ span_tel = ""
120
+ end
121
+
122
+ content_tag("span", container_fn + span_adr + span_email + span_tel, html_options.update(:class => classes), escape)
123
+ end
124
+
125
+
126
+ # Built according to http://www.google.com/support/webmasters/bin/answer.py?answer=146645
127
+ # Currently only intended to be read by machines as the displayed information
128
+ # makes little sense without knowledge of its semantical context (ie. the class
129
+ # attributes).
130
+ #
131
+ # === Parameters
132
+ # * +values+: a (nested) hash, see below
133
+ # * +escape+: passed to content_tag, defaults to false
134
+ #
135
+ # === Values
136
+ # The following keys within the +values+ hash are supported:
137
+ # * +html+: additional html attributes to pass to the container content_tag element
138
+ # * +class+: additional css class for the container content_tag element
139
+ # * +fn+: the name of reviewed item
140
+ # * +rating+: hash with keys +average+, +best+ and +worst+, the latter two being
141
+ # semantically optional. Corresponding values are integers
142
+ # * +count+: Integer. The number of aggregated reviews
143
+ # * +votes+: Integer. People who commented without writing a review. Think Facebook likes.
144
+ #
145
+ # === Example
146
+ # hreview_aggregate(:fn => "John Doe's Pizza", :count => 3, :rating => { :average => 4, :best => 10 } )
147
+ #
148
+ # => <span class="hreview-aggregate">
149
+ # <span class="item">
150
+ # <span class="fn">John Doe's Pizza</span>
151
+ # </span>
152
+ # <span class="rating">
153
+ # <span class="average">4</span>
154
+ # <span class="best">10</span>
155
+ # </span>
156
+ # <span class="count">3</span>
157
+ # </span>
158
+ #
159
+ def hreview_aggregate(values, escape = false)
160
+ values.symbolize_keys!
161
+ # support for additional HTML options, e.g. id
162
+ html_options = (values[:html] || {})
163
+
164
+ # support for additional classes
165
+ if classes = values[:class]
166
+ classes << " hreview-aggregate"
167
+ else
168
+ classes = "hreview-aggregate"
169
+ end
170
+
171
+ fn = ""
172
+ if values[:fn]
173
+ # <span class="item">
174
+ # <span class="fn">Marios Pizza</span>
175
+ # </span>
176
+ fn += content_tag("span", content_tag("span", values[:fn], {:class => "fn"}, escape), {:class => "item"}, escape)
177
+ end
178
+
179
+ rating = ""
180
+ if values[:rating]
181
+ # <span class="rating">
182
+ # <span class="average">9</span>
183
+ # <span class="best">10</span>
184
+ # </span>
185
+ average = content_tag("span", values[:rating][:average], {:class => "average"}, escape) if values[:rating][:average]
186
+ best = content_tag("span", values[:rating][:best], {:class => "best"}, escape) if values[:rating][:best]
187
+ worst = content_tag("span", values[:rating][:worst], {:class => "worst"}, escape) if values[:rating][:worst]
188
+ rating += content_tag("span", [average, best, worst].join("\n"), {:class => "rating"}, escape)
189
+ end
190
+
191
+ count = ""
192
+ if values[:count]
193
+ # <span class="count">42</span>
194
+ count += content_tag("span", values[:count], {:class => "count"}, escape)
195
+ end
196
+
197
+ votes = ""
198
+ if values[:votes]
199
+ # <span class="votes">4711</span>
200
+ votes += content_tag("span", values[:votes], {:class => "votes"}, escape)
201
+ end
202
+
203
+ # glue everything together
204
+ content_tag("span", [fn, rating, count, votes].join("\n"), html_options.update(:class => classes), escape)
205
+
206
+ end
207
+ end
208
+ end
metadata ADDED
@@ -0,0 +1,85 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: microformats_helper
3
+ version: !ruby/object:Gem::Version
4
+ hash: 27
5
+ prerelease:
6
+ segments:
7
+ - 0
8
+ - 1
9
+ - 0
10
+ version: 0.1.0
11
+ platform: ruby
12
+ authors:
13
+ - Ricardo Shiota Yasuda
14
+ autorequire:
15
+ bindir: bin
16
+ cert_chain: []
17
+
18
+ date: 2011-08-12 00:00:00 Z
19
+ dependencies:
20
+ - !ruby/object:Gem::Dependency
21
+ name: activesupport
22
+ prerelease: false
23
+ requirement: &id001 !ruby/object:Gem::Requirement
24
+ none: false
25
+ requirements:
26
+ - - ">="
27
+ - !ruby/object:Gem::Version
28
+ hash: 3
29
+ segments:
30
+ - 0
31
+ version: "0"
32
+ type: :runtime
33
+ version_requirements: *id001
34
+ description: Helper to render microformats structures (eg hcard).
35
+ email:
36
+ - shadow11@gmail.com
37
+ executables: []
38
+
39
+ extensions: []
40
+
41
+ extra_rdoc_files:
42
+ - LICENSE
43
+ - README
44
+ - README.rdoc
45
+ files:
46
+ - LICENSE
47
+ - README.rdoc
48
+ - lib/microformats_helper.rb
49
+ - lib/microformats_helper/helpers.rb
50
+ - README
51
+ homepage: http://github.com/shadow11/microformats_helper/tree/master
52
+ licenses: []
53
+
54
+ post_install_message:
55
+ rdoc_options: []
56
+
57
+ require_paths:
58
+ - lib
59
+ required_ruby_version: !ruby/object:Gem::Requirement
60
+ none: false
61
+ requirements:
62
+ - - ">="
63
+ - !ruby/object:Gem::Version
64
+ hash: 3
65
+ segments:
66
+ - 0
67
+ version: "0"
68
+ required_rubygems_version: !ruby/object:Gem::Requirement
69
+ none: false
70
+ requirements:
71
+ - - ">="
72
+ - !ruby/object:Gem::Version
73
+ hash: 3
74
+ segments:
75
+ - 0
76
+ version: "0"
77
+ requirements: []
78
+
79
+ rubyforge_project:
80
+ rubygems_version: 1.8.11
81
+ signing_key:
82
+ specification_version: 3
83
+ summary: Helper to render microformats structures (eg hcard).
84
+ test_files: []
85
+