Skip to content

Commit 910732d

Browse files
Merge pull request #9 from contentstack/fix/CS-38901-nested-asset
Fix: Nested asset and mark type break
2 parents c989425 + 3d15b40 commit 910732d

12 files changed

Lines changed: 96 additions & 36 deletions

File tree

.github/workflows/sca-scan.yml

Lines changed: 0 additions & 15 deletions
This file was deleted.

ContentstackUtils.podspec

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
Pod::Spec.new do |s|
22
s.name = 'ContentstackUtils'
3-
s.version = '1.2.1'
3+
s.version = '1.3.0'
44
s.summary = 'Contentstack is a headless CMS with an API-first approach that puts content at the centre.'
55

66
s.description = <<-DESC
@@ -16,10 +16,10 @@ s.source = { :git => 'https://github.com/contentstack/contentstack-uti
1616
s.social_media_url = 'https://twitter.com/Contentstack'
1717
s.swift_version = '5.0'
1818

19-
s.ios.deployment_target = '10.1'
20-
s.osx.deployment_target = '10.12'
21-
s.tvos.deployment_target = "10.0"
22-
s.watchos.deployment_target = "3.0"
19+
s.ios.deployment_target = '11.0'
20+
s.osx.deployment_target = '10.13'
21+
s.tvos.deployment_target = "11.0"
22+
s.watchos.deployment_target = "4.0"
2323

2424
s.source_files = 'Sources/**/*.{swift}'
2525
s.framework = "Foundation"

ContentstackUtils.xcodeproj/project.pbxproj

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -590,7 +590,7 @@
590590
INFOPLIST_FILE = ContentstackUtils.xcodeproj/ContentstackUtils_Info.plist;
591591
IPHONEOS_DEPLOYMENT_TARGET = 8.0;
592592
LD_RUNPATH_SEARCH_PATHS = "$(inherited) $(TOOLCHAIN_DIR)/usr/lib/swift/macosx";
593-
MACOSX_DEPLOYMENT_TARGET = 10.10;
593+
MACOSX_DEPLOYMENT_TARGET = 10.13;
594594
MARKETING_VERSION = 1.2.1;
595595
OTHER_CFLAGS = "$(inherited)";
596596
OTHER_LDFLAGS = "$(inherited)";
@@ -604,8 +604,8 @@
604604
SWIFT_INSTALL_OBJC_HEADER = NO;
605605
SWIFT_VERSION = 5.0;
606606
TARGET_NAME = ContentstackUtils;
607-
TVOS_DEPLOYMENT_TARGET = 9.0;
608-
WATCHOS_DEPLOYMENT_TARGET = 2.0;
607+
TVOS_DEPLOYMENT_TARGET = 11.0;
608+
WATCHOS_DEPLOYMENT_TARGET = 4.0;
609609
};
610610
name = Debug;
611611
};
@@ -622,7 +622,7 @@
622622
INFOPLIST_FILE = ContentstackUtils.xcodeproj/ContentstackUtils_Info.plist;
623623
IPHONEOS_DEPLOYMENT_TARGET = 8.0;
624624
LD_RUNPATH_SEARCH_PATHS = "$(inherited) $(TOOLCHAIN_DIR)/usr/lib/swift/macosx";
625-
MACOSX_DEPLOYMENT_TARGET = 10.10;
625+
MACOSX_DEPLOYMENT_TARGET = 10.13;
626626
MARKETING_VERSION = 1.2.1;
627627
OTHER_CFLAGS = "$(inherited)";
628628
OTHER_LDFLAGS = "$(inherited)";
@@ -636,8 +636,8 @@
636636
SWIFT_INSTALL_OBJC_HEADER = NO;
637637
SWIFT_VERSION = 5.0;
638638
TARGET_NAME = ContentstackUtils;
639-
TVOS_DEPLOYMENT_TARGET = 9.0;
640-
WATCHOS_DEPLOYMENT_TARGET = 2.0;
639+
TVOS_DEPLOYMENT_TARGET = 11.0;
640+
WATCHOS_DEPLOYMENT_TARGET = 4.0;
641641
};
642642
name = Release;
643643
};
@@ -646,6 +646,7 @@
646646
buildSettings = {
647647
HEADER_SEARCH_PATHS = "$(SDKROOT)/usr/include/libxml2";
648648
LD = /usr/bin/true;
649+
MACOSX_DEPLOYMENT_TARGET = 10.13;
649650
OTHER_SWIFT_FLAGS = "-swift-version 5 -I $(TOOLCHAIN_DIR)/usr/lib/swift/pm/4_2 -target x86_64-apple-macosx10.10 -sdk /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.15.sdk -package-description-version 5.1";
650651
SWIFT_VERSION = 5.0;
651652
};
@@ -656,6 +657,7 @@
656657
buildSettings = {
657658
HEADER_SEARCH_PATHS = "$(SDKROOT)/usr/include/libxml2";
658659
LD = /usr/bin/true;
660+
MACOSX_DEPLOYMENT_TARGET = 10.13;
659661
OTHER_SWIFT_FLAGS = "-swift-version 5 -I $(TOOLCHAIN_DIR)/usr/lib/swift/pm/4_2 -target x86_64-apple-macosx10.10 -sdk /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.15.sdk -package-description-version 5.1";
660662
SWIFT_VERSION = 5.0;
661663
};

