2022-09-13 11:36:28 +12:00
|
|
|
defmodule AshHqWeb.Components.Docs.Functions do
|
2022-11-17 08:36:05 +13:00
|
|
|
@moduledoc "Lists all of the provided functions"
|
2022-09-13 11:36:28 +12:00
|
|
|
use Surface.Component
|
|
|
|
|
|
|
|
alias AshHqWeb.Components.Docs.SourceLink
|
|
|
|
|
2023-01-19 11:56:07 +13:00
|
|
|
prop(type, :atom, required: true)
|
|
|
|
prop(functions, :list, required: true)
|
|
|
|
prop(header, :string, required: true)
|
|
|
|
prop(library, :any, required: true)
|
|
|
|
prop(library_version, :any, required: true)
|
|
|
|
prop(libraries, :list, required: true)
|
|
|
|
prop(selected_versions, :map, required: true)
|
2022-09-13 11:36:28 +12:00
|
|
|
|
|
|
|
def render(assigns) do
|
|
|
|
~F"""
|
|
|
|
{#case Enum.filter(@functions, &(&1.type == @type))}
|
|
|
|
{#match []}
|
|
|
|
{#match functions}
|
2022-09-16 10:35:33 +12:00
|
|
|
<h3>{@header}</h3>
|
2022-09-13 11:36:28 +12:00
|
|
|
{#for function <- functions}
|
2022-09-16 10:35:33 +12:00
|
|
|
<div id={"#{@type}-#{function.sanitized_name}-#{function.arity}"} class="nav-anchor mb-8">
|
|
|
|
<div class="bg-base-light-200 dark:bg-base-dark-700 w-full rounded-lg">
|
2022-11-01 20:20:09 +13:00
|
|
|
<div class="flex flex-row items-center bg-opacity-50 py-1 rounded-t-lg bg-base-light-300 dark:bg-base-dark-850 w-full">
|
2022-09-16 10:35:33 +12:00
|
|
|
<a href={"##{@type}-#{function.sanitized_name}-#{function.arity}"}>
|
2023-01-25 03:02:46 +13:00
|
|
|
<Heroicons.Outline.LinkIcon class="h-3 w-3 mr-2" />
|
2022-09-16 10:35:33 +12:00
|
|
|
</a>
|
|
|
|
<div class="flex flex-row items-center justify-between w-full pr-2">
|
|
|
|
<div class="text-xl w-full font-semibold">{function.name}/{function.arity}</div>
|
|
|
|
<SourceLink module_or_function={function} library={@library} library_version={@library_version} />
|
2022-09-13 11:36:28 +12:00
|
|
|
</div>
|
|
|
|
</div>
|
2022-09-16 10:35:33 +12:00
|
|
|
<div class="p-4">
|
2023-01-19 14:28:05 +13:00
|
|
|
{raw(rendered(function.doc_html))}
|
2022-09-16 10:35:33 +12:00
|
|
|
</div>
|
|
|
|
</div>
|
2022-09-13 12:35:59 +12:00
|
|
|
</div>
|
|
|
|
{/for}
|
2022-09-13 11:36:28 +12:00
|
|
|
{/case}
|
|
|
|
"""
|
|
|
|
end
|
2022-09-16 10:35:33 +12:00
|
|
|
|
2023-01-19 11:56:07 +13:00
|
|
|
defp rendered(html) do
|
|
|
|
html
|
2022-09-16 10:35:33 +12:00
|
|
|
|> String.split("<!--- heads-end -->")
|
|
|
|
|> case do
|
|
|
|
[] ->
|
|
|
|
""
|
|
|
|
|
|
|
|
[string] ->
|
|
|
|
string
|
|
|
|
|
|
|
|
[heads, docs] ->
|
|
|
|
if String.trim(docs) == "" do
|
|
|
|
"""
|
|
|
|
<div class="not-prose">
|
|
|
|
#{heads}
|
|
|
|
</div>
|
|
|
|
|
|
|
|
#{docs}
|
|
|
|
"""
|
|
|
|
else
|
|
|
|
"""
|
|
|
|
<div class="not-prose border-b pb-2">
|
|
|
|
#{heads}
|
|
|
|
</div>
|
|
|
|
|
|
|
|
#{docs}
|
|
|
|
"""
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
2022-09-13 11:36:28 +12:00
|
|
|
end
|