bigcartel-theme-fonts 1.8.0 → 1.8.2

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
  SHA256:
3
- metadata.gz: eda02a423d5ecebee3afd0f6ed53186cb01e1e8322073844ae90749f5ece7d73
4
- data.tar.gz: c903ea89b42f88293a8d31f1f951fa4694586b63da3b44de22bd7c09235ef18f
3
+ metadata.gz: d58b062226017f9cf542de6c90d1cdb4a2f6ffc780948745c497d7b0384ef4a1
4
+ data.tar.gz: a1f4600d2e543286f9a4312216387b183b0534734cc66bef62155a3a0f0ab2fc
5
5
  SHA512:
6
- metadata.gz: fdce3702961befcddfab26283c15993d791ac1a2f35c39ff5eec44f2909b01544b2f5022c1c2c45e14fb9e02a1ce39275696b7f562bdcdab3c17c293ac608869
7
- data.tar.gz: 4f32a6003308f29b986e63d43fcc03cf1522176c730a2a6d98ac52714295485bf05c1fb05ceda4dde40c725f8f064f113553c28c21b22cd9032fa47ba38b4a7e
6
+ metadata.gz: 1cc9c664c5678b0005512f22cfcf23f142bf158838adf52042535da9468a7a6a1d7c98d8841a034e5ed5b48b9acf9d132df2beb69aa38dfb10a03a10fbdcd3cf
7
+ data.tar.gz: 15cccfc9483a7391b06cc7fee064fdbc9f0e452ef02b933f71562c7f31ce560eadca6f1c38a9b9b58047a87c51f3cfe0b4e8388f260372e18eb747bef5564b8b
@@ -4,7 +4,7 @@ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
4
 
5
5
  Gem::Specification.new do |spec|
6
6
  spec.name = 'bigcartel-theme-fonts'
7
- spec.version = '1.8.0'
7
+ spec.version = '1.8.2'
8
8
  spec.authors = ['Big Cartel']
9
9
  spec.email = ['dev@bigcartel.com']