Package.swift

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -28,10 +28,10 @@ let provider: [SystemPackageProvider] = [
2828
#endif
2929
let package = Package(
3030
name: "ContentstackUtils",
31-
platforms: [.macOS(.v10_12),
32-
.iOS(.v10),
33-
.tvOS(.v10),
34-
.watchOS(.v3)],
31+
platforms: [.macOS(.v10_13),
32+
.iOS(.v11),
33+
.tvOS(.v11),
34+
.watchOS(.v4)],
3535

3636
products: [
3737
// Products define the executables and libraries a package produces, and make them visible to other packages.

Sources/ContentstackUtils/ContentstackUtils.swift

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,9 @@ public struct ContentstackUtils {
9494

9595
static private func textNodeToHtml(_ textNode: TextNode, _ option: Option) -> String {
9696
var text = textNode.text
97+
if (textNode.break) {
98+
text = option.renderMark(markType: .break, text: text)
99+
}
97100
if (textNode.superscript) {
98101
text = option.renderMark(markType: .superscript, text: text)
99102
}
@@ -131,6 +134,11 @@ public struct ContentstackUtils {
131134
return option.renderItem(embeddedObject: embedModel.first!, metadata: metadata) ?? ""
132135
}
133136
}
137+
if let attType = node.attrs["type"] as? String, attType == "asset" {
138+
return option.renderNode(nodeType: NodeType.image.rawValue, node: node) { children in
139+
return nodeChildrenToHtml(children: children, option)
140+
}
141+
}
134142
return ""
135143
}
136144

Sources/ContentstackUtils/MarkType.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,5 +6,5 @@
66
//
77

88
public enum MarkType: String {
9-
case bold, italic, underline, strikethrough, inlineCode, `subscript`, superscript
9+
case bold, italic, underline, strikethrough, inlineCode, `subscript`, superscript, `break`
1010
}

Sources/ContentstackUtils/Option.swift

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,8 @@ open class Option: Renderable {
5959
return "<sub>\(text)</sub>"
6060
case .superscript:
6161
return "<sup>\(text)</sup>"
62+
case .break:
63+
return "<br />\(text)"
6264
}
6365
}
6466

@@ -69,7 +71,7 @@ open class Option: Renderable {
6971
case NodeType.link.rawValue:
7072
return "<a href=\"\(node.attrs["href"] ?? "")\">\(next(node.children))</a>"
7173
case NodeType.image.rawValue:
72-
return "<img src=\"\(node.attrs["src"] ?? "")\" />\(next(node.children))"
74+
return "<img src=\"\(node.attrs["src"] ?? node.attrs["asset-link"] ?? "")\" />\(next(node.children))"
7375
case NodeType.embed.rawValue:
7476
return "<iframe src=\"\(node.attrs["src"] ?? "")\">\(next(node.children))</iframe>"
7577
case NodeType.heading_1.rawValue:

Sources/ContentstackUtils/TextNode.swift

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,10 +15,11 @@ class TextNode: Node {
1515
public var inlineCode: Bool = false
1616
public var `subscript`: Bool = false
1717
public var superscript: Bool = false
18+
public var `break`: Bool = false
1819
public var text: String
1920
public enum FieldKeys: String, CodingKey {
2021
case text
21-
case bold, italic, underline, strikethrough, inlineCode, `subscript`, superscript
22+
case bold, italic, underline, strikethrough, inlineCode, `subscript`, superscript, `break`
2223
}
2324

2425
public required init(from decoder: Decoder) throws {
@@ -32,6 +33,8 @@ class TextNode: Node {
3233
inlineCode = try container.decodeIfPresent(Bool.self, forKey: .inlineCode) ?? false
3334
`subscript` = try container.decodeIfPresent(Bool.self, forKey: .`subscript`) ?? false
3435
superscript = try container.decodeIfPresent(Bool.self, forKey: .superscript) ?? false
36+
`break` = try container.decodeIfPresent(Bool.self, forKey: .break) ?? false
37+
3538

3639
try super.init(from: decoder)
3740
type = NodeType.text.rawValue

Tests/ContentstackUtilsTests/ContentstackUtilsJsonToHtmlTest.swift

Lines changed: 27 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -42,12 +42,37 @@ class ContentstackUtilsJsonToHtmlTest: XCTestCase {
4242
XCTAssertEqual(result, [kPlainTextHtml])
4343
}
4444

45+
func testSpan() {
46+
let node = NodeParser.parse(from: kSpanJson)
47+
48+
var result = ContentstackUtils.jsonToHtml(node: node)
49+
50+
XCTAssertEqual(result, "<strong><em><u><sub>Lorem ipsum dolor sit amet.</sub></u></em></strong>")
51+
52+
result = ContentstackUtils.jsonToHtml(node: node, CustomRenderOption());
53+
54+
XCTAssertEqual(result, "<span class='class-id'><b><em><u><sub>Lorem ipsum dolor sit amet.</sub></u></em></b></span>")
55+
}
56+
57+
func testAsset_Reference_NonEmbed_Document() {
58+
let node = NodeParser.parse(from: kAssetReferenceJson)
59+
60+
var result = ContentstackUtils.jsonToHtml(node: node)
61+
62+
XCTAssertEqual(result, "<img src=\"https://images.contentstack.com/v3/assets/blt77263d3e6b/blt73403ee7281/51807f919e0e4/11.jpg\" />")
63+
64+
result = ContentstackUtils.jsonToHtml(node: node,
65+
Option())
66+
67+
XCTAssertEqual(result, "<img src=\"https://images.contentstack.com/v3/assets/blt77263d3e6b/blt73403ee7281/51807f919e0e4/11.jpg\" />")
68+
69+
}
4570
func testAsset_Reference_Document() {
4671
let node = NodeParser.parse(from: kAssetReferenceJson)
4772

4873
var result = ContentstackUtils.jsonToHtml(node: node)
4974

50-
XCTAssertEqual(result, "")
75+
XCTAssertEqual(result, "<img src=\"https://images.contentstack.com/v3/assets/blt77263d3e6b/blt73403ee7281/51807f919e0e4/11.jpg\" />")
5176

5277
result = ContentstackUtils.jsonToHtml(node: node,
5378
Option(entry:
@@ -63,7 +88,7 @@ class ContentstackUtilsJsonToHtmlTest: XCTestCase {
6388

6489
var result = ContentstackUtils.jsonToHtml(node: [node])
6590

66-
XCTAssertEqual(result, [""])
91+
XCTAssertEqual(result, ["<img src=\"https://images.contentstack.com/v3/assets/blt77263d3e6b/blt73403ee7281/51807f919e0e4/11.jpg\" />"])
6792

6893
result = ContentstackUtils.jsonToHtml(node: [node],
6994
Option(entry:

Tests/ContentstackUtilsTests/CustomRenderOptionMock.swift

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,8 @@ class CustomRenderOption: Option {
2424
return "<p class='class-id'>\(next(node.children))</p>"
2525
case NodeType.heading_1.rawValue:
2626
return "<h1 class='class-id'>\(next(node.children))</h1>"
27+
case "span":
28+
return "<span class='class-id'>\(next(node.children))</span>"
2729
default:
2830
return super.renderNode(nodeType: nodeType, node: node, next: next)
2931
}

0 commit comments

Comments
 (0)