Skip to content

Commit

Permalink
url conversion for @font-face declarations
Browse files Browse the repository at this point in the history
  • Loading branch information
bago committed May 31, 2022
1 parent c50fc62 commit 37fa7d5
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 0 deletions.
10 changes: 10 additions & 0 deletions spec/stylesheet-spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ describe('Stylesheet declaration processor', function() {
var processStylesheetRules;
var mockery = require('mockery');

var templateUrlConverter = function(url) { return 'https://PREFIXED/'+url; };

var mockedWithBindingProvider = function(x, y, a, b) {
return "$" + x + '.' + a + "[" + b + "]";
};
Expand Down Expand Up @@ -179,6 +181,14 @@ describe('Stylesheet declaration processor', function() {
// console.log("BBB", blockDefsUpdater.calls);
});

it('should parse @font-face definitions, mainly for template url prefixing', function() {
var result;
var blockDefsUpdater = jasmine.createSpy("blockDefsUpdater");
result = processStylesheetRules('@font-face { src: url("../fonts/Calibri.woff") format("woff"), url("../fonts/Calibri.woff2") format("woff2"); }', undefined, mockedWithBindingProvider, undefined, undefined, templateUrlConverter, 'template', 'block');
expect(result).toEqual('@font-face { src: url("https://PREFIXED/../fonts/Calibri.woff") format("woff"), url("https://PREFIXED/../fonts/Calibri.woff2") format("woff2"); }');
});


afterAll(function() {
mockery.disable();
mockery.deregisterAll();
Expand Down
3 changes: 3 additions & 0 deletions src/js/converter/stylesheet.js
Original file line number Diff line number Diff line change
Expand Up @@ -175,6 +175,9 @@ var processStylesheetRules = function(style, rules, localWithBindingProvider, bl
if (elaboratedStyle !== null) newStyle = elaboratedStyle;

newStyle = converterUtils.removeStyle(newStyle, rules[i].position.start, rules[i].position.end, 0, 0, 0, newSel);
} else if (rules[i].type == 'font-face') {
var elaboratedFF = elaborateDeclarations(newStyle, rules[i].declarations, templateUrlConverter, bindingProvider);
if (elaboratedFF !== null) newStyle = elaboratedFF;
} else {
console.log("Unknown rule type", rules[i].type, "while parsing <style> rules");
}
Expand Down

0 comments on commit 37fa7d5

Please sign in to comment.