bigcartel-theme-fonts 1.2.0 → 1.3.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: f43edfee9943ab660cd6a9769b3b135c6a41b1c8ff4ec5c0388bd7309023f2c7
4
- data.tar.gz: f03554bfad9c4b75cfa4c23c42b8bb51773b9903c472fdad0bb2f5ea4c8e60c1
3
+ metadata.gz: e9c62987d04b87cd2bc97b94d0b67b3788e8651cc35b8867fd6b2b765e8c7c8a
4
+ data.tar.gz: 920a5db7b7da48287c1911206228a01e61006e3cac164d01b5de19d7caeaa48e
5
5
  SHA512:
6
- metadata.gz: 1a59d9bcd61be1f1c6058342d731802a295ecb2009389b12386947c435bd5cfce7a0fb122297276b404626239d638613cf888d60a0ad59afc770daa58d9d07d0
7
- data.tar.gz: 35cfdd4ed6e703688a614c13d383b985894d05a6ebad61cce267539298af3c1c442a2bd673d8401b28c1b53c1a50f67f797b353d81fdcc89bbc81d407132fa02
6
+ metadata.gz: 1e3f4dd696bf60146c3a0564ef3b3db5b09d15d942e694d370c384988313607e6b42aa7eef43d490cd8dec497e33a4a5cf4df454216c8b55dba6f87b92afe1a5
7
+ data.tar.gz: a3d3318ce640fac9ac81b4822f64c8138e1da74c363b9d637fb2e5174920abdfa777cc460d2df9408f75dfc8fdeb190966d7a287da2e6919dec78b05cf63a6de
@@ -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.2.0'
7
+ spec.version = '1.3.0'
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.}
@@ -1,12 +1,12 @@
1
1
  require 'yaml'
2
2
 
3
- class ThemeFont < Struct.new(:name, :family, :collection)
3
+ class ThemeFont < Struct.new(:name, :family, :weights, :collection)
4
4
  class << self
5
5
  def all
6
6
  @@all ||= Array.new.tap { |fonts|
7
7
  source.each_pair { |collection, collection_fonts|
8
8
  collection_fonts.values.each { |font|
9
- fonts << ThemeFont.new(font['name'], font['family'], collection)
9
+ fonts << ThemeFont.new(font['name'], font['family'], font['weights'], collection)
10
10
  }
11
11
  }
12
12
  }.sort_by { |font| font.name }
@@ -30,22 +30,39 @@ class ThemeFont < Struct.new(:name, :family, :collection)
30
30
  end
31
31
  end
32
32
 
33
- def google_font_names
34
- @@google_font_names ||= all.select { |font|
33
+ def google_fonts
34
+ @@google_fonts ||= all.select { |font|
35
35
  font.collection == 'google'
36
- }.map(&:name)
36
+ }
37
+ end
38
+
39
+ def google_font_names
40
+ google_fonts.map(&:name)
37
41
  end
38
42
 
39
43
  def google_font_url_for_fonts(fonts)
44
+ fonts = fonts.map do |font|
45
+ if font.kind_of? ThemeFont
46
+ font.weights ? "#{font.name}:#{font.weights}" : font.name
47
+ else
48
+ font
49
+ end
50
+ end
51
+
40
52
  "//fonts.googleapis.com/css?family=#{ fonts.uniq.map { |font| font.gsub(' ', '+') }.join('|') }"
41
53
  end
42
54
 
43
55
  def google_font_url_for_all_fonts
44
- google_font_url_for_fonts(google_font_names)
56
+ google_font_url_for_fonts(google_fonts)
45
57
  end
46
58
 
47
59
  def google_font_url_for_theme(fonts, settings)
48
- google_fonts = fonts.keys.map { |key| settings[key] }.select { |font_name| google_font_names.include? font_name }.sort
60
+ google_fonts = fonts.keys.map { |key| settings[key] }.compact.
61
+ map { |font_name| find_by_name font_name }.
62
+ compact.
63
+ select { |font| font.collection == 'google' }.
64
+ sort_by { |font| font.name }
65
+
49
66
  google_fonts.empty? ? nil : google_font_url_for_fonts(google_fonts)
50
67
  end
51
68
 
@@ -60,10 +60,12 @@ google:
60
60
  amaranth:
61
61
  name: Amaranth
62
62
  family: '"Amaranth", serif'
63
+ weights: "400,700"
63
64
 
64
65
  arvo:
65
66
  name: Arvo
66
67
  family: '"Arvo", serif'
68
+ weights: "400,700"
67
69
 
68
70
  asap:
69
71
  name: Asap
@@ -84,6 +86,7 @@ google:
84
86
  chivo:
85
87
  name: Chivo
86
88
  family: '"Chivo", sans-serif'
89
+ weights: "400,700"
87
90
 
88
91
  cutive:
89
92
  name: Cutive
@@ -100,10 +103,12 @@ google:
100
103
  dosis:
101
104
  name: Dosis
102
105
  family: '"Dosis", sans-serif'
106
+ weights: "400,700"
103
107
 
104
108
  enriqueta:
105
109
  name: Enriqueta
106
110
  family: '"Enriqueta", serif'
111
+ weights: "400,700"
107
112
 
108
113
  fauna_one:
109
114
  name: Fauna One
@@ -116,10 +121,12 @@ google:
116
121
  gentium_book_basic:
117
122
  name: Gentium Book Basic
118
123
  family: '"Gentium Book Basic", serif'
124
+ weights: "400,700"
119
125
 
120
126
  glegoo:
121
127
  name: Glegoo
122
128
  family: '"Glegoo", serif'
129
+ weights: "400,700"
123
130
 
124
131
  goudy_bookletter_1911:
125
132
  name: Goudy Bookletter 1911
@@ -128,38 +135,47 @@ google:
128
135
  inconsolata:
129
136
  name: Inconsolata
130
137
  family: '"Inconsolata", sans-serif'
138
+ weights: "400,700"
131
139
 
132
140
  karla:
133
141
  name: Karla
134
142
  family: '"Karla", sans-serif'
143
+ weights: "400,700"
135
144
 
136
145
  lato:
137
146
  name: Lato
138
147
  family: '"Lato", sans-serif'
148
+ weights: "400,700"
139
149
 
140
150
  lekton:
141
151
  name: Lekton
142
152
  family: '"Lekton", sans-serif'
143
-
153
+ weights: "400,700"
154
+
144
155
  libre_baskerville:
145
156
  name: Libre Baskerville
146
157
  family: '"Libre Baskerville", serif'
158
+ weights: 400,700
147
159
 
148
160
  lobster_two:
149
161
  name: Lobster Two
150
162
  family: '"Lobster Two", cursive'
163
+ weights: "400,700"
151
164
 
152
165
  merriweather:
153
166
  name: Merriweather
154
167
  family: '"Merriweather", serif'
168
+ weights: "400,700"
155
169
 
156
170
  montserrat:
157
171
  name: Montserrat
158
172
  family: '"Montserrat", sans-serif'
173
+ weights: "400,500,700"
159
174
 
160
175
  muli:
161
176
  name: Muli
162
177
  family: '"Muli", sans-serif'
178
+ weights: "400,700,900"
163
179
 
164
180
  nixie_one:
165
181
  name: Nixie One
@@ -168,46 +184,57 @@ google:
168
184
  open_sans:
169
185
  name: Open Sans
170
186
  family: '"Open Sans", sans-serif'
187
+ weights: "400,700"
171
188
 
172
189
  overlock:
173
190
  name: Overlock
174
191
  family: '"Overlock", cursive'
192
+ weights: "400,700"
175
193
 
176
194
  noticia_text:
177
195
  name: Noticia Text
178
196
  family: '"Noticia Text", serif'
197
+ weights: "400,700"
179
198
 
180
199
  playfair_display:
181
200
  name: Playfair Display
182
201
  family: '"Playfair Display", serif'
202
+ weights: "400,700"
183
203
 
184
204
  pt_serif:
185
205
  name: PT Serif
186
206
  family: '"PT Serif", serif'
207
+ weights: "400,700"
187
208
 
188
209
  raleway:
189
210
  name: Raleway
190
211
  family: '"Raleway", sans-serif'
212
+ weights: "400,700"
191
213
 
192
214
  roboto:
193
215
  name: Roboto
194
216
  family: '"Roboto", sans-serif'
217
+ weights: "400,700"
195
218
 
196
219
  rokkitt:
197
220
  name: Rokkitt
198
221
  family: '"Rokkitt", serif'
222
+ weights: "400,700"
199
223
 
200
224
  signika:
201
225
  name: Signika
202
226
  family: '"Signika", sans-serif'
227
+ weights: "400,700"
203
228
 
204
229
  source_sans_pro:
205
230
  name: Source Sans Pro
206
231
  family: '"Source Sans Pro", sans-serif'
232
+ weights: "400,700"
207
233
 
208
234
  titillium_web:
209
235
  name: Titillium Web
210
236
  family: '"Titillium Web", sans-serif'
237
+ weights: "400,700"
211
238
 
212
239
  vampiro_one:
213
240
  name: Vampiro One
@@ -220,3 +247,4 @@ google:
220
247
  work_sans:
221
248
  name: Work Sans
222
249
  family: '"Work Sans", sans-serif'
250
+ weights: "400,600,700"
@@ -6,7 +6,7 @@ describe ThemeFont do
6
6
  ThemeFont.send(:remove_class_variable, :@@source) rescue nil
7
7
  ThemeFont.send(:remove_class_variable, :@@all) rescue nil
8
8
  ThemeFont.send(:remove_class_variable, :@@options) rescue nil
9
- ThemeFont.send(:remove_class_variable, :@@google_font_names) rescue nil
9
+ ThemeFont.send(:remove_class_variable, :@@google_fonts) rescue nil
10
10
  end
