middleman-dato 0.5.9 → 0.5.10

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 594507c939804a084dce7c226152d785846d168d
4
- data.tar.gz: cb2613448b0cd0235697ef9d34086fb2f78840df
3
+ metadata.gz: 66f8b84f068ef2285a1084e62f59b07e688fe81e
4
+ data.tar.gz: b4c83ba00f33a2fe48692241ea818a3b39d778a2
5
5
  SHA512:
6
- metadata.gz: 1f23f627756a08c5cdfe37597a5129fa8fb2485bceb15b0c0dea85eff74b08462b2183a600e3a115151c441b7b12afa40328ebfd79ef4f7b176db7858cfe1a72
7
- data.tar.gz: 88340c0336b01cefd2fc2048a7a8065307905a6576a245254065c22c081aadf68495fcc99379913616e6067e843b2381782dc506a7a218fec14f95f427a68b85
6
+ metadata.gz: 10061b7196f9bf326afb551fbc88a798f7e3ffae12538253447c95f3d303c3026ac381059c8ae57d273c0b4bb7baef9bf3bf8da03de21888918182bf84d3339c
7
+ data.tar.gz: ff9fcf1950fa73b25b11031f3992b9727f2e1c82ba0a46343c4184dc6d890f2c532d103db7a2140619047385fd1e67cc9c174881903f752ae9c110be14234473
@@ -0,0 +1,84 @@
1
+ module Dato
2
+ module MetaTags
3
+ class Favicon
4
+ attr_reader :builder, :theme_color, :favicon, :app_name
5
+ APPLE_TOUCH_ICON_SIZES = [57, 60, 72, 76, 114, 120, 144, 152, 180].freeze
6
+ ICON_SIZES = [16, 32, 96, 192].freeze
7
+ APPLICATION_SIZES = [70, 150, 310].freeze
8
+
9
+ def initialize(builder, entity, theme_color)
10
+ @favicon = entity.favicon
11
+ @builder = builder
12
+ @theme_color = theme_color
13
+ @app_name = entity.global_seo['site_name'] || ''
14
+ end
15
+
16
+ def image
17
+ Dato::FieldType::Image.parse(favicon, nil) if favicon.present?
18
+ end
19
+
20
+ def url(width, height = nil)
21
+ height ||= width
22
+ image.file.width(width).height(height).to_url
23
+ end
24
+
25
+ def build_apple_icon_tags
26
+ APPLE_TOUCH_ICON_SIZES.map do |size|
27
+ builder.tag(:link,
28
+ rel: 'apple-touch-icon',
29
+ sizes: "#{size}x#{size}",
30
+ href: url(size)
31
+ )
32
+ end
33
+ end
34
+
35
+ def build_icon_tags
36
+ ICON_SIZES.map do |size|
37
+ builder.tag(:link,
38
+ rel: 'icon',
39
+ type: "image/#{image.format}",
40
+ href: url(size),
41
+ sizes: "#{size}x#{size}"
42
+ )
43
+ end
44
+ end
45
+
46
+ def build_application_tags
47
+ APPLICATION_SIZES.map do |size|
48
+ builder.tag(:meta,
49
+ name: "msapplication-square#{size}x#{size}logo",
50
+ content: url(size)
51
+ )
52
+ end + [builder.tag(:meta,
53
+ name: 'msapplication-wide310x150logo',
54
+ content: url(310, 150)
55
+ )]
56
+ end
57
+
58
+ def main_tags
59
+ [
60
+ builder.tag(:meta, name: 'application-name', content: app_name),
61
+ builder.tag(:meta, name: 'theme-color', content: theme_color),
62
+ builder.tag(:meta,
63
+ name: 'msapplication-TileColor',
64
+ content: theme_color
65
+ )
66
+ ]
67
+ end
68
+
69
+ def build_tags
70
+ tags = main_tags
71
+ unless image.nil?
72
+ tags += build_apple_icon_tags
73
+ tags += build_icon_tags
74
+ tags += build_application_tags
75
+ end
76
+ tags
77
+ end
78
+
79
+ def build
80
+ build_tags.join("\n")
81
+ end
82
+ end
83
+ end
84
+ end
@@ -3,6 +3,7 @@ require 'middleman-core/version'
3
3
  require 'semantic'
4
4
  require 'dato/meta_tags_builder'
5
5
  require 'dato/space'
6
+ require 'dato/meta_tags/favicon'
6
7
 
7
8
  module Dato
8
9
  class MiddlemanExtension < ::Middleman::Extension
@@ -57,6 +58,17 @@ module Dato
57
58
  )
58
59
  builder.meta_tags
59
60
  end
61
+
62
+ def dato_favicon_meta_tags(options = {})
63
+ options[:theme_color] ||= '#ffffff'
64
+ options[:app_name] ||= ''
65
+ favicon_builder = MetaTags::Favicon.new(
66
+ self,
67
+ extensions[:dato].space.entity,
68
+ options[:theme_color]
69
+ )
70
+ favicon_builder.build
71
+ end
60
72
  end
