Class: Dato::Utils::FaviconTagsBuilder
- Inherits:
-
Object
- Object
- Dato::Utils::FaviconTagsBuilder
- Defined in:
- lib/dato/utils/favicon_tags_builder.rb
Constant Summary collapse
- APPLE_TOUCH_ICON_SIZES =
[57, 60, 72, 76, 114, 120, 144, 152, 180].freeze
- ICON_SIZES =
[16, 32, 96, 192].freeze
- WINDOWS_SIZES =
[[70, 70], [150, 150], [310, 310], [310, 150]].freeze
Instance Attribute Summary collapse
-
#site ⇒ Object
readonly
Returns the value of attribute site.
-
#theme_color ⇒ Object
readonly
Returns the value of attribute theme_color.
Instance Method Summary collapse
- #build_app_name_tag ⇒ Object
- #build_apple_icon_tags ⇒ Object
- #build_color_tags ⇒ Object
- #build_icon_tags ⇒ Object
- #build_windows_tags ⇒ Object
-
#initialize(site, theme_color) ⇒ FaviconTagsBuilder
constructor
A new instance of FaviconTagsBuilder.
- #link_tag(rel, href, attrs = {}) ⇒ Object
- #meta_tag(name, value) ⇒ Object
- #meta_tags ⇒ Object
- #url(width, height = width) ⇒ Object
Constructor Details
#initialize(site, theme_color) ⇒ FaviconTagsBuilder
Returns a new instance of FaviconTagsBuilder.
12 13 14 15 |
# File 'lib/dato/utils/favicon_tags_builder.rb', line 12 def initialize(site, theme_color) @site = site @theme_color = theme_color end |
Instance Attribute Details
#site ⇒ Object (readonly)
Returns the value of attribute site.
6 7 8 |
# File 'lib/dato/utils/favicon_tags_builder.rb', line 6 def site @site end |
#theme_color ⇒ Object (readonly)
Returns the value of attribute theme_color.
6 7 8 |
# File 'lib/dato/utils/favicon_tags_builder.rb', line 6 def theme_color @theme_color end |
Instance Method Details
#build_app_name_tag ⇒ Object
60 61 62 |
# File 'lib/dato/utils/favicon_tags_builder.rb', line 60 def build_app_name_tag ("application-name", site.name) end |
#build_apple_icon_tags ⇒ Object
27 28 29 30 31 32 33 34 35 36 37 |
# File 'lib/dato/utils/favicon_tags_builder.rb', line 27 def 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 ⇒ Object
64 65 66 67 68 69 70 71 |
# File 'lib/dato/utils/favicon_tags_builder.rb', line 64 def return unless theme_color [ ("theme-color", theme_color), ("msapplication-TileColor", theme_color), ] end |
#build_icon_tags ⇒ Object
39 40 41 42 43 44 45 46 47 48 49 50 |
# File 'lib/dato/utils/favicon_tags_builder.rb', line 39 def 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 ⇒ Object
52 53 54 55 56 57 58 |
# File 'lib/dato/utils/favicon_tags_builder.rb', line 52 def return unless site.favicon WINDOWS_SIZES.map do |(w, h)| ("msapplication-square#{w}x#{h}logo", url(w, h)) end end |
#link_tag(rel, href, attrs = {}) ⇒ Object
81 82 83 |
# File 'lib/dato/utils/favicon_tags_builder.rb', line 81 def link_tag(rel, href, attrs = {}) { tag_name: "link", attributes: attrs.merge(rel: rel, href: href) } end |
#meta_tag(name, value) ⇒ Object
77 78 79 |
# File 'lib/dato/utils/favicon_tags_builder.rb', line 77 def (name, value) { tag_name: "meta", attributes: { name: name, content: value } } end |
#meta_tags ⇒ Object
17 18 19 20 21 22 23 24 25 |
# File 'lib/dato/utils/favicon_tags_builder.rb', line 17 def [ , , , , build_app_name_tag, ].flatten.compact end |
#url(width, height = width) ⇒ Object
73 74 75 |
# File 'lib/dato/utils/favicon_tags_builder.rb', line 73 def url(width, height = width) site.favicon.url(w: width, h: height) end |