bigcartel-theme-fonts 1.8.0 → 1.8.1
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 +15 -23
- data/spec/theme_font_spec.rb +82 -52
- 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: c24d66f05033aa4200161c1f0c2e1f76b2e2d7ffc05ebf2c7362d0402c83d731
|
4
|
+
data.tar.gz: c2c5567bbd85fa600d66c62d561984d9bd16cd7c60132f6684620d63112c99b3
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 4a321d1697c53a3dba38e686faa7dff2f7425ca78f604153e209dcfccaf2cfabd551dd7866bf99ed5b7f8f02e5dfb1260afd9fca1b3ca379ebe719a62b978792
|
7
|
+
data.tar.gz: 8ecd906210fdae6fd8ea4d7a239cc520d27630a9785b7631a2a124b2110bd9d41915a3a3e94f45c9b9c4aa539427e70cebb7b00ec7d70453c42fae96d03a2118
|
@@ -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.1'
|
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
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
.
|
78
|
-
|
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
|
-
|
80
|
+
font = find_by_name(font_setting)
|
81
|
+
return {} if font.nil? || font.collection != 'google'
|
85
82
|
|
86
|
-
|
87
|
-
|
88
|
-
|
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
|
data/spec/theme_font_spec.rb
CHANGED
@@ -144,8 +144,9 @@ describe ThemeFont do
|
|
144
144
|
end
|
145
145
|
end
|
146
146
|
|
147
|
-
describe ".
|
148
|
-
let(:
|
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
|
159
|
-
it "
|
160
|
-
settings
|
161
|
-
result = ThemeFont.
|
162
|
-
result.should ==
|
163
|
-
"
|
164
|
-
|
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
|
-
|
169
|
-
|
170
|
-
|
171
|
-
|
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
|
175
|
-
settings
|
176
|
-
result = ThemeFont.
|
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 "
|
181
|
-
settings
|
182
|
-
result = ThemeFont.
|
183
|
-
result.should ==
|
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
|
188
|
-
|
189
|
-
|
190
|
-
|
191
|
-
|
192
|
-
|
193
|
-
|
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
|
-
|
199
|
-
|
200
|
-
|
201
|
-
|
202
|
-
|
203
|
-
|
204
|
-
|
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
|
210
|
-
|
211
|
-
|
212
|
-
|
213
|
-
|
214
|
-
|
215
|
-
|
216
|
-
|
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
|