Break up views into components
This commit is contained in:
parent
c954fc1006
commit
57f26996b2
3 changed files with 47 additions and 33 deletions
16
src/components/iframe.cr
Normal file
16
src/components/iframe.cr
Normal file
|
@ -0,0 +1,16 @@
|
||||||
|
class Post::IFrame < BaseComponent
|
||||||
|
needs paragraph : PostResponse::Paragraph
|
||||||
|
|
||||||
|
def render
|
||||||
|
embed = paragraph.iframe
|
||||||
|
if embed
|
||||||
|
embed_data = MediumClient.media_data(embed.mediaResource.id)
|
||||||
|
embed_value = embed_data.payload.value
|
||||||
|
if embed_value.iframeSrc.blank?
|
||||||
|
iframe src: embed_data.payload.value.href
|
||||||
|
else
|
||||||
|
iframe src: embed_data.payload.value.iframeSrc
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
29
src/components/post.cr
Normal file
29
src/components/post.cr
Normal file
|
@ -0,0 +1,29 @@
|
||||||
|
class Post::Post < BaseComponent
|
||||||
|
needs response : PostResponse::Root
|
||||||
|
|
||||||
|
def render
|
||||||
|
data = response.data.post.content.bodyModel.paragraphs
|
||||||
|
data.each do |paragraph|
|
||||||
|
case paragraph.type
|
||||||
|
when PostResponse::ParagraphType::H3
|
||||||
|
h3 paragraph.text
|
||||||
|
when PostResponse::ParagraphType::H4
|
||||||
|
h4 paragraph.text
|
||||||
|
when PostResponse::ParagraphType::P
|
||||||
|
para paragraph.text
|
||||||
|
when PostResponse::ParagraphType::PRE
|
||||||
|
pre paragraph.text
|
||||||
|
when PostResponse::ParagraphType::BQ
|
||||||
|
blockquote paragraph.text
|
||||||
|
when PostResponse::ParagraphType::OLI
|
||||||
|
li paragraph.text
|
||||||
|
when PostResponse::ParagraphType::ULI
|
||||||
|
li paragraph.text
|
||||||
|
when PostResponse::ParagraphType::IFRAME
|
||||||
|
mount IFrame, paragraph: paragraph
|
||||||
|
else
|
||||||
|
para "#{paragraph.type} not yet implimented"
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
|
@ -1,38 +1,7 @@
|
||||||
class Articles::ShowPage < MainLayout
|
class Articles::ShowPage < MainLayout
|
||||||
needs medium_response_body : PostResponse::Root
|
needs post_response : PostResponse::Root
|
||||||
|
|
||||||
def content
|
def content
|
||||||
paragraphs = medium_response_body.data.post.content.bodyModel.paragraphs
|
mount Post::Post, response: post_response
|
||||||
paragraphs.each do |paragraph|
|
|
||||||
case paragraph.type
|
|
||||||
when PostResponse::ParagraphType::H3
|
|
||||||
h3 paragraph.text
|
|
||||||
when PostResponse::ParagraphType::H4
|
|
||||||
h4 paragraph.text
|
|
||||||
when PostResponse::ParagraphType::P
|
|
||||||
para paragraph.text
|
|
||||||
when PostResponse::ParagraphType::PRE
|
|
||||||
pre paragraph.text
|
|
||||||
when PostResponse::ParagraphType::BQ
|
|
||||||
blockquote paragraph.text
|
|
||||||
when PostResponse::ParagraphType::OLI
|
|
||||||
li paragraph.text
|
|
||||||
when PostResponse::ParagraphType::ULI
|
|
||||||
li paragraph.text
|
|
||||||
when PostResponse::ParagraphType::IFRAME
|
|
||||||
embed = paragraph.iframe
|
|
||||||
if embed
|
|
||||||
embed_data = LocalClient.embed_data(embed.mediaResource.id)
|
|
||||||
embed_value = embed_data.payload.value
|
|
||||||
if embed_value.iframeSrc.blank?
|
|
||||||
iframe src: embed_data.payload.value.href
|
|
||||||
else
|
|
||||||
iframe src: embed_data.payload.value.iframeSrc
|
|
||||||
end
|
|
||||||
end
|
|
||||||
else
|
|
||||||
para "#{paragraph.type} not yet implimented"
|
|
||||||
end
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
Loading…
Reference in a new issue