class Agave::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/agave/utils/favicon_tags_builder.rb, line 11
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/agave/utils/favicon_tags_builder.rb, line 59
def build_app_name_tag
  meta_tag('application-name', site.name)
end
build_apple_icon_tags() click to toggle source
# File lib/agave/utils/favicon_tags_builder.rb, line 26
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/agave/utils/favicon_tags_builder.rb, line 63
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/agave/utils/favicon_tags_builder.rb, line 38
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/agave/utils/favicon_tags_builder.rb, line 51
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/agave/utils/favicon_tags_builder.rb, line 76
def meta_tag(name, value)
  { tag_name: 'meta', attributes: { name: name, content: value } }
end
meta_tags() click to toggle source
# File lib/agave/utils/favicon_tags_builder.rb, line 16
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/agave/utils/favicon_tags_builder.rb, line 72
def url(width, height = width)
  site.favicon.url(w: width, h: height)
end