Skip to content

Commit ed30529

Browse files
committed
Merge pull request #13 from deini/quoteFont
BIG-25633: Now returning font-family wrapped in quotes
2 parents 0d62a55 + f03e397 commit ed30529

2 files changed

Lines changed: 14 additions & 3 deletions

File tree

lib/styles.js

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -255,7 +255,8 @@ module.exports = function StencilStyles() {
255255
* @returns {*}
256256
*/
257257
self.defaultFontParser = function(value, type) {
258-
var index = type === 'family' ? 0 : 1,
258+
var typeFamily = type === 'family',
259+
index = typeFamily ? 0 : 1,
259260
formattedString,
260261
split;
261262

@@ -273,6 +274,16 @@ module.exports = function StencilStyles() {
273274
formattedString = split[index].split(',')[0];
274275
formattedString = formattedString.replace(/\+/g, ' ');
275276

276-
return new Sass.types.String(formattedString);
277+
// Make sure the string has no quotes in it
278+
formattedString = formattedString.replace(/'|"/g, '');
279+
280+
if (typeFamily) {
281+
// Wrap the string in quotes since Sass type String
282+
// works with quotes and without quotes (it won't add them)
283+
// and we end up with font-family: Open Sans with no quotes
284+
formattedString = '"' + formattedString + '"';
285+
}
286+
287+
return Sass.types.String(formattedString);
277288
};
278289
};

test/styles.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -220,7 +220,7 @@ describe('Stencil-Styles Plugin', function () {
220220
it('should return the font family name', function(done) {
221221
var result = stencilStyles.defaultFontParser(nativeFont, 'family');
222222

223-
expect(result.getValue()).to.equal('Times New Roman');
223+
expect(result.getValue()).to.equal('"Times New Roman"');
224224

225225
done();
226226
});

0 commit comments

Comments
 (0)