class Dato::Utils::FaviconTagsBuilder

Constants

APPLE_TOUCH_ICON_SIZES
ICON_SIZES
WINDOWS_SIZES

Attributes

site[R]
theme_color[R]

Public Class Methods

new(site, theme_color) click to toggle source
# File lib/dato/utils/favicon_tags_builder.rb, line 12
def initialize(site, theme_color)
  @site = site
  @theme_color = theme_color
end

Public Instance Methods

build_app_name_tag() click to toggle source
# File lib/dato/utils/favicon_tags_builder.rb, line 60
def build_app_name_tag
  meta_tag("application-name", site.name)
end
build_apple_icon_tags() click to toggle source
# File lib/dato/utils/favicon_tags_builder.rb, line 27
def build_apple_icon_tags
  return unless site.favicon

  APPLE_TOUCH_ICON_SIZES.map do |size|
    link_tag(
      "apple-touch-icon",
      url(size),
      sizes: "#{size}x#{size}",
    )
  end
end
build_color_tags() click to toggle source
# File lib/dato/utils/favicon_tags_builder.rb, line 64
def build_color_tags
  return unless theme_color

  [
    meta_tag("theme-color", theme_color),
    meta_tag("msapplication-TileColor", theme_color),
  ]
end
build_icon_tags() click to toggle source
# File lib/dato/utils/favicon_tags_builder.rb, line 39
def build_icon_tags
  return unless site.favicon

  ICON_SIZES.map do |size|
    link_tag(
      "icon",
      url(size),
      sizes: "#{size}x#{size}",
      type: "image/#{site.favicon.format}",
    )
  end
end
build_windows_tags() click to toggle source
# File lib/dato/utils/favicon_tags_builder.rb, line 52
def build_windows_tags
  return unless site.favicon

  WINDOWS_SIZES.map do |(w, h)|
    meta_tag("msapplication-square#{w}x#{h}logo", url(w, h))
  end
end
meta_tag(name, value) click to toggle source
# File lib/dato/utils/favicon_tags_builder.rb, line 77
def meta_tag(name, value)
  { tag_name: "meta", attributes: { name: name, content: value } }
end
meta_tags() click to toggle source
# File lib/dato/utils/favicon_tags_builder.rb, line 17
def meta_tags
  [
    build_icon_tags,
    build_apple_icon_tags,
    build_windows_tags,
    build_color_tags,
    build_app_name_tag,
  ].flatten.compact
end
url(width, height = width) click to toggle source
# File lib/dato/utils/favicon_tags_builder.rb, line 73
def url(width, height = width)
  site.favicon.url(w: width, h: height)
end