Class: Agave::Utils::FaviconTagsBuilder
- Inherits:
-
Object
- Object
- Agave::Utils::FaviconTagsBuilder
- Defined in:
- lib/agave/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.
11 12 13 14 |
# File 'lib/agave/utils/favicon_tags_builder.rb', line 11 def initialize(site, theme_color) @site = site @theme_color = theme_color end |
Instance Attribute Details
#site ⇒ Object (readonly)
Returns the value of attribute site.
5 6 7 |
# File 'lib/agave/utils/favicon_tags_builder.rb', line 5 def site @site end |
#theme_color ⇒ Object (readonly)
Returns the value of attribute theme_color.
5 6 7 |
# File 'lib/agave/utils/favicon_tags_builder.rb', line 5 def theme_color @theme_color end |
Instance Method Details
#build_app_name_tag ⇒ Object
59 60 61 |
# File 'lib/agave/utils/favicon_tags_builder.rb', line 59 def build_app_name_tag ('application-name', site.name) end |
#build_apple_icon_tags ⇒ Object
26 27 28 29 30 31 32 33 34 35 36 |
# File 'lib/agave/utils/favicon_tags_builder.rb', line 26 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
63 64 65 66 67 68 69 70 |
# File 'lib/agave/utils/favicon_tags_builder.rb', line 63 def return unless theme_color [ ('theme-color', theme_color), ('msapplication-TileColor', theme_color) ] end |
#build_icon_tags ⇒ Object
38 39 40 41 42 43 44 45 46 47 48 49 |
# File 'lib/agave/utils/favicon_tags_builder.rb', line 38 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
51 52 53 54 55 56 57 |
# File 'lib/agave/utils/favicon_tags_builder.rb', line 51 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
80 81 82 |
# File 'lib/agave/utils/favicon_tags_builder.rb', line 80 def link_tag(rel, href, attrs = {}) { tag_name: 'link', attributes: attrs.merge(rel: rel, href: href) } end |
#meta_tag(name, value) ⇒ Object
76 77 78 |
# File 'lib/agave/utils/favicon_tags_builder.rb', line 76 def (name, value) { tag_name: 'meta', attributes: { name: name, content: value } } end |
#meta_tags ⇒ Object
16 17 18 19 20 21 22 23 24 |
# File 'lib/agave/utils/favicon_tags_builder.rb', line 16 def [ , , , , build_app_name_tag ].flatten.compact end |
#url(width, height = width) ⇒ Object
72 73 74 |
# File 'lib/agave/utils/favicon_tags_builder.rb', line 72 def url(width, height = width) site.favicon.url(w: width, h: height) end |