61
73
  end
62
74
  end
data/lib/dato/record.rb CHANGED
@@ -11,7 +11,7 @@ module Dato
11
11
  extend Forwardable
12
12
 
13
13
  attr_reader :entity
14
- def_delegators :entity, :id, :type
14
+ def_delegators :entity, :id, :type, :content_type
15
15
 
16
16
  def initialize(entity, records_repo)
17
17
  @entity = entity
data/lib/dato/space.rb CHANGED
@@ -1,3 +1,4 @@
1
+ # coding: utf-8
1
2
  require 'dato/client'
2
3
  require 'dato/entities_repo'
3
4
  require 'dato/records_repo'
@@ -3,7 +3,7 @@ $LOAD_PATH.push File.expand_path('../lib', __FILE__)
3
3
 
4
4
  Gem::Specification.new do |s|
5
5
  s.name = 'middleman-dato'
6
- s.version = '0.5.9'
6
+ s.version = '0.5.10'
7
7
  s.platform = Gem::Platform::RUBY
8
8
  s.authors = ['Stefano Verna']
9
9
  s.email = ['s.verna@cantierecreativo.net']
@@ -0,0 +1,187 @@
1
+ require 'spec_helper'
2
+ require 'active_support/core_ext/hash/indifferent_access'
3
+
4
+ require 'pry'
5
+
6
+ module Dato
7
+ module MetaTags
8
+ RSpec.describe Favicon do
9
+ subject(:meta_tag) { described_class.new(builder, entity, theme_color) }
10
+ let(:builder) { ::MockBuilder.new }
11
+ let(:theme_color) { '#ffffff' }
12
+ let(:application_name) { 'An app name' }
13
+ let(:image_format) { 'image_format' }
14
+ let(:entity) do
15
+ double(
16
+ 'Dato::JsonApiEntity',
17
+ favicon: favicon,
18
+ global_seo: ActiveSupport::HashWithIndifferentAccess.new(
19
+ site_name: application_name
20
+ )
21
+ )
22
+ end
23
+ let(:favicon) do
24
+ ActiveSupport::HashWithIndifferentAccess.new(
25
+ path: '/path/to/file',
26
+ width: 1000,
27
+ height: 1000,
28
+ format: image_format,
29
+ size: 10_000
30
+ )
31
+ end
32
+
33
+ describe '#build_tags' do
34
+ let(:result) { meta_tag.build_tags }
35
+
36
+ it 'render the application-name' do
37
+ meta = result.find { |t| t[0] == :meta && t[1][:name] == 'application-name' }
38
+ expect(meta).to be_present
39
+ expect(meta[1][:content]).to eq application_name
40
+ end
41
+
42
+ it 'render the theme-color' do
43
+ meta = result.find { |t| t[0] == :meta && t[1][:name] == 'theme-color' }
44
+ expect(meta).to be_present
45
+ expect(meta[1][:content]).to eq theme_color
46
+ end
47
+
48
+ it 'render the msapplication-TileColor' do
49
+ meta = result.find { |t| t[0] == :meta && t[1][:name] == 'msapplication-TileColor' }
50
+ expect(meta).to be_present
51
+ expect(meta[1][:content]).to eq theme_color
52
+ end
53
+ end
54
+
55
+ describe '#image' do
56
+ context 'when favicon is not present' do
57
+ let(:favicon) { nil }
58
+
59
+ it 'renders nil' do
60
+ expect(meta_tag.image).to eq nil
61
+ end
62
+ end
63
+
64
+ context 'else' do
65
+ let(:image_obj) { double('Dato::FieldType::Image', format: image_format) }
66
+
67
+ it 'return the image parsed with Dato::FieldType::Image' do
68
+ allow(Dato::FieldType::Image).to receive(:parse).and_return(image_obj)
69
+ image = meta_tag.image
70
+ expect(Dato::FieldType::Image).to have_received(:parse)
71
+ .with(favicon, nil)
72
+ expect(image).to eq image_obj
73
+ end
74
+ end
75
+ end
76
+
77
+ describe '#url' do
78
+ let(:image) { instance_double('Dato::FieldType::Image', file: file) }
79
+ let(:file) { instance_double('Imgix::Path') }
80
+ let(:width) { 1 }
81
+ let(:height) { 2 }
82
+
83
+ let(:result) { meta_tag.url(width, height) }
84
+
85
+ before do
86
+ allow(meta_tag).to receive(:image).and_return(image)
87
+ allow(file).to receive(:width).and_return(file)
88
+ allow(file).to receive(:height).and_return(file)
89
+ allow(file).to receive(:to_url)
90
+ result
91
+ end
92
+
93
+ it 'generates the url for that size' do
94
+ expect(meta_tag).to have_received(:image)
95
+ expect(image).to have_received(:file)
96
+ expect(file).to have_received(:width).with(width)
97
+ expect(file).to have_received(:height).with(height)
98
+ expect(file).to have_received(:to_url)
99
+ end
100
+
101
+ context 'without height' do
102
+ let(:result) { meta_tag.url(width) }
103
+
104
+ it 'call height with width value' do
105
+ expect(file).to have_received(:height).with(width)
106
+ end
107
+ end
108
+ end
109
+
110
+ describe '#build_apple_icon_tags' do
111
+ let(:result) { meta_tag.build_apple_icon_tags }
112
+ let(:image_url) { '/path/to/image' }
113
+
114
+ before do
115
+ allow(meta_tag).to receive(:url).and_return(image_url)
116
+ result
117
+ end
118
+
119
+ it 'render an apple-touch-icon link for each size' do
120
+ described_class::APPLE_TOUCH_ICON_SIZES.each do |apple_icon_size|
121
+ meta = result.find do |t|
122
+ t[0] == :link &&
123
+ t[1][:rel] == 'apple-touch-icon' &&
124
+ t[1][:sizes] == "#{apple_icon_size}x#{apple_icon_size}"
125
+ end
126
+
127
+ expect(meta_tag).to have_received(:url).with(apple_icon_size)
128
+ expect(meta).to be_present
129
+ expect(meta[1][:href]).to eq image_url
130
+ end
131
+ end
132
+ end
133
+
134
+ describe '#build_apple_icon_tags' do
135
+ let(:result) { meta_tag.build_icon_tags }
136
+ let(:image) { instance_double('Dato::FieldType::Image', format: format) }
137
+ let(:format) { 'png' }
138
+ let(:image_url) { '/path/to/image' }
139
+
140
+ before do
141
+ allow(meta_tag).to receive(:url).and_return(image_url)
142
+ allow(meta_tag).to receive(:image).and_return(image)
143
+ result
144
+ end
145
+
146
+ it 'render an icon link for each size' do
147
+ described_class::ICON_SIZES.each do |icon_size|
148
+ meta = result.find do |t|
149
+ t[0] == :link &&
150
+ t[1][:rel] == 'icon' &&
151
+ t[1][:sizes] == "#{icon_size}x#{icon_size}"
152
+ end
153
+
154
+ expect(meta_tag).to have_received(:url).with(icon_size)
155
+ expect(meta).to be_present
156
+ expect(meta[1][:href]).to eq image_url
157
+ end
158
+ end
159
+ end
160
+
161
+ describe '#build_application_tags' do
162
+ let(:result) { meta_tag.build_application_tags }
163
+ let(:image) { instance_double('Dato::FieldType::Image', format: format) }
164
+ let(:format) { 'png' }
165
+ let(:image_url) { '/path/to/image' }
166
+
167
+ before do
168
+ allow(meta_tag).to receive(:url).and_return(image_url)
169
+ allow(meta_tag).to receive(:image).and_return(image)
170
+ result
171
+ end
172
+
173
+ it 'render application meta for each size' do
174
+ described_class::APPLICATION_SIZES.each do |size|
175
+ meta = result.find do |t|
176
+ t[0] == :meta &&
177
+ t[1][:name] == "msapplication-square#{size}x#{size}logo"
178
+ end
179
+ expect(meta_tag).to have_received(:url).with(size)
180
+ expect(meta).to be_present
181
+ expect(meta[1][:content]).to eq image_url
182
+ end
183
+ end
184
+ end
185
+ end
186
+ end
187
+ end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: middleman-dato
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.5.9
4
+ version: 0.5.10
5
5
  platform: ruby
