devel #307
2 changed files with 40 additions and 22 deletions
|
@ -1,6 +1,5 @@
|
||||||
defmodule ChiyaWeb.PageHTML do
|
defmodule ChiyaWeb.PageHTML do
|
||||||
use ChiyaWeb, :html_public
|
use ChiyaWeb, :html_public
|
||||||
import Phoenix.HTML.Tag, only: [content_tag: 3, content_tag: 2]
|
|
||||||
import ChiyaWeb.Format, only: [pretty_datetime: 1, pretty_date: 1, datetime: 1]
|
import ChiyaWeb.Format, only: [pretty_datetime: 1, pretty_date: 1, datetime: 1]
|
||||||
|
|
||||||
embed_templates "page_html/*"
|
embed_templates "page_html/*"
|
||||||
|
@ -27,30 +26,11 @@ defmodule ChiyaWeb.PageHTML do
|
||||||
def tag_list(assigns)
|
def tag_list(assigns)
|
||||||
|
|
||||||
def render_outline(note) do
|
def render_outline(note) do
|
||||||
note.content
|
ChiyaWeb.OutlineRenderer.render_outline(note.content)
|
||||||
|> ChiyaWeb.Outline.get()
|
|
||||||
|> Enum.map(&do_render_outline/1)
|
|
||||||
|> Enum.map(&safe_to_string/1)
|
|
||||||
end
|
end
|
||||||
|
|
||||||
def has_outline?(note) do
|
def has_outline?(note) do
|
||||||
outline_empty =
|
ChiyaWeb.OutlineRenderer.has_outline?(note.content)
|
||||||
note.content
|
|
||||||
|> ChiyaWeb.Outline.get()
|
|
||||||
|> Enum.empty?()
|
|
||||||
|
|
||||||
!outline_empty
|
|
||||||
end
|
|
||||||
|
|
||||||
def do_render_outline(%{text: text, children: children, level: _level}) do
|
|
||||||
slug = Slugger.slugify_downcase(text)
|
|
||||||
|
|
||||||
content_tag(:ul, [class: "m-0"],
|
|
||||||
do: [
|
|
||||||
content_tag(:li, do: content_tag(:a, text, href: "##{slug}")),
|
|
||||||
Enum.map(children, &do_render_outline/1)
|
|
||||||
]
|
|
||||||
)
|
|
||||||
end
|
end
|
||||||
|
|
||||||
def group_tags(notes) do
|
def group_tags(notes) do
|
||||||
|
|
38
lib/chiya_web/outline_renderer.ex
Normal file
38
lib/chiya_web/outline_renderer.ex
Normal file
|
@ -0,0 +1,38 @@
|
||||||
|
defmodule ChiyaWeb.OutlineRenderer do
|
||||||
|
import Phoenix.HTML, only: [safe_to_string: 1]
|
||||||
|
import Phoenix.HTML.Tag, only: [content_tag: 3, content_tag: 2]
|
||||||
|
|
||||||
|
def render_outline(content) do
|
||||||
|
children =
|
||||||
|
content
|
||||||
|
|> ChiyaWeb.Outline.get()
|
||||||
|
|> Enum.map(&do_render_outline/1)
|
||||||
|
|
||||||
|
root = content_tag(:ul, do: children)
|
||||||
|
|
||||||
|
safe_to_string(root)
|
||||||
|
end
|
||||||
|
|
||||||
|
def has_outline?(content) do
|
||||||
|
outline_empty =
|
||||||
|
content
|
||||||
|
|> ChiyaWeb.Outline.get()
|
||||||
|
|> Enum.empty?()
|
||||||
|
|
||||||
|
!outline_empty
|
||||||
|
end
|
||||||
|
|
||||||
|
def do_render_outline(%{text: text, children: children, level: _level}) do
|
||||||
|
slug = Slugger.slugify_downcase(text)
|
||||||
|
list_item = content_tag(:li, do: content_tag(:a, text, href: "##{slug}"))
|
||||||
|
|
||||||
|
if Enum.empty?(children) do
|
||||||
|
[list_item]
|
||||||
|
else
|
||||||
|
[
|
||||||
|
list_item,
|
||||||
|
content_tag(:ul, do: Enum.map(children, &do_render_outline/1))
|
||||||
|
]
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
Loading…
Reference in a new issue