Class: Microformats::Address
- Inherits:
-
Object
- Object
- Microformats::Address
- Includes:
- FormattingHelpers
- Defined in:
- lib/address.rb
Instance Method Summary collapse
-
#city(str, opts = {}) ⇒ Object
Outputs the passed string as a city.
-
#country(str, opts = {}) ⇒ Object
Outputs the passed string as a country.
-
#initialize(template) ⇒ Address
constructor
A new instance of Address.
-
#run(opts = {}, &block) ⇒ Object
You can directly initialize and run this class, but it’s easier to use the Microformats::Helpers#vaddress helper method or the Microformats::Vcard#address method.
-
#state(str, opts = {}) ⇒ Object
Outputs the passed string as a state.
-
#street(str, opts = {}) ⇒ Object
Outputs the passed string as a street address.
-
#type(str, opts = {}) ⇒ Object
Outputs markup for the type of address (‘work’, ‘home’, etc.) There will be no visible text unless provided with the :text option.
-
#zip(str, opts = {}) ⇒ Object
(also: #postal_code)
Outputs the passed string as a postal code.
Methods included from FormattingHelpers
#combine_class_names, #concat, #concat_tag, #content_tag, #encode_time, #humanize_time, #merge_html_attrs
Constructor Details
#initialize(template) ⇒ Address
Returns a new instance of Address.
4 5 6 7 |
# File 'lib/address.rb', line 4 def initialize(template) @template = template @default_tag = :span end |
Instance Method Details
#city(str, opts = {}) ⇒ Object
Outputs the passed string as a city.
OPTIONS
-
:tag - The HTML wrapper element (defaults to :span)
-
Any other passed options will be treated as HTML attributes.
62 63 64 |
# File 'lib/address.rb', line 62 def city(str, opts = {}) content_tag(str, merge_html_attrs({:class => 'locality', :itemprop => 'locality'}, opts)) end |
#country(str, opts = {}) ⇒ Object
Outputs the passed string as a country.
OPTIONS
-
:tag - The HTML wrapper element (defaults to :span)
-
Any other passed options will be treated as HTML attributes.
93 94 95 |
# File 'lib/address.rb', line 93 def country(str, opts = {}) content_tag(str, merge_html_attrs({:class => 'country-name', :itemprop => 'country-name'}, opts)) end |
#run(opts = {}, &block) ⇒ Object
You can directly initialize and run this class, but it’s easier to use the Microformats::Helpers#vaddress helper method or the Microformats::Vcard#address method.
OPTIONS:
-
:type - A string that specifies the type of address(‘home’, ‘work’, etc)
-
:tag - The HTML wrapper element (defaults to :div)
-
Any other passed options will be treated as HTML attributes.
18 19 20 21 22 23 24 25 26 27 28 |
# File 'lib/address.rb', line 18 def run(opts = {}, &block) type = opts[:type] ? self.type(opts.delete(:type)) : nil opts[:class] = combine_class_names('adr', opts[:class]) opts[:itemscope] = 'itemscope' opts[:itemtype] = 'http://data-vocabulary.org/Address' opts[:tag] ||= :div concat_tag(opts) do concat type if type block.call(self) end end |
#state(str, opts = {}) ⇒ Object
Outputs the passed string as a state.
OPTIONS
-
:tag - The HTML wrapper element (defaults to :span)
-
Any other passed options will be treated as HTML attributes.
72 73 74 |
# File 'lib/address.rb', line 72 def state(str, opts = {}) content_tag(str, merge_html_attrs({:class => 'region', :itemprop => 'region'}, opts)) end |
#street(str, opts = {}) ⇒ Object
Outputs the passed string as a street address.
OPTIONS
-
:tag - The HTML wrapper element (defaults to :span)
-
Any other passed options will be treated as HTML attributes.
52 53 54 |
# File 'lib/address.rb', line 52 def street(str, opts = {}) content_tag(str, merge_html_attrs({:class => 'street-address', :itemprop => 'street-address'}, opts)) end |
#type(str, opts = {}) ⇒ Object
Outputs markup for the type of address (‘work’, ‘home’, etc.) There will be no visible text unless provided with the :text option.
NOTE: You get this for free with the :type option of Microformats::Helpers#vaddress, Microformats::Vcard#address and #run methods.
OPTIONS
-
:text - String, the text you want displayed as a text node (default is ”)
-
Any other passed options will be treated as HTML attributes.
40 41 42 43 44 |
# File 'lib/address.rb', line 40 def type(str, opts = {}) inner = content_tag('', :class => 'value-title', :title => str) text = opts.delete(:text) || '' content_tag(inner + text, merge_html_attrs({:class => 'type'}, opts)) end |
#zip(str, opts = {}) ⇒ Object Also known as: postal_code
Outputs the passed string as a postal code.
OPTIONS
-
:tag - The HTML wrapper element (defaults to :span)
-
Any other passed options will be treated as HTML attributes.
82 83 84 |
# File 'lib/address.rb', line 82 def zip(str, opts = {}) content_tag(str, merge_html_attrs({:class => 'postal-code', :itemprop => 'postal-code'}, opts)) end |