6
6
  authors:
7
7
  - Stefano Verna
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2016-05-06 00:00:00.000000000 Z
11
+ date: 2016-05-20 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: middleman-core
@@ -128,6 +128,7 @@ files:
128
128
  - lib/dato/meta_tags/article_publisher.rb
129
129
  - lib/dato/meta_tags/base.rb
130
130
  - lib/dato/meta_tags/description.rb
131
+ - lib/dato/meta_tags/favicon.rb
131
132
  - lib/dato/meta_tags/image.rb
132
133
  - lib/dato/meta_tags/og_locale.rb
133
134
  - lib/dato/meta_tags/og_meta_tag.rb
@@ -154,6 +155,7 @@ files:
154
155
  - spec/dato/field_type/video_spec.rb
155
156
  - spec/dato/json_api_entity_spec.rb
156
157
  - spec/dato/meta_tags/article_modified_time_spec.rb
158
+ - spec/dato/meta_tags/favicon_spec.rb
157
159
  - spec/dato/meta_tags/image_spec.rb
158
160
  - spec/dato/meta_tags/og_locale_spec.rb
159
161
  - spec/dato/record_spec.rb
@@ -192,6 +194,7 @@ test_files:
192
194
  - spec/dato/field_type/video_spec.rb
193
195
  - spec/dato/json_api_entity_spec.rb
194
196
  - spec/dato/meta_tags/article_modified_time_spec.rb
197
+ - spec/dato/meta_tags/favicon_spec.rb
195
198
  - spec/dato/meta_tags/image_spec.rb
196
199
  - spec/dato/meta_tags/og_locale_spec.rb
197
200
  - spec/dato/record_spec.rb