Module: MetaTags::Controller
- Extended by:
- ActiveSupport::Concern
- Includes:
- PageDataHelper
- Defined in:
- lib/meta_tags/controller.rb
Defined Under Namespace
Modules: ClassMethods
Instance Attribute Summary collapse
-
#instance ⇒ Object
readonly
Returns the value of attribute instance.
Instance Method Summary collapse
- #markup_from_provider(provider = :default) ⇒ Object
- #meta_tags(*providers) ⇒ Object
- #meta_tags_container ⇒ Object
- #meta_tags_data ⇒ Object
- #meta_tags_for(identifier) ⇒ Object
- #process_meta_tags ⇒ Object
- #set_meta_tag(key, value, options = {}) ⇒ Object
Methods included from PageDataHelper
#process_meta_tag, #processors
Instance Attribute Details
#instance ⇒ Object (readonly)
Returns the value of attribute instance.
28 29 30 |
# File 'lib/meta_tags/controller.rb', line 28 def instance @instance end |
Instance Method Details
#markup_from_provider(provider = :default) ⇒ Object
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 |
# File 'lib/meta_tags/controller.rb', line 81 def markup_from_provider(provider = :default) = case provider.to_sym when :open_graph { title: "property=\"og:title\"", description: "property=\"og:description\"", image: "property=\"og:image\"", type: "property=\"og:type\"", url: "property=\"og:url\"", site_name: "property=\"og:site_name\"" } when :twitter { title: "name=\"twitter:title\"", description: "name=\"twitter:description\"", image: "name=\"twitter:image\"", url: "name=\"twitter:url\"", site: "name=\"twitter:site\"", card: "name=\"twitter:card\"" } else { description: "name=\"description\"", } end .each_with_object("") do |(key, property_string), buffer| if (content = .send(key)).presence buffer << "<meta #{ property_string } content=\"#{ content }\">\n" end end end |
#meta_tags(*providers) ⇒ Object
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 |
# File 'lib/meta_tags/controller.rb', line 51 def (*providers) = providers.pop if providers.last.is_a? Hash charset = [:encoding] rescue 'utf-8' data = # Required meta tags markup = <<-HTML <meta charset="#{ charset }"> <title>#{ data.title }</title> HTML if data.keywords.presence markup << "<meta name=\"keywords\" content=\"#{ data.keywords }\">" end # Default meta tags markup << markup_from_provider(:default) # Meta tags by provider providers.each do |provider| str = markup_from_provider provider # Prevents same meta tags added twice markup << str if !markup.include?(str) end markup.html_safe end |
#meta_tags_container ⇒ Object
30 31 32 |
# File 'lib/meta_tags/controller.rb', line 30 def @_meta_tags_container ||= ::ApplicationController..dup end |
#meta_tags_data ⇒ Object
34 35 36 37 |
# File 'lib/meta_tags/controller.rb', line 34 def end |
#meta_tags_for(identifier) ⇒ Object
39 40 41 42 43 44 45 46 47 48 49 |
# File 'lib/meta_tags/controller.rb', line 39 def (identifier) if identifier.kind_of?(ActiveRecord::Base) @instance = identifier elsif (list = MetaTags::List.where(identifier: identifier.to_s).first) %w(title description keywords).each do |key| if (value = list.send(:"meta_#{ key }").presence) .send(:"#{ key }=", value) end end end end |
#process_meta_tags ⇒ Object
114 115 116 117 118 119 120 121 122 |
# File 'lib/meta_tags/controller.rb', line 114 def Container::TAGS_LIST.each do |label| next if .send(:"#{ label }_changed?") if (data = (label)) (label, data) end end end |
#set_meta_tag(key, value, options = {}) ⇒ Object
124 125 126 127 128 |
# File 'lib/meta_tags/controller.rb', line 124 def (key, value, = {}) if value.presence && ![:force] .send("#{ key }=", value) end end |