bigcartel-theme-fonts 1.8.1 → 1.8.3
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 +4 -4
- data/bigcartel-theme-fonts.gemspec +1 -1
- data/lib/bigcartel/theme/fonts/theme_font.rb +9 -6
- data/spec/theme_font_spec.rb +46 -22
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 2baed7db194a686348bf4ef821d7a0f139e4f4d7b2c400d7bb2afc1d3719c3b2
|
4
|
+
data.tar.gz: 2d406ddecc9e86a422261d71fc4bed68722872e65e7a6b55602904335ef2f626
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: d376e3f0da72ed79e202c0fdb3a79fe90acd8acb5fb87179768c15845470e95b2535b51509266bbfbe3f0d6558804a9a1a409e0081648e35d84d71f032b11d45
|
7
|
+
data.tar.gz: 1f9ab812bdedc4a77b3a5a591088b2e97687fad43ffd4707d111c88317879e88cf6f803183578a117600a3ded7d62580c22f6c2c405bde06f9ec8c32f12c3936
|
@@ -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.
|
7
|
+
spec.version = '1.8.3'
|
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.}
|
@@ -69,19 +69,22 @@ class ThemeFont < Struct.new(:name, :family, :weights, :collection)
|
|
69
69
|
def google_font_url_for_theme_json(account_theme)
|
70
70
|
# Cosmos and Lunch Break use the secondary font for the primary text font
|
71
71
|
font_setting = if ["cosmos", "lunch break"].include?(account_theme.theme.name.downcase)
|
72
|
-
account_theme.settings[
|
72
|
+
account_theme.settings[:secondary_font]
|
73
73
|
else
|
74
|
-
account_theme.settings[
|
75
|
-
account_theme.settings[
|
76
|
-
account_theme.settings[
|
77
|
-
account_theme.settings[
|
74
|
+
account_theme.settings[:primary_font] ||
|
75
|
+
account_theme.settings[:text_font] ||
|
76
|
+
account_theme.settings[:font] ||
|
77
|
+
account_theme.settings[:serif_font]
|
78
78
|
end
|
79
79
|
|
80
80
|
font = find_by_name(font_setting)
|
81
81
|
return {} if font.nil? || font.collection != 'google'
|
82
82
|
|
83
83
|
{
|
84
|
-
"primary_text_font" =>
|
84
|
+
"primary_text_font" => {
|
85
|
+
"name" => font.name,
|
86
|
+
"url" => "https://fonts.googleapis.com/css?family=#{font.name.gsub(' ', '+')}"
|
87
|
+
}
|
85
88
|
}
|
86
89
|
end
|
87
90
|
|
data/spec/theme_font_spec.rb
CHANGED
@@ -158,60 +158,75 @@ describe ThemeFont do
|
|
158
158
|
|
159
159
|
context "with default theme" do
|
160
160
|
it "uses primary_font when present" do
|
161
|
-
stub(account_theme).settings { {
|
161
|
+
stub(account_theme).settings { { primary_font: "One Font" } }
|
162
162
|
result = ThemeFont.google_font_url_for_theme_json(account_theme)
|
163
163
|
result.should == {
|
164
|
-
"primary_text_font" =>
|
164
|
+
"primary_text_font" => {
|
165
|
+
"name" => "One Font",
|
166
|
+
"url" => "https://fonts.googleapis.com/css?family=One+Font"
|
167
|
+
}
|
165
168
|
}
|
166
169
|
end
|
167
170
|
|
168
171
|
context "font setting fallback stack" do
|
169
172
|
it "falls back to text_font when primary_font is absent" do
|
170
|
-
stub(account_theme).settings { {
|
173
|
+
stub(account_theme).settings { { text_font: "Three" } }
|
171
174
|
result = ThemeFont.google_font_url_for_theme_json(account_theme)
|
172
175
|
result.should == {
|
173
|
-
"primary_text_font" =>
|
176
|
+
"primary_text_font" => {
|
177
|
+
"name" => "Three",
|
178
|
+
"url" => "https://fonts.googleapis.com/css?family=Three"
|
179
|
+
}
|
174
180
|
}
|
175
181
|
end
|
176
182
|
|
177
183
|
it "falls back to font when primary_font and text_font are absent" do
|
178
|
-
stub(account_theme).settings { {
|
184
|
+
stub(account_theme).settings { { font: "One Font" } }
|
179
185
|
result = ThemeFont.google_font_url_for_theme_json(account_theme)
|
180
186
|
result.should == {
|
181
|
-
"primary_text_font" =>
|
187
|
+
"primary_text_font" => {
|
188
|
+
"name" => "One Font",
|
189
|
+
"url" => "https://fonts.googleapis.com/css?family=One+Font"
|
190
|
+
}
|
182
191
|
}
|
183
192
|
end
|
184
193
|
|
185
194
|
it "falls back to serif_font when all others are absent" do
|
186
|
-
stub(account_theme).settings { {
|
195
|
+
stub(account_theme).settings { { serif_font: "Three" } }
|
187
196
|
result = ThemeFont.google_font_url_for_theme_json(account_theme)
|
188
197
|
result.should == {
|
189
|
-
"primary_text_font" =>
|
198
|
+
"primary_text_font" => {
|
199
|
+
"name" => "Three",
|
200
|
+
"url" => "https://fonts.googleapis.com/css?family=Three"
|
201
|
+
}
|
190
202
|
}
|
191
203
|
end
|
192
204
|
|
193
205
|
it "prefers primary_font over other settings" do
|
194
206
|
stub(account_theme).settings { {
|
195
|
-
|
196
|
-
|
197
|
-
|
198
|
-
|
207
|
+
primary_font: "One Font",
|
208
|
+
text_font: "Three",
|
209
|
+
font: "Three",
|
210
|
+
serif_font: "Three"
|
199
211
|
} }
|
200
212
|
result = ThemeFont.google_font_url_for_theme_json(account_theme)
|
201
213
|
result.should == {
|
202
|
-
"primary_text_font" =>
|
214
|
+
"primary_text_font" => {
|
215
|
+
"name" => "One Font",
|
216
|
+
"url" => "https://fonts.googleapis.com/css?family=One+Font"
|
217
|
+
}
|
203
218
|
}
|
204
219
|
end
|
205
220
|
end
|
206
221
|
|
207
222
|
it "returns empty hash for non-Google font" do
|
208
|
-
stub(account_theme).settings { {
|
223
|
+
stub(account_theme).settings { { primary_font: "Two" } }
|
209
224
|
result = ThemeFont.google_font_url_for_theme_json(account_theme)
|
210
225
|
result.should == {}
|
211
226
|
end
|
212
227
|
|
213
228
|
it "returns empty hash for unknown font" do
|
214
|
-
stub(account_theme).settings { {
|
229
|
+
stub(account_theme).settings { { primary_font: "Unknown" } }
|
215
230
|
result = ThemeFont.google_font_url_for_theme_json(account_theme)
|
216
231
|
result.should == {}
|
217
232
|
end
|
@@ -221,21 +236,27 @@ describe ThemeFont do
|
|
221
236
|
let(:theme) { double("Theme", name: "cosmos") }
|
222
237
|
|
223
238
|
it "uses secondary_font setting" do
|
224
|
-
stub(account_theme).settings { {
|
239
|
+
stub(account_theme).settings { { secondary_font: "Three" } }
|
225
240
|
result = ThemeFont.google_font_url_for_theme_json(account_theme)
|
226
241
|
result.should == {
|
227
|
-
"primary_text_font" =>
|
242
|
+
"primary_text_font" => {
|
243
|
+
"name" => "Three",
|
244
|
+
"url" => "https://fonts.googleapis.com/css?family=Three"
|
245
|
+
}
|
228
246
|
}
|
229
247
|
end
|
230
248
|
|
231
249
|
it "ignores primary_font when secondary_font is present" do
|
232
250
|
stub(account_theme).settings { {
|
233
|
-
|
234
|
-
|
251
|
+
secondary_font: "Three",
|
252
|
+
primary_font: "One Font"
|
235
253
|
} }
|
236
254
|
result = ThemeFont.google_font_url_for_theme_json(account_theme)
|
237
255
|
result.should == {
|
238
|
-
"primary_text_font" =>
|
256
|
+
"primary_text_font" => {
|
257
|
+
"name" => "Three",
|
258
|
+
"url" => "https://fonts.googleapis.com/css?family=Three"
|
259
|
+
}
|
239
260
|
}
|
240
261
|
end
|
241
262
|
end
|
@@ -244,10 +265,13 @@ describe ThemeFont do
|
|
244
265
|
let(:theme) { double("Theme", name: "lunch break") }
|
245
266
|
|
246
267
|
it "uses secondary_font setting" do
|
247
|
-
stub(account_theme).settings { {
|
268
|
+
stub(account_theme).settings { { secondary_font: "One Font" } }
|
248
269
|
result = ThemeFont.google_font_url_for_theme_json(account_theme)
|
249
270
|
result.should == {
|
250
|
-
"primary_text_font" =>
|
271
|
+
"primary_text_font" => {
|
272
|
+
"name" => "One Font",
|
273
|
+
"url" => "https://fonts.googleapis.com/css?family=One+Font"
|
274
|
+
}
|
251
275
|
}
|
252
276
|
end
|
253
277
|
end
|