|
1 |
| - |
2 | 1 | extension Post {
|
3 | 2 |
|
4 |
| - func prepareForPrompt(_ prompt: Prompt?) { |
| 3 | + func prepareForPrompt(_ prompt: BloggingPrompt?) { |
5 | 4 | guard let prompt = prompt else {
|
6 | 5 | return
|
7 | 6 | }
|
8 |
| - postTitle = prompt.postTitle |
9 |
| - let pullquoteBlock = getPullquoteBlock(title: prompt.promptText, |
10 |
| - promptUrl: prompt.promptUrl?.absoluteString, |
11 |
| - answerUrl: prompt.answerUrl?.absoluteString, |
12 |
| - answerCount: prompt.answerCount) |
13 |
| - content = pullquoteBlock + Strings.emptyParagraph |
| 7 | + postTitle = prompt.title |
| 8 | + content = prompt.content |
14 | 9 | }
|
15 | 10 |
|
16 | 11 | }
|
17 |
| - |
18 |
| -// MARK: - Private methods |
19 |
| - |
20 |
| -private extension Post { |
21 |
| - |
22 |
| - func getPullquoteBlock(title: String, |
23 |
| - promptUrl: String?, |
24 |
| - answerUrl: String?, |
25 |
| - answerCount: Int) -> String { |
26 |
| - let answerFormat = answerCount == 1 ? Strings.answerInfoSingularFormat : Strings.answerInfoPluralFormat |
27 |
| - let answerText = String(format: answerFormat, answerCount) |
28 |
| - let promptUrlHtml = getUrlHtml(url: promptUrl, urlText: Strings.prompt) |
29 |
| - let answerUrlHtml = getUrlHtml(url: answerUrl, urlText: answerText) |
30 |
| - let separatorText = promptUrlHtml.isEmpty || answerUrlHtml.isEmpty ? "" : " — " |
31 |
| - let subtitleHtml = promptUrlHtml.isEmpty && answerUrlHtml.isEmpty ? "" : "<cite>\(promptUrlHtml)\(separatorText)\(answerUrlHtml)</cite>" |
32 |
| - return """ |
33 |
| - <!-- wp:pullquote --> |
34 |
| - <figure class="wp-block-pullquote"><blockquote><p>\(title)</p>\(subtitleHtml)</blockquote></figure> |
35 |
| - <!-- /wp:pullquote --> |
36 |
| - """ |
37 |
| - } |
38 |
| - |
39 |
| - func getUrlHtml(url: String?, urlText: String) -> String { |
40 |
| - guard let url = url else { |
41 |
| - return "" |
42 |
| - } |
43 |
| - return "<a href=\"\(url)\">\(urlText)</a>" |
44 |
| - } |
45 |
| - |
46 |
| - // MARK: - Strings |
47 |
| - |
48 |
| - struct Strings { |
49 |
| - static let prompt = NSLocalizedString("Prompt", comment: "Prompt link text in a new blogging prompts post") |
50 |
| - static let answerInfoSingularFormat = NSLocalizedString("%1$d answer", comment: "Singular format string for displaying the number of users that answered the blogging prompt.") |
51 |
| - static let answerInfoPluralFormat = NSLocalizedString("%1$d answers", comment: "Plural format string for displaying the number of users that answered the blogging prompt.") |
52 |
| - static let emptyParagraph = """ |
53 |
| - <!-- wp:paragraph --> |
54 |
| - <p></p> |
55 |
| - <!-- /wp:paragraph --> |
56 |
| - """ |
57 |
| - } |
58 |
| - |
59 |
| -} |
60 |
| - |
61 |
| -// MARK: - Temporary prompt object |
62 |
| - |
63 |
| -// TODO: Remove after prompt object is created and use that |
64 |
| -struct Prompt { |
65 |
| - let postTitle: String |
66 |
| - let promptText: String |
67 |
| - let promptUrl: URL? |
68 |
| - let answerUrl: URL? |
69 |
| - let answerCount: Int |
70 |
| - |
71 |
| - static let examplePrompt = Prompt(postTitle: "Cast the movie of my life", |
72 |
| - promptText: "Cast the movie of your life.", |
73 |
| - promptUrl: URL(string: "https://wordpress.com"), |
74 |
| - answerUrl: URL(string: "https://wordpress.com"), |
75 |
| - answerCount: 19) |
76 |
| -} |
0 commit comments