Skip to content

Commit bbdf850

Browse files
authored
Add support for variables in text style (#507)
1 parent b29662d commit bbdf850

File tree

4 files changed

+25
-0
lines changed

4 files changed

+25
-0
lines changed

lib-es5/utils/index.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -106,6 +106,10 @@ var _require2 = require('./consts'),
106106
function textStyle(layer) {
107107
var keywords = [];
108108
var style = "";
109+
110+
if (!isEmpty(layer.text_style)) {
111+
return layer.text_style;
112+
}
109113
Object.keys(LAYER_KEYWORD_PARAMS).forEach(function (attr) {
110114
var default_value = LAYER_KEYWORD_PARAMS[attr];
111115
var attr_value = layer[attr] || default_value;

lib/utils/index.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,10 @@ const {
9393
function textStyle(layer) {
9494
let keywords = [];
9595
let style = "";
96+
97+
if (!isEmpty(layer.text_style)) {
98+
return layer.text_style;
99+
}
96100
Object.keys(LAYER_KEYWORD_PARAMS).forEach((attr) => {
97101
let default_value = LAYER_KEYWORD_PARAMS[attr];
98102
let attr_value = layer[attr] || default_value;

test/utils/utils_spec.js

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1268,6 +1268,22 @@ describe("utils", function () {
12681268
.emptyOptions();
12691269
});
12701270
});
1271+
it('should support text layer style identifier variables', function () {
1272+
const options = {
1273+
transformation: [
1274+
{
1275+
variables: [["$style", "!Arial_12!"]]
1276+
}, {
1277+
overlay: {
1278+
text: "hello-world",
1279+
text_style: "$style"
1280+
}
1281+
}
1282+
]
1283+
}
1284+
const url = cloudinary.utils.url("sample", options);
1285+
expect(url).to.eql(`http://res.cloudinary.com/${cloud_name}/image/upload/$style_!Arial_12!/l_text:$style:hello-world/sample`);
1286+
});
12711287
});
12721288
});
12731289
describe('build_eager', function () {

types/index.d.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -312,6 +312,7 @@ declare module 'cloudinary' {
312312
}
313313

314314
interface TextStyleOptions {
315+
text_style?: string;
315316
font_family?: string;
316317
font_size?: number;
317318
font_color?: string;

0 commit comments

Comments
 (0)