Module: OpenMetaTags::ViewHelper
- Defined in:
- lib/open_meta_tags/view_helper.rb
Overview
Methods to use in views and helpers.
Class Method Summary collapse
-
.meta_methods(*attribute_names) ⇒ Object
metaprogramming.
Instance Method Summary collapse
- #admins(admins) ⇒ Object
- #app_id(app_id) ⇒ Object
- #country_name(country_name) ⇒ Object
- #description(description) ⇒ Object
-
#global_meta_tags(default = {}) ⇒ Object
set default metadata values and display metadata.
- #postal_code(postal_code) ⇒ Object
- #single_meta_tags(open_meta_tags = {}) ⇒ Object
- #street_address(street_address) ⇒ Object
Class Method Details
.meta_methods(*attribute_names) ⇒ Object
metaprogramming
41 42 43 44 45 46 47 48 |
# File 'lib/open_meta_tags/view_helper.rb', line 41 def self.(*attribute_names) attribute_names.each do |attribute_name| define_method(attribute_name) do |value| (attribute_name => value) value end end end |
Instance Method Details
#admins(admins) ⇒ Object
15 16 17 18 |
# File 'lib/open_meta_tags/view_helper.rb', line 15 def admins(admins) (:admins => admins) admins end |
#app_id(app_id) ⇒ Object
20 21 22 23 |
# File 'lib/open_meta_tags/view_helper.rb', line 20 def app_id(app_id) (:app_id => app_id) app_id end |
#country_name(country_name) ⇒ Object
35 36 37 38 |
# File 'lib/open_meta_tags/view_helper.rb', line 35 def country_name(country_name) (:country_name => country_name) country_name end |
#description(description) ⇒ Object
10 11 12 13 |
# File 'lib/open_meta_tags/view_helper.rb', line 10 def description(description) (:description => description) description end |
#global_meta_tags(default = {}) ⇒ Object
set default metadata values and display metadata
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 |
# File 'lib/open_meta_tags/view_helper.rb', line 54 def (default = {}) = (default || {}).merge(@open_meta_tags || {}) result = [] ##### metadata options description = normalize_description([:description]) result << tag(:meta, :property => 'og:description', :content => description) unless description.blank? admins = normalize_admins([:admins]) result << tag(:meta, :property => 'fb:admins', :content => admins) unless admins.blank? app_id = [:app_id] result << tag(:meta, :property => 'fb:app_id', :content => app_id) unless app_id.blank? street_address = [:street_address] result << tag(:meta, :property => 'og:street-address', :content => street_address) unless street_address.blank? postal_code = [:postal_code] result << tag(:meta, :property => 'og:postal-code', :content => postal_code) unless postal_code.blank? country_name = [:country_name] result << tag(:meta, :property => 'og:country-name', :content => country_name) unless country_name.blank? # metaprogramming [:title, :type, :url, :image, :site_name, :latitude, :longitude, :locality, :region, :email, :phone_number, :fax_number, :upc, :isbn].each do |attr| result << tag(:meta, :property => "og:#{attr}", :content => [attr]) unless [attr].blank? end result = result.join("\n") result.respond_to?(:html_safe) ? result.html_safe : result end |
#postal_code(postal_code) ⇒ Object
30 31 32 33 |
# File 'lib/open_meta_tags/view_helper.rb', line 30 def postal_code(postal_code) (:postal_code => postal_code) postal_code end |
#single_meta_tags(open_meta_tags = {}) ⇒ Object
5 6 7 8 |
# File 'lib/open_meta_tags/view_helper.rb', line 5 def ( = {}) @open_meta_tags ||= {} @open_meta_tags.merge!( || {}) end |
#street_address(street_address) ⇒ Object
25 26 27 28 |
# File 'lib/open_meta_tags/view_helper.rb', line 25 def street_address(street_address) (:street_address => street_address) street_address end |