Add MIXTAPE_EMBED paragraph type
This commit is contained in:
parent
0cab1a11ed
commit
9770ff5c7a
6 changed files with 68 additions and 0 deletions
|
@ -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)
|
||||
|
|
|
@ -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",
|
||||
|
|
|
@ -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)
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -48,6 +48,9 @@ module Nodes
|
|||
class ListItem < Container
|
||||
end
|
||||
|
||||
class MixtapeEmbed < Container
|
||||
end
|
||||
|
||||
class OrderedList < Container
|
||||
end
|
||||
|
||||
|
|
|
@ -46,6 +46,7 @@ class PostResponse
|
|||
H4
|
||||
IFRAME
|
||||
IMG
|
||||
MIXTAPE_EMBED
|
||||
OLI
|
||||
P
|
||||
PQ
|
||||
|
|
Loading…
Reference in a new issue