class MetaTags::Renderer

Experimental RBS support (using type sampling data from the type_fusion project).

# sig/meta_tags/renderer.rbs

class MetaTags::Renderer
  def configured_name_key: (String name) -> Symbol
  def initialize: (MetaTags::MetaTagsCollection meta_tags) -> void
  def process_tree: (Array[MetaTags::ContentTag] tags, String property, String content, itemprop: nil, **Hash opts) -> Array[MetaTags::ContentTag]
  def render_alternate: (Array[MetaTags::ContentTag] tags) -> nil
  def render_hash: (Array[MetaTags::ContentTag] tags, String key, **Hash opts) -> Hash
  def render_links: (Array[MetaTags::ContentTag] tags) -> untyped
  def render_noindex: (Array[MetaTags::ContentTag] tags) -> untyped
  def render_open_search: (Array[MetaTags::ContentTag] tags) -> nil
  def render_refresh: (Array[MetaTags::ContentTag] tags) -> nil
  def render_tag: (Array[MetaTags::ContentTag] tags, String name, String value, itemprop: nil) -> Array[MetaTags::ContentTag]
  def render_title: (Array[MetaTags::ContentTag] tags) -> Array[MetaTags::ContentTag]
  def render_with_normalization: (Array[MetaTags::ContentTag] tags, Symbol name) -> untyped
end

This class is used by MetaTags gems to render HTML meta tags into page.

def configured_name_key(name)

Experimental RBS support (using type sampling data from the type_fusion project).

def configured_name_key: (String name) -> Symbol

This signature was generated using 7 samples from 1 application.

Returns:
  • (Symbol) - meta tag attribute name (:property or :name).

Parameters:
  • name (String, Symbol) -- tag key.
