Module: ViewHelpers
- Defined in:
- app/helpers/view_helpers.rb
Instance Method Summary collapse
- #erb_sanitized(value) ⇒ Object
-
#header_meta_tags(subject, options = {}) ⇒ Object
header_meta_tags renders the most important metatags based on the SocialLinker::Subject.
-
#meta_tag(name, content) ⇒ Object
renders a metatag param [String, Symbol] name (or property) (defaults to name, values starting with ‘og:’ (opengraph) will be using the property attribute) param [String, Symbol] content (the value for the name or the property).
- #social_link_to(subject, network, options = {}) ⇒ Object
-
#social_link_to_image(network, image_path) ⇒ Object
Generates the <SVG> code for the image It references the parent image path with ‘xhref`.
Instance Method Details
#erb_sanitized(value) ⇒ Object
11 12 13 14 15 16 17 |
# File 'app/helpers/view_helpers.rb', line 11 def erb_sanitized(value) if defined? Rails h(value) else ERB::Util.h(value) end end |
#header_meta_tags(subject, options = {}) ⇒ Object
header_meta_tags renders the most important metatags based on the SocialLinker::Subject
24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 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 |
# File 'app/helpers/view_helpers.rb', line 24 def subject, ={} site_title_postfix = [:site_title_postfix] header_html = [] if subject domain = [:domain] || subject.[:domain] header_html << ("twitter:card", subject.media ? :summary_large_image : :summary) header_html << ("twitter:site", subject.[:twitter_username]) header_html << ("twitter:creator", subject.[:twitter_username]) header_html << ("twitter:domain", domain) if subject.url header_html << ("og:url", subject.canonical_url) header_html << "<link rel=\"canonical\" content=\"#{erb_sanitized(subject.canonical_url)}\" />" end header_html << ("keywords", subject..join(" ")) header_html << ("description", subject.summary) header_html << ("twitter:description", subject.summary) header_html << ("og:description", subject.summary) if subject.media header_html << ("twitter:image:src", subject.media) header_html << ("og:image", subject.media) header_html << ("og:image:type", subject.[:image_type]) end end title = @title title = subject.title if subject site_title = [title, site_title_postfix].uniq.compact.join(" - ") header_html << "<title>#{erb_sanitized(site_title)}</title>" header_html << ("twitter:title", title) header_html << ("og:title", title) header_html.compact! header_html = header_html.join("\n") if header_html # we trust the html because all user input is sanitized by erb_sanitized header_html = header_html.html_safe if header_html.methods.include?(:html_safe) header_html end |
#meta_tag(name, content) ⇒ Object
renders a metatag param [String, Symbol] name (or property) (defaults to name, values starting with ‘og:’ (opengraph) will be using the property attribute) param [String, Symbol] content (the value for the name or the property)
6 7 8 9 |
# File 'app/helpers/view_helpers.rb', line 6 def (name, content) name_or_property_section = name.start_with?("og:") ? "property=\"#{erb_sanitized(name)}\"" : "name=\"#{erb_sanitized(name)}\"" "<meta #{name_or_property_section} content=\"#{erb_sanitized(content)}\" />" if content and content != "" end |
#social_link_to(subject, network, options = {}) ⇒ Object
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 |
# File 'app/helpers/view_helpers.rb', line 80 def subject, network, = {} raise ArgumentError, "subject can't be nil" unless subject raise ArgumentError, "network can't be nil" unless network = { social_icons_image_path: 'social_linker/icons.svg', title: network.to_s.capitalize }.merge() link_content = network if block_given? link_content = yield else = [:social_icons_image_path] = image_path() if self.methods.include?(:image_path) link_content = (network, ) end title = [:title] html = "<a href=\"#{erb_sanitized(subject.share_link(network))}\" class=\"#{network}\" title=\"#{title}\">#{link_content}</a>" html = html.html_safe if html.methods.include?(:html_safe) html end |
#social_link_to_image(network, image_path) ⇒ Object
Generates the <SVG> code for the image It references the parent image path with ‘xhref`. Make sure your browser supports this, or use something like `svg4everyone` to fix your client’s browsers Options:
-
social_icons_image_path (defaults to the default SocialLinker iconset)
-
title (the title attribute, defaults to the network’s name capitalized)
74 75 76 77 78 |
# File 'app/helpers/view_helpers.rb', line 74 def (network, image_path) if network and image_path "<svg class=\"icon icon-#{network} icon-default-style\"><use xlink:href=\"#{image_path}#icon-#{network}\"></use></svg>" end end |