10
10
  spec.description = %q{A simple class for working with Big Cartel's supported theme fonts.}
@@ -66,31 +66,23 @@ class ThemeFont < Struct.new(:name, :family, :weights, :collection)
66
66
  google_fonts.empty? ? nil : google_font_url_for_fonts(google_fonts)
67
67
  end
68
68
 
69
- def google_font_url_for_theme_array(fonts, settings, options = {})
70
- defaults = {
71
- include_protocol: false,
72
- include_weights: true
73
- }
74
- opts = defaults.merge(options)
75
-
76
- google_fonts = fonts.keys.map { |key| settings[key] }.compact
77
- .map { |font_name| find_by_name(font_name) }
78
- .compact
79
- .select { |font| font.collection == 'google' }
80
- .sort_by { |font| font.name }
81
-
82
- return [] if google_fonts.empty?
69
+ def google_font_url_for_theme_json(account_theme)
70
+ # Cosmos and Lunch Break use the secondary font for the primary text font
71
+ font_setting = if ["cosmos", "lunch break"].include?(account_theme.theme.name.downcase)
72
+ account_theme.settings[:secondary_font]
73
+ else
74
+ account_theme.settings[:primary_font] ||
75
+ account_theme.settings[:text_font] ||
76
+ account_theme.settings[:font] ||
77
+ account_theme.settings[:serif_font]
78
+ end
83
79
 
84
- base_url = opts[:include_protocol] ? "https://fonts.googleapis.com/css?family=" : "//fonts.googleapis.com/css?family="
80
+ font = find_by_name(font_setting)
81
+ return {} if font.nil? || font.collection != 'google'
85
82
 
86
- google_fonts.map do |font|
87
- font_string = if opts[:include_weights] && font.weights
88
- "#{font.name}:#{font.weights}"
89
- else
90
- font.name
91
- end
92
- "#{base_url}#{font_string.gsub(' ', '+')}&display=swap"
93
- end
83
+ {
84
+ "primary_text_font" => "https://fonts.googleapis.com/css?family=#{font.name.gsub(' ', '+')}"
85
+ }
94
86
  end
95
87
 
96
88
  private
@@ -144,8 +144,9 @@ describe ThemeFont do
144
144
  end
145
145
  end
146
146
 
147
- describe ".google_font_url_for_theme_array" do
148
- let(:fonts) {{ :header_font => {}, :body_font => {}, :paragraph_font => {} }}
147
+ describe ".google_font_url_for_theme_json" do
148
+ let(:theme) { double("Theme", name: "default") }
149
+ let(:account_theme) { double("AccountTheme", theme: theme, settings: {}) }
149
150
 
150
151
  before(:each) do
151
152
  stub(ThemeFont).all {[
@@ -155,70 +156,99 @@ describe ThemeFont do
155
156
  ]}
156
157
  end
157
158
 
158
- context "with default options" do
159
- it "returns an array of URLs with weights and no protocol" do
160
- settings = { :header_font => 'One Font', :body_font => 'Two', :paragraph_font => 'Three' }
161
- result = ThemeFont.google_font_url_for_theme_array(fonts, settings)
162
- result.should == [
163
- "//fonts.googleapis.com/css?family=One+Font:400,700&display=swap",
164
- "//fonts.googleapis.com/css?family=Three:300,600&display=swap"
165
- ]
159
+ context "with default theme" do
160
+ it "uses primary_font when present" do
161
+ stub(account_theme).settings { { primary_font: "One Font" } }
162
+ result = ThemeFont.google_font_url_for_theme_json(account_theme)
163
+ result.should == {
164
+ "primary_text_font" => "https://fonts.googleapis.com/css?family=One+Font"
165
+ }
166
166
  end
167
167
 
168
- it "returns a single URL in array when only one Google font" do
169
- settings = { :header_font => 'One Font', :body_font => 'Two' }
170
- result = ThemeFont.google_font_url_for_theme_array(fonts, settings)
171
- result.should == ["//fonts.googleapis.com/css?family=One+Font:400,700&display=swap"]
168
+ context "font setting fallback stack" do
169
+ it "falls back to text_font when primary_font is absent" do
170
+ stub(account_theme).settings { { text_font: "Three" } }
171
+ result = ThemeFont.google_font_url_for_theme_json(account_theme)
172
+ result.should == {
173
+ "primary_text_font" => "https://fonts.googleapis.com/css?family=Three"
174
+ }
175
+ end
176
+
177
+ it "falls back to font when primary_font and text_font are absent" do
178
+ stub(account_theme).settings { { font: "One Font" } }
179
+ result = ThemeFont.google_font_url_for_theme_json(account_theme)
180
+ result.should == {
181
+ "primary_text_font" => "https://fonts.googleapis.com/css?family=One+Font"
182
+ }
183
+ end
184
+
185
+ it "falls back to serif_font when all others are absent" do
186
+ stub(account_theme).settings { { serif_font:"Three" } }
187
+ result = ThemeFont.google_font_url_for_theme_json(account_theme)
188
+ result.should == {
189
+ "primary_text_font" => "https://fonts.googleapis.com/css?family=Three"
190
+ }
191
+ end
192
+
193
+ it "prefers primary_font over other settings" do
194
+ stub(account_theme).settings { {
195
+ primary_font: "One Font",
196
+ text_font: "Three",
197
+ font: "Three",
198
+ serif_font: "Three"
199
+ } }
200
+ result = ThemeFont.google_font_url_for_theme_json(account_theme)
201
+ result.should == {
202
+ "primary_text_font" => "https://fonts.googleapis.com/css?family=One+Font"
203
+ }
204
+ end
172
205
  end
173
206
 
174
- it "returns empty array when no Google fonts" do
175
- settings = { :body_font => 'Two' }
176
- result = ThemeFont.google_font_url_for_theme_array(fonts, settings)
177
- result.should == []
207
+ it "returns empty hash for non-Google font" do
208
+ stub(account_theme).settings { { primary_font: "Two" } }
209
+ result = ThemeFont.google_font_url_for_theme_json(account_theme)
210
+ result.should == {}
178
211
  end
179
212
 
180
- it "deduplicates identical fonts" do
181
- settings = { :header_font => 'One Font', :body_font => 'One Font' }
182
- result = ThemeFont.google_font_url_for_theme_array(fonts, settings)
183
- result.should == ["//fonts.googleapis.com/css?family=One+Font:400,700&display=swap"]
213
+ it "returns empty hash for unknown font" do
214
+ stub(account_theme).settings { { primary_font: "Unknown" } }
215
+ result = ThemeFont.google_font_url_for_theme_json(account_theme)
216
+ result.should == {}
184
217
  end
185
218
  end
186
219
 
187
- context "with include_protocol: true" do
188
- it "returns URLs with https protocol" do
189
- settings = { :header_font => 'One Font', :paragraph_font => 'Three' }
190
- result = ThemeFont.google_font_url_for_theme_array(fonts, settings, include_protocol: true)
191
- result.should == [
192
- "https://fonts.googleapis.com/css?family=One+Font:400,700&display=swap",
193
- "https://fonts.googleapis.com/css?family=Three:300,600&display=swap"
194
- ]
220
+ context "with Cosmos theme" do
221
+ let(:theme) { double("Theme", name: "cosmos") }
222
+
223
+ it "uses secondary_font setting" do
224
+ stub(account_theme).settings { { secondary_font: "Three" } }
225
+ result = ThemeFont.google_font_url_for_theme_json(account_theme)
226
+ result.should == {
227
+ "primary_text_font" => "https://fonts.googleapis.com/css?family=Three"
228
+ }
195
229
  end
196
- end
197
230
 
198
- context "with include_weights: false" do
199
- it "returns URLs without weights" do
200
- settings = { :header_font => 'One Font', :paragraph_font => 'Three' }
201
- result = ThemeFont.google_font_url_for_theme_array(fonts, settings, include_weights: false)
202
- result.should == [
203
- "//fonts.googleapis.com/css?family=One+Font&display=swap",
204
- "//fonts.googleapis.com/css?family=Three&display=swap"
205
- ]
231
+ it "ignores primary_font when secondary_font is present" do
232
+ stub(account_theme).settings { {
233
+ secondary_font: "Three",
234
+ primary_font: "One Font"
235
+ } }
236
+ result = ThemeFont.google_font_url_for_theme_json(account_theme)
237
+ result.should == {
238
+ "primary_text_font" => "https://fonts.googleapis.com/css?family=Three"
239
+ }
206
240
  end
207
241
  end
208
242
 
209
- context "with both options customized" do
210
- it "returns URLs with protocol and no weights" do
211
- settings = { :header_font => 'One Font', :paragraph_font => 'Three' }
212
- result = ThemeFont.google_font_url_for_theme_array(
213
- fonts,
214
- settings,
215
- include_protocol: true,
216
- include_weights: false
217
- )
218
- result.should == [
219
- "https://fonts.googleapis.com/css?family=One+Font&display=swap",
220
- "https://fonts.googleapis.com/css?family=Three&display=swap"
221
- ]
243
+ context "with Lunch Break theme" do
244
+ let(:theme) { double("Theme", name: "lunch break") }
245
+
246
+ it "uses secondary_font setting" do
247
+ stub(account_theme).settings { { secondary_font: "One Font" } }
248
+ result = ThemeFont.google_font_url_for_theme_json(account_theme)
249
+ result.should == {
250
+ "primary_text_font" => "https://fonts.googleapis.com/css?family=One+Font"
251
+ }
222
252
  end
223
253
  end
224
254
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: bigcartel-theme-fonts
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.8.0
4
+ version: 1.8.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Big Cartel