First step rendering a page
The API responds with a bunch of paragraphs which the client converts
into Paragraph objects.
This turns the paragraphs in a PostResponse's Paragraph objects into the
form needed to render them on a page. This includes converting flat list
elements into list elements nested by a UL. And adding a limited markups
along the way.
The array of paragraphs is passed to a recursive function. The function
takes the first paragraph and either wraps the (marked up) contents in a
container tag (like Paragraph or Heading3), and then moves onto the next
tag. If it finds a list, it starts parsing the next paragraphs as a list
instead.
Originally, this was implemented like so:
```crystal
paragraph = paragraphs.shift
if list?
convert_list([paragraph] + paragraphs)
end
```
However, passing the `paragraphs` after adding it to the already shifted
`paragraph` creates a new object. This means `paragraphs` won't be
mutated and once the list is parsed, it starts with the next element of
the list. Instead, the element is `shift`ed inside each converter.
```crystal
if paragraphs.first == list?
convert_list(paragraphs)
end
def convert_list(paragraphs)
paragraph = paragraphs.shift
# ...
end
```
When rendering, there is an Empty and Container object. These represent
a kind of "null object" for both leafs and parent objects respectively.
They should never actually render. Emptys are filtered out, and
Containers are never created explicitly but this will make the types
pass.
IFrames are a bit of a special case. Each IFrame has custom data on it
that this system would need to be aware of. For now, instead of trying
to parse the seemingly large number of iframe variations and dealing
with embedded iframe problems, this will just keep track of the source
page URL and send the user there with a link.
2021-05-16 20:14:25 +02:00
|
|
|
class PageContent < BaseComponent
|
|
|
|
include Nodes
|
|
|
|
needs page : Page
|
|
|
|
|
|
|
|
def render
|
|
|
|
page.nodes.each do |node|
|
|
|
|
render_child(node)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
def render_children(children : Children)
|
|
|
|
children.each { |child| render_child(child) }
|
|
|
|
end
|
|
|
|
|
2021-07-04 23:06:17 +02:00
|
|
|
def render_child(node : Anchor)
|
2021-08-08 20:34:40 +02:00
|
|
|
a(href: node.href) { render_children(node.children) }
|
2021-07-04 23:06:17 +02:00
|
|
|
end
|
|
|
|
|
First step rendering a page
The API responds with a bunch of paragraphs which the client converts
into Paragraph objects.
This turns the paragraphs in a PostResponse's Paragraph objects into the
form needed to render them on a page. This includes converting flat list
elements into list elements nested by a UL. And adding a limited markups
along the way.
The array of paragraphs is passed to a recursive function. The function
takes the first paragraph and either wraps the (marked up) contents in a
container tag (like Paragraph or Heading3), and then moves onto the next
tag. If it finds a list, it starts parsing the next paragraphs as a list
instead.
Originally, this was implemented like so:
```crystal
paragraph = paragraphs.shift
if list?
convert_list([paragraph] + paragraphs)
end
```
However, passing the `paragraphs` after adding it to the already shifted
`paragraph` creates a new object. This means `paragraphs` won't be
mutated and once the list is parsed, it starts with the next element of
the list. Instead, the element is `shift`ed inside each converter.
```crystal
if paragraphs.first == list?
convert_list(paragraphs)
end
def convert_list(paragraphs)
paragraph = paragraphs.shift
# ...
end
```
When rendering, there is an Empty and Container object. These represent
a kind of "null object" for both leafs and parent objects respectively.
They should never actually render. Emptys are filtered out, and
Containers are never created explicitly but this will make the types
pass.
IFrames are a bit of a special case. Each IFrame has custom data on it
that this system would need to be aware of. For now, instead of trying
to parse the seemingly large number of iframe variations and dealing
with embedded iframe problems, this will just keep track of the source
page URL and send the user there with a link.
2021-05-16 20:14:25 +02:00
|
|
|
def render_child(node : BlockQuote)
|
2021-09-15 21:25:34 +02:00
|
|
|
blockquote do
|
|
|
|
para { render_children(node.children) }
|
|
|
|
end
|
First step rendering a page
The API responds with a bunch of paragraphs which the client converts
into Paragraph objects.
This turns the paragraphs in a PostResponse's Paragraph objects into the
form needed to render them on a page. This includes converting flat list
elements into list elements nested by a UL. And adding a limited markups
along the way.
The array of paragraphs is passed to a recursive function. The function
takes the first paragraph and either wraps the (marked up) contents in a
container tag (like Paragraph or Heading3), and then moves onto the next
tag. If it finds a list, it starts parsing the next paragraphs as a list
instead.
Originally, this was implemented like so:
```crystal
paragraph = paragraphs.shift
if list?
convert_list([paragraph] + paragraphs)
end
```
However, passing the `paragraphs` after adding it to the already shifted
`paragraph` creates a new object. This means `paragraphs` won't be
mutated and once the list is parsed, it starts with the next element of
the list. Instead, the element is `shift`ed inside each converter.
```crystal
if paragraphs.first == list?
convert_list(paragraphs)
end
def convert_list(paragraphs)
paragraph = paragraphs.shift
# ...
end
```
When rendering, there is an Empty and Container object. These represent
a kind of "null object" for both leafs and parent objects respectively.
They should never actually render. Emptys are filtered out, and
Containers are never created explicitly but this will make the types
pass.
IFrames are a bit of a special case. Each IFrame has custom data on it
that this system would need to be aware of. For now, instead of trying
to parse the seemingly large number of iframe variations and dealing
with embedded iframe problems, this will just keep track of the source
page URL and send the user there with a link.
2021-05-16 20:14:25 +02:00
|
|
|
end
|
|
|
|
|
|
|
|
def render_child(node : Code)
|
|
|
|
code { render_children(node.children) }
|
|
|
|
end
|
|
|
|
|
|
|
|
def render_child(container : Container)
|
|
|
|
# Should never get called
|
|
|
|
raw "<!-- a Container was rendered -->"
|
|
|
|
end
|
|
|
|
|
2021-09-13 19:27:52 +02:00
|
|
|
def render_child(child : EmbeddedContent)
|
2021-09-25 19:26:10 +02:00
|
|
|
figure do
|
2021-09-13 19:27:52 +02:00
|
|
|
iframe(
|
|
|
|
src: child.src,
|
|
|
|
width: child.width,
|
|
|
|
height: child.height,
|
|
|
|
frameborder: "0",
|
|
|
|
allowfullscreen: true,
|
|
|
|
)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
def render_child(child : EmbeddedLink)
|
2021-09-25 19:26:10 +02:00
|
|
|
figure do
|
2021-09-13 19:27:52 +02:00
|
|
|
a href: child.href do
|
|
|
|
text "Embedded content at #{child.domain}"
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
First step rendering a page
The API responds with a bunch of paragraphs which the client converts
into Paragraph objects.
This turns the paragraphs in a PostResponse's Paragraph objects into the
form needed to render them on a page. This includes converting flat list
elements into list elements nested by a UL. And adding a limited markups
along the way.
The array of paragraphs is passed to a recursive function. The function
takes the first paragraph and either wraps the (marked up) contents in a
container tag (like Paragraph or Heading3), and then moves onto the next
tag. If it finds a list, it starts parsing the next paragraphs as a list
instead.
Originally, this was implemented like so:
```crystal
paragraph = paragraphs.shift
if list?
convert_list([paragraph] + paragraphs)
end
```
However, passing the `paragraphs` after adding it to the already shifted
`paragraph` creates a new object. This means `paragraphs` won't be
mutated and once the list is parsed, it starts with the next element of
the list. Instead, the element is `shift`ed inside each converter.
```crystal
if paragraphs.first == list?
convert_list(paragraphs)
end
def convert_list(paragraphs)
paragraph = paragraphs.shift
# ...
end
```
When rendering, there is an Empty and Container object. These represent
a kind of "null object" for both leafs and parent objects respectively.
They should never actually render. Emptys are filtered out, and
Containers are never created explicitly but this will make the types
pass.
IFrames are a bit of a special case. Each IFrame has custom data on it
that this system would need to be aware of. For now, instead of trying
to parse the seemingly large number of iframe variations and dealing
with embedded iframe problems, this will just keep track of the source
page URL and send the user there with a link.
2021-05-16 20:14:25 +02:00
|
|
|
def render_child(node : Emphasis)
|
|
|
|
em { render_children(node.children) }
|
|
|
|
end
|
|
|
|
|
|
|
|
def render_child(container : Empty)
|
|
|
|
# Should never get called
|
|
|
|
raw "<!-- an Empty was rendered -->"
|
|
|
|
end
|
|
|
|
|
2021-07-05 20:10:40 +02:00
|
|
|
def render_child(node : Figure)
|
|
|
|
figure { render_children(node.children) }
|
|
|
|
end
|
|
|
|
|
|
|
|
def render_child(node : FigureCaption)
|
2021-08-15 21:08:03 +02:00
|
|
|
writing_hand = "✍"
|
|
|
|
text_variant = "︎"
|
|
|
|
footnote_id = node.children.hash.to_s
|
|
|
|
label class: "margin-toggle", for: footnote_id do
|
|
|
|
raw writing_hand + text_variant
|
|
|
|
end
|
|
|
|
input class: "margin-toggle", type: "checkbox", id: footnote_id
|
|
|
|
span class: "marginnote" do
|
|
|
|
render_children(node.children)
|
|
|
|
end
|
2021-07-05 20:10:40 +02:00
|
|
|
end
|
|
|
|
|
2021-09-13 19:27:52 +02:00
|
|
|
def render_child(child : GithubGist)
|
|
|
|
script src: child.src
|
|
|
|
end
|
|
|
|
|
2021-08-14 22:12:01 +02:00
|
|
|
def render_child(node : Heading2)
|
|
|
|
h2 { render_children(node.children) }
|
First step rendering a page
The API responds with a bunch of paragraphs which the client converts
into Paragraph objects.
This turns the paragraphs in a PostResponse's Paragraph objects into the
form needed to render them on a page. This includes converting flat list
elements into list elements nested by a UL. And adding a limited markups
along the way.
The array of paragraphs is passed to a recursive function. The function
takes the first paragraph and either wraps the (marked up) contents in a
container tag (like Paragraph or Heading3), and then moves onto the next
tag. If it finds a list, it starts parsing the next paragraphs as a list
instead.
Originally, this was implemented like so:
```crystal
paragraph = paragraphs.shift
if list?
convert_list([paragraph] + paragraphs)
end
```
However, passing the `paragraphs` after adding it to the already shifted
`paragraph` creates a new object. This means `paragraphs` won't be
mutated and once the list is parsed, it starts with the next element of
the list. Instead, the element is `shift`ed inside each converter.
```crystal
if paragraphs.first == list?
convert_list(paragraphs)
end
def convert_list(paragraphs)
paragraph = paragraphs.shift
# ...
end
```
When rendering, there is an Empty and Container object. These represent
a kind of "null object" for both leafs and parent objects respectively.
They should never actually render. Emptys are filtered out, and
Containers are never created explicitly but this will make the types
pass.
IFrames are a bit of a special case. Each IFrame has custom data on it
that this system would need to be aware of. For now, instead of trying
to parse the seemingly large number of iframe variations and dealing
with embedded iframe problems, this will just keep track of the source
page URL and send the user there with a link.
2021-05-16 20:14:25 +02:00
|
|
|
end
|
|
|
|
|
2021-08-14 22:12:01 +02:00
|
|
|
def render_child(node : Heading3)
|
|
|
|
h3 { render_children(node.children) }
|
First step rendering a page
The API responds with a bunch of paragraphs which the client converts
into Paragraph objects.
This turns the paragraphs in a PostResponse's Paragraph objects into the
form needed to render them on a page. This includes converting flat list
elements into list elements nested by a UL. And adding a limited markups
along the way.
The array of paragraphs is passed to a recursive function. The function
takes the first paragraph and either wraps the (marked up) contents in a
container tag (like Paragraph or Heading3), and then moves onto the next
tag. If it finds a list, it starts parsing the next paragraphs as a list
instead.
Originally, this was implemented like so:
```crystal
paragraph = paragraphs.shift
if list?
convert_list([paragraph] + paragraphs)
end
```
However, passing the `paragraphs` after adding it to the already shifted
`paragraph` creates a new object. This means `paragraphs` won't be
mutated and once the list is parsed, it starts with the next element of
the list. Instead, the element is `shift`ed inside each converter.
```crystal
if paragraphs.first == list?
convert_list(paragraphs)
end
def convert_list(paragraphs)
paragraph = paragraphs.shift
# ...
end
```
When rendering, there is an Empty and Container object. These represent
a kind of "null object" for both leafs and parent objects respectively.
They should never actually render. Emptys are filtered out, and
Containers are never created explicitly but this will make the types
pass.
IFrames are a bit of a special case. Each IFrame has custom data on it
that this system would need to be aware of. For now, instead of trying
to parse the seemingly large number of iframe variations and dealing
with embedded iframe problems, this will just keep track of the source
page URL and send the user there with a link.
2021-05-16 20:14:25 +02:00
|
|
|
end
|
|
|
|
|
|
|
|
def render_child(child : Image)
|
2021-08-14 22:07:31 +02:00
|
|
|
img src: child.src, width: child.width
|
First step rendering a page
The API responds with a bunch of paragraphs which the client converts
into Paragraph objects.
This turns the paragraphs in a PostResponse's Paragraph objects into the
form needed to render them on a page. This includes converting flat list
elements into list elements nested by a UL. And adding a limited markups
along the way.
The array of paragraphs is passed to a recursive function. The function
takes the first paragraph and either wraps the (marked up) contents in a
container tag (like Paragraph or Heading3), and then moves onto the next
tag. If it finds a list, it starts parsing the next paragraphs as a list
instead.
Originally, this was implemented like so:
```crystal
paragraph = paragraphs.shift
if list?
convert_list([paragraph] + paragraphs)
end
```
However, passing the `paragraphs` after adding it to the already shifted
`paragraph` creates a new object. This means `paragraphs` won't be
mutated and once the list is parsed, it starts with the next element of
the list. Instead, the element is `shift`ed inside each converter.
```crystal
if paragraphs.first == list?
convert_list(paragraphs)
end
def convert_list(paragraphs)
paragraph = paragraphs.shift
# ...
end
```
When rendering, there is an Empty and Container object. These represent
a kind of "null object" for both leafs and parent objects respectively.
They should never actually render. Emptys are filtered out, and
Containers are never created explicitly but this will make the types
pass.
IFrames are a bit of a special case. Each IFrame has custom data on it
that this system would need to be aware of. For now, instead of trying
to parse the seemingly large number of iframe variations and dealing
with embedded iframe problems, this will just keep track of the source
page URL and send the user there with a link.
2021-05-16 20:14:25 +02:00
|
|
|
end
|
|
|
|
|
|
|
|
def render_child(node : ListItem)
|
|
|
|
li { render_children(node.children) }
|
|
|
|
end
|
|
|
|
|
2021-09-08 03:13:28 +02:00
|
|
|
def render_child(node : MixtapeEmbed)
|
2021-09-25 19:26:10 +02:00
|
|
|
blockquote do
|
|
|
|
para { render_children(node.children) }
|
2021-09-08 03:13:28 +02:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
First step rendering a page
The API responds with a bunch of paragraphs which the client converts
into Paragraph objects.
This turns the paragraphs in a PostResponse's Paragraph objects into the
form needed to render them on a page. This includes converting flat list
elements into list elements nested by a UL. And adding a limited markups
along the way.
The array of paragraphs is passed to a recursive function. The function
takes the first paragraph and either wraps the (marked up) contents in a
container tag (like Paragraph or Heading3), and then moves onto the next
tag. If it finds a list, it starts parsing the next paragraphs as a list
instead.
Originally, this was implemented like so:
```crystal
paragraph = paragraphs.shift
if list?
convert_list([paragraph] + paragraphs)
end
```
However, passing the `paragraphs` after adding it to the already shifted
`paragraph` creates a new object. This means `paragraphs` won't be
mutated and once the list is parsed, it starts with the next element of
the list. Instead, the element is `shift`ed inside each converter.
```crystal
if paragraphs.first == list?
convert_list(paragraphs)
end
def convert_list(paragraphs)
paragraph = paragraphs.shift
# ...
end
```
When rendering, there is an Empty and Container object. These represent
a kind of "null object" for both leafs and parent objects respectively.
They should never actually render. Emptys are filtered out, and
Containers are never created explicitly but this will make the types
pass.
IFrames are a bit of a special case. Each IFrame has custom data on it
that this system would need to be aware of. For now, instead of trying
to parse the seemingly large number of iframe variations and dealing
with embedded iframe problems, this will just keep track of the source
page URL and send the user there with a link.
2021-05-16 20:14:25 +02:00
|
|
|
def render_child(node : OrderedList)
|
|
|
|
ol { render_children(node.children) }
|
|
|
|
end
|
|
|
|
|
|
|
|
def render_child(node : Paragraph)
|
|
|
|
para { render_children(node.children) }
|
|
|
|
end
|
|
|
|
|
|
|
|
def render_child(node : Preformatted)
|
|
|
|
pre { render_children(node.children) }
|
|
|
|
end
|
|
|
|
|
|
|
|
def render_child(node : Strong)
|
|
|
|
strong { render_children(node.children) }
|
|
|
|
end
|
|
|
|
|
|
|
|
def render_child(child : Text)
|
|
|
|
text child.content
|
|
|
|
end
|
|
|
|
|
|
|
|
def render_child(node : UnorderedList)
|
|
|
|
ul { render_children(node.children) }
|
|
|
|
end
|
2021-07-04 23:37:45 +02:00
|
|
|
|
|
|
|
def render_child(node : UserAnchor)
|
2021-08-08 20:34:40 +02:00
|
|
|
a(href: node.href) { render_children(node.children) }
|
2021-07-04 23:37:45 +02:00
|
|
|
end
|
First step rendering a page
The API responds with a bunch of paragraphs which the client converts
into Paragraph objects.
This turns the paragraphs in a PostResponse's Paragraph objects into the
form needed to render them on a page. This includes converting flat list
elements into list elements nested by a UL. And adding a limited markups
along the way.
The array of paragraphs is passed to a recursive function. The function
takes the first paragraph and either wraps the (marked up) contents in a
container tag (like Paragraph or Heading3), and then moves onto the next
tag. If it finds a list, it starts parsing the next paragraphs as a list
instead.
Originally, this was implemented like so:
```crystal
paragraph = paragraphs.shift
if list?
convert_list([paragraph] + paragraphs)
end
```
However, passing the `paragraphs` after adding it to the already shifted
`paragraph` creates a new object. This means `paragraphs` won't be
mutated and once the list is parsed, it starts with the next element of
the list. Instead, the element is `shift`ed inside each converter.
```crystal
if paragraphs.first == list?
convert_list(paragraphs)
end
def convert_list(paragraphs)
paragraph = paragraphs.shift
# ...
end
```
When rendering, there is an Empty and Container object. These represent
a kind of "null object" for both leafs and parent objects respectively.
They should never actually render. Emptys are filtered out, and
Containers are never created explicitly but this will make the types
pass.
IFrames are a bit of a special case. Each IFrame has custom data on it
that this system would need to be aware of. For now, instead of trying
to parse the seemingly large number of iframe variations and dealing
with embedded iframe problems, this will just keep track of the source
page URL and send the user there with a link.
2021-05-16 20:14:25 +02:00
|
|
|
end
|