diff --git a/spec/classes/paragraph_converter_spec.cr b/spec/classes/paragraph_converter_spec.cr index 37e5816..1d31bbb 100644 --- a/spec/classes/paragraph_converter_spec.cr +++ b/spec/classes/paragraph_converter_spec.cr @@ -277,6 +277,25 @@ describe ParagraphConverter do }, "layout": null, "metadata": null + }, + { + "text": "Mixtape", + "type": "MIXTAPE_EMBED", + "href": null, + "layout": null, + "markups": [ + { + "title": "https://example.com", + "type": "A", + "href": "https://example.com", + "userId": null, + "start": 0, + "end": 7, + "anchorType": "LINK" + } + ], + "iframe": null, + "metadata": null } ] JSON @@ -294,6 +313,12 @@ describe ParagraphConverter do FigureCaption.new(children: [Text.new("text")] of Child), ] of Child), IFrame.new(href: "https://example.com"), + MixtapeEmbed.new(children: [ + Anchor.new( + children: [Text.new("Mixtape")] of Child, + href: "https://example.com" + ), + ] of Child), ] result = ParagraphConverter.new.convert(paragraphs) diff --git a/spec/components/page_content_spec.cr b/spec/components/page_content_spec.cr index e5673aa..bbb5877 100644 --- a/spec/components/page_content_spec.cr +++ b/spec/components/page_content_spec.cr @@ -234,6 +234,35 @@ describe PageContent do HTML end + it "renders an mixtape embed container" do + page = Page.new( + title: "Title", + subtitle: nil, + author: "Author", + created_at: Time.local, + nodes: [ + Paragraph.new(children: [ + MixtapeEmbed.new(children: [ + Anchor.new( + children: [Text.new("Mixtape")] of Child, + href: "https://example.com" + ), + ] of Child), + ] of Child), + ] of Child + ) + + html = PageContent.new(page: page).render_to_string + + html.should eq stripped_html <<-HTML +

+

+ Mixtape +
+

+ HTML + end + it "renders an ordered list" do page = Page.new( title: "Title", diff --git a/src/classes/paragraph_converter.cr b/src/classes/paragraph_converter.cr index 1c6b062..0596aff 100644 --- a/src/classes/paragraph_converter.cr +++ b/src/classes/paragraph_converter.cr @@ -28,6 +28,10 @@ class ParagraphConverter when PostResponse::ParagraphType::IMG paragraph = paragraphs.shift node = convert_img(paragraph) + when PostResponse::ParagraphType::MIXTAPE_EMBED + paragraph = paragraphs.shift + children = MarkupConverter.convert(paragraph.text, paragraph.markups) + node = MixtapeEmbed.new(children: children) when PostResponse::ParagraphType::OLI list_items = convert_oli(paragraphs) node = OrderedList.new(children: list_items) diff --git a/src/components/page_content.cr b/src/components/page_content.cr index 0c58244..248e544 100644 --- a/src/components/page_content.cr +++ b/src/components/page_content.cr @@ -79,6 +79,12 @@ class PageContent < BaseComponent li { render_children(node.children) } end + def render_child(node : MixtapeEmbed) + div class: "embedded" do + render_children(node.children) + end + end + def render_child(node : OrderedList) ol { render_children(node.children) } end diff --git a/src/models/nodes.cr b/src/models/nodes.cr index a47a081..3c141d8 100644 --- a/src/models/nodes.cr +++ b/src/models/nodes.cr @@ -48,6 +48,9 @@ module Nodes class ListItem < Container end + class MixtapeEmbed < Container + end + class OrderedList < Container end diff --git a/src/models/post_response.cr b/src/models/post_response.cr index f1882a9..d1411de 100644 --- a/src/models/post_response.cr +++ b/src/models/post_response.cr @@ -46,6 +46,7 @@ class PostResponse H4 IFRAME IMG + MIXTAPE_EMBED OLI P PQ