Add MIXTAPE_EMBED paragraph type

This commit is contained in:
Edward Loveall 2021-09-07 21:13:28 -04:00
parent 0cab1a11ed
commit 9770ff5c7a
No known key found for this signature in database
GPG Key ID: 789A4AE983AC8901
6 changed files with 68 additions and 0 deletions

View File

@ -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)

View File

@ -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
<p>
<div class="embedded">
<a href="https://example.com">Mixtape</a>
</div>
</p>
HTML
end
it "renders an ordered list" do
page = Page.new(
title: "Title",

View File

@ -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)

View File

@ -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

View File

@ -48,6 +48,9 @@ module Nodes
class ListItem < Container
end
class MixtapeEmbed < Container
end
class OrderedList < Container
end

View File

@ -46,6 +46,7 @@ class PostResponse
H4
IFRAME
IMG
MIXTAPE_EMBED
OLI
P
PQ