11
11
 
12
12
  describe ".all" do
@@ -60,9 +60,9 @@ describe ThemeFont do
60
60
  describe ".google_font_names" do
61
61
  before(:each) do
62
62
  stub(ThemeFont).all {[
63
- ThemeFont.new('One Font', 'One Family', 'google'),
64
- ThemeFont.new('Two', 'Two Family', 'default'),
65
- ThemeFont.new('Three', 'Three Family', 'google')
63
+ ThemeFont.new('One Font', 'One Family', nil, 'google'),
64
+ ThemeFont.new('Two', 'Two Family', nil, 'default'),
65
+ ThemeFont.new('Three', 'Three Families', nil, 'google')
66
66
  ]}
67
67
  end
68
68
 
@@ -83,19 +83,32 @@ describe ThemeFont do
83
83
  it "should only use unique font names" do
84
84
  ThemeFont.google_font_url_for_fonts(['Yeah', 'Buddy', 'Yeah']).should == "//fonts.googleapis.com/css?family=Yeah|Buddy"
85
85
  end
86
+
87
+ context "when the fonts are an array of ThemeFonts" do
88
+ let(:fonts) do
89
+ [
90
+ ThemeFont.new('One Font', 'One Family', '400,500', 'google'),
91
+ ThemeFont.new('Two Font', 'Two Families', '500,700,800', 'google')
92
+ ]
93
+ end
94
+
95
+ it "includes font weights in the URL" do
96
+ ThemeFont.google_font_url_for_fonts(fonts).should == "//fonts.googleapis.com/css?family=One+Font:400,500|Two+Font:500,700,800"
97
+ end
98
+ end
86
99
  end
87
100
 
88
101
  describe ".google_font_url_for_all_fonts" do
89
102
  before(:each) do
90
103
  stub(ThemeFont).all {[
91
- ThemeFont.new('One Font', 'One Family', 'google'),
92
- ThemeFont.new('Two', 'Two Family', 'default'),
93
- ThemeFont.new('Three', 'Three Family', 'google')
104
+ ThemeFont.new('One Font', 'One Family', nil, 'google'),
105
+ ThemeFont.new('Two', 'Two Family', nil, 'default'),
106
+ ThemeFont.new('Three', 'Three Family', '400,600', 'google')
94
107
  ]}
95
108
  end
96
109
 
97
110
  it "should return a URL for all Google fonts" do
98
- ThemeFont.google_font_url_for_all_fonts.should == "//fonts.googleapis.com/css?family=One+Font|Three"
111
+ ThemeFont.google_font_url_for_all_fonts.should == "//fonts.googleapis.com/css?family=One+Font|Three:400,600"
99
112
  end
100
113
  end
101
114
 
@@ -104,20 +117,25 @@ describe ThemeFont do
104
117
 
105
118
  before(:each) do
106
119
  stub(ThemeFont).all {[
107
- ThemeFont.new('One Font', 'One Family', 'google'),
108
- ThemeFont.new('Two', 'Two Family', 'default'),
109
- ThemeFont.new('Three', 'Three Family', 'google')
120
+ ThemeFont.new('One Font', 'One Family', '400,700', 'google'),
121
+ ThemeFont.new('Two', 'Two Family', nil, 'default'),
122
+ ThemeFont.new('Three', 'Three Family', nil, 'google')
110
123
  ]}
111
124
  end
112
125
 
113
126
  it "should return a URL if a theme has multiple" do
114
127
  settings = { :header_font => 'One Font', :body_font => 'Two', :paragraph_font => 'Three' }
115
- ThemeFont.google_font_url_for_theme(fonts, settings).should == "//fonts.googleapis.com/css?family=One+Font|Three"
128
+ ThemeFont.google_font_url_for_theme(fonts, settings).should == "//fonts.googleapis.com/css?family=One+Font:400,700|Three"
116
129
  end
117
130
 
118
131
  it "should return single font name if a theme has one" do
119
132
  settings = { :header_font => 'One Font', :body_font => 'Two' }
120
- ThemeFont.google_font_url_for_theme(fonts, settings).should == "//fonts.googleapis.com/css?family=One+Font"
133
+ ThemeFont.google_font_url_for_theme(fonts, settings).should == "//fonts.googleapis.com/css?family=One+Font:400,700"
134
+ end
135
+
136
+ it "should dedup" do
137
+ settings = { :header_font => 'One Font', :body_font => 'One Font' }
138
+ ThemeFont.google_font_url_for_theme(fonts, settings).should == "//fonts.googleapis.com/css?family=One+Font:400,700"
121
139
  end
122
140
 
123
141
  it "should return nil if a theme has none" do
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: bigcartel-theme-fonts
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.2.0
4
+ version: 1.3.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Big Cartel
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2018-04-06 00:00:00.000000000 Z
11
+ date: 2018-04-30 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler