Skip to content

Commit 7e7a70e

Browse files
committed
Merge branch 'release/3.6.1'
2 parents f81aa4c + fa1cf5b commit 7e7a70e

File tree

6 files changed

+33
-16
lines changed

6 files changed

+33
-16
lines changed

ExampleiOS/ViewController.swift

+17
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,23 @@ class ViewController: UIViewController {
1717
override func viewDidLoad() {
1818
super.viewDidLoad()
1919

20+
let text = """
21+
- <img named="check" att="5"/> Performed!
22+
"""
23+
let base = Style {
24+
$0.font = UIFont.boldSystemFont(ofSize: 14)
25+
$0.color = UIColor(hexString: "#8E8E8E")
26+
}
27+
28+
let xmlStyle = StyleXML(base: base)
29+
xmlStyle.imageProvider = { imageName, attributes in
30+
fatalError()
31+
}
32+
33+
self.textView?.attributedText = text.set(style: xmlStyle)
34+
35+
return
36+
2037
// self.textView?.attributedText = "ciao ciao " + AttributedString(image: UIImage(named: "rocket")!,
2138
// bounds: CGRect(x: 0, y: -20, width: 25, height: 25)) + "ciao ciao"
2239
//

README.md

+2-2
Original file line numberDiff line numberDiff line change
@@ -539,7 +539,7 @@ This is the result:
539539
Sometimes you may want to provide these images lazily. In order to do it just provide a custom implementation of the `imageProvider` callback in `StyleXML` instance:
540540

541541
```swift
542-
let xmlText = "- <img named=\"check\"/> has done!"
542+
let xmlText = "- <img named=\"check\" background=\"#0000\"/> has done!"
543543

544544
let xmlStyle = StyleXML(base: {
545545
/// some attributes for base style
@@ -548,7 +548,7 @@ let xmlStyle = StyleXML(base: {
548548
// This method is called when a new `img` tag is found. It's your chance to
549549
// return a custom image. If you return `nil` (or you don't implement this method)
550550
// image is searched inside any bundled `xcasset` file.
551-
xmlStyle.imageProvider = { imageName in
551+
xmlStyle.imageProvider = { (imageName, attributes) in
552552
switch imageName {
553553
case "check":
554554
// create & return your own image

Sources/SwiftRichString/Style/StyleGroup.swift

+1-1
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ public class StyleXML: StyleProtocol {
5656

5757
/// Image provider is called to provide custom image when `StyleXML` encounter a `img` tag image.
5858
/// If not implemented the image is automatically searched inside any bundled `xcassets`.
59-
public var imageProvider: ((String) -> Image?)? = nil
59+
public var imageProvider: ((_ name: String, _ attributes: [String: String]?) -> Image?)? = nil
6060

6161
/// Dynamic attributes resolver.
6262
/// By default the `StandardXMLAttributesResolver` instance is used.

Sources/SwiftRichString/Support/XMLDynamicAttributesResolver.swift

+4-4
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ public protocol XMLDynamicAttributesResolver {
4747
/// - Parameters:
4848
/// - name: name of the image to get.
4949
/// - fromStyle: caller instance of `StyleXML.
50-
func imageWithName(_ name: String, fromStyle style: StyleXML) -> Image?
50+
func image(name: String, attributes: [String: String]?, fromStyle style: StyleXML) -> Image?
5151

5252
/// You are receiving this event when SwiftRichString correctly render an existing tag but the tag
5353
/// contains extra attributes you may want to handle.
@@ -75,8 +75,8 @@ public protocol XMLDynamicAttributesResolver {
7575

7676
extension XMLDynamicAttributesResolver {
7777

78-
public func imageWithName(_ name: String, fromStyle style: StyleXML) -> Image? {
79-
guard let mappedImage = style.imageProvider?(name) else {
78+
public func image(name: String, attributes: [String: String]?, fromStyle style: StyleXML) -> Image? {
79+
guard let mappedImage = style.imageProvider?(name, attributes) else {
8080
return Image(named: name) // xcassets fallback
8181
}
8282

@@ -124,7 +124,7 @@ open class StandardXMLAttributesResolver: XMLDynamicAttributesResolver {
124124
#if os(iOS) || os(OSX)
125125
// Local Image support
126126
if let imageName = attributes?["named"] {
127-
if let image = imageWithName(imageName, fromStyle: fromStyle),
127+
if let image = image(name: imageName, attributes: attributes, fromStyle: fromStyle),
128128
let imageString = AttributedString(image: image, bounds: attributes?["rect"]) {
129129
attributedString.append(imageString)
130130
}

SwiftRichString.podspec

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
Pod::Spec.new do |s|
22
s.name = "SwiftRichString"
3-
s.version = "3.6.0"
3+
s.version = "3.6.1"
44
s.summary = "Elegant Strings & Attributed Strings Toolkit for Swift"
55
s.description = <<-DESC
66
SwiftRichString is the best toolkit to work easily with Strings and Attributed Strings.

SwiftRichString.xcodeproj/project.pbxproj

+8-8
Original file line numberDiff line numberDiff line change
@@ -1640,7 +1640,7 @@
16401640
IPHONEOS_DEPLOYMENT_TARGET = 8.0;
16411641
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @loader_path/Frameworks";
16421642
MACOSX_DEPLOYMENT_TARGET = 10.11;
1643-
MARKETING_VERSION = 3.6.0;
1643+
MARKETING_VERSION = 3.6.1;
16441644
ONLY_ACTIVE_ARCH = NO;
16451645
PRODUCT_BUNDLE_IDENTIFIER = "com.SwiftRichString.SwiftRichString-iOS";
16461646
PRODUCT_NAME = SwiftRichString;
@@ -1666,7 +1666,7 @@
16661666
IPHONEOS_DEPLOYMENT_TARGET = 8.0;
16671667
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @loader_path/Frameworks";
16681668
MACOSX_DEPLOYMENT_TARGET = 10.11;
1669-
MARKETING_VERSION = 3.6.0;
1669+
MARKETING_VERSION = 3.6.1;
16701670
PRODUCT_BUNDLE_IDENTIFIER = "com.SwiftRichString.SwiftRichString-iOS";
16711671
PRODUCT_NAME = SwiftRichString;
16721672
SKIP_INSTALL = YES;
@@ -1718,7 +1718,7 @@
17181718
IPHONEOS_DEPLOYMENT_TARGET = 9.0;
17191719
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @loader_path/Frameworks";
17201720
MACOSX_DEPLOYMENT_TARGET = 10.11;
1721-
MARKETING_VERSION = 3.5.0;
1721+
MARKETING_VERSION = 3.6.1;
17221722
PRODUCT_BUNDLE_IDENTIFIER = "com.SwiftRichString.SwiftRichString-watchOS";
17231723
PRODUCT_NAME = SwiftRichString;
17241724
SDKROOT = watchos;
@@ -1745,7 +1745,7 @@
17451745
IPHONEOS_DEPLOYMENT_TARGET = 9.0;
17461746
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @loader_path/Frameworks";
17471747
MACOSX_DEPLOYMENT_TARGET = 10.11;
1748-
MARKETING_VERSION = 3.5.0;
1748+
MARKETING_VERSION = 3.6.1;
17491749
PRODUCT_BUNDLE_IDENTIFIER = "com.SwiftRichString.SwiftRichString-watchOS";
17501750
PRODUCT_NAME = SwiftRichString;
17511751
SDKROOT = watchos;
@@ -1772,7 +1772,7 @@
17721772
IPHONEOS_DEPLOYMENT_TARGET = 9.0;
17731773
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @loader_path/Frameworks";
17741774
MACOSX_DEPLOYMENT_TARGET = 10.11;
1775-
MARKETING_VERSION = 3.5.0;
1775+
MARKETING_VERSION = 3.6.1;
17761776
PRODUCT_BUNDLE_IDENTIFIER = "com.SwiftRichString.SwiftRichString-tvOS";
17771777
PRODUCT_NAME = SwiftRichString;
17781778
SDKROOT = appletvos;
@@ -1799,7 +1799,7 @@
17991799
IPHONEOS_DEPLOYMENT_TARGET = 9.0;
18001800
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @loader_path/Frameworks";
18011801
MACOSX_DEPLOYMENT_TARGET = 10.11;
1802-
MARKETING_VERSION = 3.5.0;
1802+
MARKETING_VERSION = 3.6.1;
18031803
PRODUCT_BUNDLE_IDENTIFIER = "com.SwiftRichString.SwiftRichString-tvOS";
18041804
PRODUCT_NAME = SwiftRichString;
18051805
SDKROOT = appletvos;
@@ -1828,7 +1828,7 @@
18281828
IPHONEOS_DEPLOYMENT_TARGET = 9.0;
18291829
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/../Frameworks @loader_path/Frameworks";
18301830
MACOSX_DEPLOYMENT_TARGET = 10.11;
1831-
MARKETING_VERSION = 3.5.0;
1831+
MARKETING_VERSION = 3.6.1;
18321832
PRODUCT_BUNDLE_IDENTIFIER = "com.SwiftRichString.SwiftRichString-macOS";
18331833
PRODUCT_NAME = SwiftRichString;
18341834
SDKROOT = macosx;
@@ -1855,7 +1855,7 @@
18551855
IPHONEOS_DEPLOYMENT_TARGET = 9.0;
18561856
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/../Frameworks @loader_path/Frameworks";
18571857
MACOSX_DEPLOYMENT_TARGET = 10.11;
1858-
MARKETING_VERSION = 3.5.0;
1858+
MARKETING_VERSION = 3.6.1;
18591859
PRODUCT_BUNDLE_IDENTIFIER = "com.SwiftRichString.SwiftRichString-macOS";
18601860
PRODUCT_NAME = SwiftRichString;
18611861
SDKROOT = macosx;

0 commit comments

Comments
 (0)