Skip to content
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 8 additions & 7 deletions Cloudinary/Classes/Core/Features/Helpers/CLDExpression.swift
Original file line number Diff line number Diff line change
Expand Up @@ -286,15 +286,16 @@ import Foundation
// MARK: - provide content
public func asString() -> String {

guard !currentKey.isEmpty && !currentValue.isEmpty else {

return String()
}
guard !currentKey.isEmpty else { return String() }

let key = replaceAllExpressionKeys(in: currentKey)
let value = removeExtraDashes(from: replaceAllUnencodeChars(in: currentValue))
let key = replaceAllExpressionKeys(in: currentKey)

return "\(key)_\(value)"
if currentValue.isEmpty {
return "\(key)"
} else {
let value = removeExtraDashes(from: replaceAllUnencodeChars(in: currentValue))
return "\(key)_\(value)"
}
}

public func asParams() -> [String : String] {
Expand Down
13 changes: 13 additions & 0 deletions Cloudinary/Classes/Core/Features/Helpers/Layers/CLDTextLayer.swift
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,19 @@ import Foundation
return self
}

/**
Sets a text style identifier using an expression.
Note: If this is used, all other style attributes are ignored in favor of this identifier

- parameter text: An expression instance referencing the style.

- returns: The same instance of CLDTextLayer.
*/
open func setTextStyle(expression: CLDExpression) -> CLDTextLayer {
self.textStyle = expression.asString()
return self
}

/**
Set the name of a font family. e.g. `arial`.

Expand Down
2 changes: 2 additions & 0 deletions Example/Tests/GenerateUrlTests/UrlTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -1055,6 +1055,8 @@ class UrlTests: BaseTestCase {

func testTextStyle() {
XCTAssertEqual(sut?.createUrl().setTransformation(CLDTransformation().setVariable("$style", string: "!Arial_12!").chain().setOverlayWithLayer(CLDTextLayer().setText(text: "hello-world").setTextStyle(textStyle: "$style"))).generate("test"), "\(prefix)/image/upload/$style_!Arial_12!/l_text:$style:hello-world/test")

XCTAssertEqual(sut?.createUrl().setTransformation(CLDTransformation().setVariable("$style", string: "!Arial_12!").chain().setOverlayWithLayer(CLDTextLayer().setText(text: "hello-world").setTextStyle(expression: CLDExpression(value: "$style")))).generate("test"), "\(prefix)/image/upload/$style_!Arial_12!/l_text:$style:hello-world/test")
}

func testTextStyleOverpowerOtherTextAttributes() {
Expand Down