def configured_name_key(name)
  is_property_tag = MetaTags.config.property_tags.any? do |tag_name|
    name.to_s.match(/^#{Regexp.escape(tag_name.to_s)}\b/)
  end
  is_property_tag ? :property : :name
end

def initialize(meta_tags)

Experimental RBS support (using type sampling data from the type_fusion project).

def initialize: (MetaTags::MetaTagsCollection meta_tags) -> void

This signature was generated using 1 sample from 1 application.

Parameters:
  • meta_tags (MetaTagsCollection) -- meta tags object to render.
def initialize(meta_tags)
  @meta_tags = meta_tags
  @normalized_meta_tags = {}
end

def process_array(tags, property, content, **opts)

Parameters:
  • content (Array) -- array of nested meta tag attributes or values.
  • property (String, Symbol) -- a Hash or a String to render as meta tag.
  • tags (Array) -- a buffer object to store tag in.
def process_array(tags, property, content, **opts)
  content.each { |v| process_tree(tags, property, v, **opts) }
end

def process_hash(tags, property, content, **opts)

Parameters:
  • content (Hash) -- nested meta tag attributes.
  • property (String, Symbol) -- a Hash or a String to render as meta tag.
  • tags (Array) -- a buffer object to store tag in.
def process_hash(tags, property, content, **opts)
  itemprop = content.delete(:itemprop)
  content.each do |key, value|
    if key.to_s == '_'
      iprop = itemprop
      key = property
    else
      key = "#{property}:#{key}"
    end
    normalized_value = if value.kind_of?(Symbol)
                         normalized_meta_tags[value]
                       else
                         value
                       end
    process_tree(tags, key, normalized_value, **opts.merge(itemprop: iprop))
  end
end

def process_tree(tags, property, content, itemprop: nil, **opts)

Experimental RBS support (using type sampling data from the type_fusion project).

type MetaTags__Renderer_process_tree_tags = MetaTags::Tag | MetaTags::Tag | MetaTags::Tag | MetaTags::Tag | MetaTags::Tag | MetaTags::Tag | MetaTags::Tag | MetaTags::Tag | MetaTags::Tag | MetaTags::Tag | MetaTags::Tag | MetaTags::Tag | MetaTags::Tag | MetaTags::Tag | MetaTags::Tag | MetaTags::Tag | MetaTags::Tag | MetaTags::Tag | MetaTags::Tag | MetaTags::Tag | MetaTags::Tag | MetaTags::Tag | MetaTags::Tag | MetaTags::Tag | MetaTags::Tag | MetaTags::Tag | MetaTags::Tag | MetaTags::Tag | MetaTags::Tag | MetaTags::Tag | MetaTags::Tag | MetaTags::Tag | MetaTags::Tag | MetaTags::Tag | MetaTags::Tag | MetaTags::Tag | MetaTags::Tag | MetaTags::Tag | MetaTags::Tag | MetaTags::Tag | MetaTags::Tag | MetaTags::Tag | MetaTags::Tag | MetaTags::Tag | MetaTags::Tag

def process_tree: (MetaTags__Renderer_process_tree_tags tags, String property, String content, itemprop: nil, ** opts) -> (MetaTags::Tag | MetaTags::Tag | MetaTags::Tag | MetaTags::Tag | MetaTags::Tag | MetaTags::Tag | MetaTags::Tag | MetaTags::Tag | MetaTags::Tag | MetaTags::Tag | MetaTags::Tag | MetaTags::Tag | MetaTags::Tag | MetaTags::Tag | MetaTags::Tag | MetaTags::Tag | MetaTags::Tag | MetaTags::Tag | MetaTags::Tag | MetaTags::Tag | MetaTags::Tag | MetaTags::Tag | MetaTags::Tag | MetaTags::Tag | MetaTags::Tag | MetaTags::Tag)

This signature was generated using 7 samples from 1 application.

Parameters:
  • content (Hash, Array, String, Symbol) -- text content or a symbol reference to
  • property (String, Symbol) -- a Hash or a String to render as meta tag.
  • tags (Array) -- a buffer object to store tag in.
def process_tree(tags, property, content, itemprop: nil, **opts)
  method = case content
           when Hash
             :process_hash
           when Array
             :process_array
           else
             iprop = itemprop
             :render_tag
           end
  __send__(method, tags, property, content, itemprop: iprop, **opts)
end

def render(view)

Parameters:
  • view (ActionView::Base) -- Rails view object.
def render(view)
  tags = []
  render_charset(tags)
  render_title(tags)
  render_icon(tags)
  render_with_normalization(tags, :description)
  render_with_normalization(tags, :keywords)
  render_refresh(tags)
  render_canonical_link(tags)
  render_noindex(tags)
  render_alternate(tags)
  render_open_search(tags)
  render_links(tags)
  render_hashes(tags)
  render_custom(tags)
  tags.tap(&:compact!).map! { |tag| tag.render(view) }
  view.safe_join tags, MetaTags.config.minify_output ? "" : "\n"
end

def render_alternate(tags)

Experimental RBS support (using type sampling data from the type_fusion project).

def render_alternate: (MetaTags::Tag | MetaTags::Tag | MetaTags::Tag | MetaTags::Tag tags) -> nil

This signature was generated using 1 sample from 1 application.

Parameters:
  • tags (Array) -- a buffer object to store tag in.
def render_alternate(tags)
  alternate = meta_tags.extract(:alternate)
  return unless alternate
  if alternate.kind_of?(Hash)
    alternate.each do |hreflang, href|
      tags << Tag.new(:link, rel: 'alternate', href: href, hreflang: hreflang) if href.present?
    end
  elsif alternate.kind_of?(Array)
    alternate.each do |link_params|
      tags << Tag.new(:link, { rel: 'alternate' }.with_indifferent_access.merge(link_params))
    end
  end
end

def render_canonical_link(tags)

Parameters:
  • tags (Array) -- a buffer object to store tag in.
def render_canonical_link(tags)
  href = meta_tags.extract(:canonical) # extract, so its not used anywhere else
  return if MetaTags.config.skip_canonical_links_on_noindex && meta_tags[:noindex]
  return if href.blank?
  @normalized_meta_tags[:canonical] = href
  tags << Tag.new(:link, rel: :canonical, href: href)
end

def render_charset(tags)

Parameters:
  • tags (Array) -- a buffer object to store tag in.
def render_charset(tags)
  charset = meta_tags.extract(:charset)
  tags << Tag.new(:meta, charset: charset) if charset.present?
end

def render_custom(tags)

Parameters:
  • tags (Array) -- a buffer object to store tag in.
def render_custom(tags)
  meta_tags.meta_tags.each do |name, data|
    Array(data).each do |val|
      tags << Tag.new(:meta, configured_name_key(name) => name, content: val)
    end
    meta_tags.extract(name)
  end
end

def render_hash(tags, key, **opts)

Experimental RBS support (using type sampling data from the type_fusion project).

def render_hash: (MetaTags::Tag | MetaTags::Tag | MetaTags::Tag | MetaTags::Tag | MetaTags::Tag | MetaTags::Tag | MetaTags::Tag | MetaTags::Tag | MetaTags::Tag tags, String key, ** opts) -> site_name | String | description | String | type | String | url | String | image | String

This signature was generated using 2 samples from 2 applications.

Parameters:
  • tags (Array) -- a buffer object to store tag in.
def render_hash(tags, key, **opts)
  data = meta_tags.meta_tags[key]
  return unless data.kind_of?(Hash)
  process_hash(tags, key, data, **opts)
  meta_tags.extract(key)
end

def render_hashes(tags, **opts)

Parameters:
  • tags (Array) -- a buffer object to store tag in.
def render_hashes(tags, **opts)
  meta_tags.meta_tags.each_key do |property|
    render_hash(tags, property, **opts)
  end
end

def render_icon(tags)

Parameters:
  • tags (Array) -- a buffer object to store tag in.
def render_icon(tags)
  icon = meta_tags.extract(:icon)
  return unless icon
  # String? Value is an href
  icon = [{ href: icon }] if icon.kind_of?(String)
  # Hash? Single icon instead of a list of icons
  icon = [icon] if icon.kind_of?(Hash)
  icon.each do |icon_params|
    icon_params = { rel: 'icon', type: 'image/x-icon' }.with_indifferent_access.merge(icon_params)
    tags << Tag.new(:link, icon_params)
  end
end

def render_links(tags)

Experimental RBS support (using type sampling data from the type_fusion project).

def render_links: (MetaTags::Tag | MetaTags::Tag | MetaTags::Tag | MetaTags::Tag tags) -> untyped

This signature was generated using 1 sample from 1 application.

Parameters:
  • tags (Array) -- a buffer object to store tag in.
def render_links(tags)
  [ :amphtml, :prev, :next, :image_src, :manifest ].each do |tag_name|
    href = meta_tags.extract(tag_name)
    if href.present?
      @normalized_meta_tags[tag_name] = href
      tags << Tag.new(:link, rel: tag_name, href: href)
    end
  end
end

def render_noindex(tags)

Experimental RBS support (using type sampling data from the type_fusion project).

def render_noindex: (MetaTags::Tag | MetaTags::Tag | MetaTags::Tag | MetaTags::Tag tags) -> untyped

This signature was generated using 1 sample from 1 application.

Parameters:
  • tags (Array) -- a buffer object to store tag in.
def render_noindex(tags)
  meta_tags.extract_robots.each do |name, content|
    tags << Tag.new(:meta, name: name, content: content) if content.present?
  end
end

def render_open_search(tags)

Experimental RBS support (using type sampling data from the type_fusion project).

def render_open_search: (MetaTags::Tag | MetaTags::Tag | MetaTags::Tag | MetaTags::Tag tags) -> nil

This signature was generated using 1 sample from 1 application.

Parameters:
  • tags (Array) -- a buffer object to store tag in.
def render_open_search(tags)
  open_search = meta_tags.extract(:open_search)
  return unless open_search
  href = open_search[:href]
  title = open_search[:title]
  type = "application/opensearchdescription+xml"
  tags << Tag.new(:link, rel: 'search', type: type, href: href, title: title) if href.present?
end

def render_refresh(tags)

Experimental RBS support (using type sampling data from the type_fusion project).

def render_refresh: (MetaTags::Tag | MetaTags::Tag tags) -> nil

This signature was generated using 1 sample from 1 application.

Parameters:
  • tags (Array) -- a buffer object to store tag in.
def render_refresh(tags)
  refresh = meta_tags.extract(:refresh)
  tags << Tag.new(:meta, 'http-equiv' => 'refresh', content: refresh.to_s) if refresh.present?
end

def render_tag(tags, name, value, itemprop: nil)

Experimental RBS support (using type sampling data from the type_fusion project).

type MetaTags__Renderer_render_tag_tags = MetaTags::Tag | MetaTags::Tag | MetaTags::Tag | MetaTags::Tag | MetaTags::Tag | MetaTags::Tag | MetaTags::Tag | MetaTags::Tag | MetaTags::Tag | MetaTags::Tag | MetaTags::Tag | MetaTags::Tag | MetaTags::Tag | MetaTags::Tag | MetaTags::Tag | MetaTags::Tag | MetaTags::Tag | MetaTags::Tag | MetaTags::Tag | MetaTags::Tag | MetaTags::Tag | MetaTags::Tag | MetaTags::Tag | MetaTags::Tag | MetaTags::Tag | MetaTags::Tag | MetaTags::Tag | MetaTags::Tag | MetaTags::Tag | MetaTags::Tag | MetaTags::Tag | MetaTags::Tag | MetaTags::Tag | MetaTags::Tag | MetaTags::Tag | MetaTags::Tag | MetaTags::Tag | MetaTags::Tag | MetaTags::Tag | MetaTags::Tag | MetaTags::Tag | MetaTags::Tag | MetaTags::Tag | MetaTags::Tag | MetaTags::Tag
type MetaTags__Renderer_render_tag_return_value = MetaTags::Tag | MetaTags::Tag | MetaTags::Tag | MetaTags::Tag | MetaTags::Tag | MetaTags::Tag | MetaTags::Tag | MetaTags::Tag | MetaTags::Tag | MetaTags::Tag | MetaTags::Tag | MetaTags::Tag | MetaTags::Tag | MetaTags::Tag | MetaTags::Tag | MetaTags::Tag | MetaTags::Tag | MetaTags::Tag | MetaTags::Tag | MetaTags::Tag | MetaTags::Tag | MetaTags::Tag | MetaTags::Tag | MetaTags::Tag | MetaTags::Tag | MetaTags::Tag | MetaTags::Tag | MetaTags::Tag

def render_tag: (MetaTags__Renderer_render_tag_tags tags, String name, String value, itemprop: nil) -> MetaTags__Renderer_render_tag_return_value

This signature was generated using 8 samples from 1 application.

Parameters:
  • itemprop (String, Symbol) -- value of the itemprop attribute.
  • value (String, Symbol) -- text content or a symbol reference to
  • name (String, Symbol) -- a Hash or a String to render as meta tag.
  • tags (Array) -- a buffer object to store tag in.
def render_tag(tags, name, value, itemprop: nil)
  name_key ||= configured_name_key(name)
  tags << Tag.new(:meta, name_key => name.to_s, content: value, itemprop: itemprop) if value.present?
end

def render_title(tags)

Experimental RBS support (using type sampling data from the type_fusion project).

def render_title: ( tags) ->

This signature was generated using 2 samples from 1 application.

Parameters:
  • tags (Array) -- a buffer object to store tag in.
def render_title(tags)
  normalized_meta_tags[:title] = meta_tags.page_title
  normalized_meta_tags[:site] = meta_tags[:site]
  title = meta_tags.extract_full_title
  normalized_meta_tags[:full_title] = title
  tags << ContentTag.new(:title, content: title) if title.present?
end

def render_with_normalization(tags, name)

Experimental RBS support (using type sampling data from the type_fusion project).

def render_with_normalization: (MetaTags::Tag | MetaTags::Tag tags, Symbol name) -> untyped

This signature was generated using 1 sample from 1 application.

Other tags:
    See: TextNormalizer -

Parameters:
  • tags (Array) -- a buffer object to store tag in.
def render_with_normalization(tags, name)
  value = TextNormalizer.public_send("normalize_#{name}", meta_tags.extract(name))
  normalized_meta_tags[name] = value
  tags << Tag.new(:meta, name: name, content: value) if value.present?
end