2021-07-23 07:18:40 +08:00
|
|
|
defmodule LivebookWeb.SessionLive.ExportComponent do
|
|
|
|
use LivebookWeb, :live_component
|
|
|
|
|
|
|
|
alias Livebook.Session
|
|
|
|
|
|
|
|
@impl true
|
|
|
|
def update(assigns, socket) do
|
|
|
|
socket = assign(socket, assigns)
|
|
|
|
|
|
|
|
socket =
|
2021-07-28 19:40:36 +08:00
|
|
|
if socket.assigns[:notebook] do
|
2021-07-23 07:18:40 +08:00
|
|
|
socket
|
|
|
|
else
|
|
|
|
# Note: we need to load the notebook, because the local data
|
|
|
|
# has cell contents stripped out
|
2021-09-05 01:16:01 +08:00
|
|
|
notebook = Session.get_notebook(socket.assigns.session.pid)
|
2021-07-28 19:40:36 +08:00
|
|
|
assign(socket, :notebook, notebook)
|
2021-07-23 07:18:40 +08:00
|
|
|
end
|
|
|
|
|
|
|
|
{:ok, socket}
|
|
|
|
end
|
|
|
|
|
|
|
|
@impl true
|
|
|
|
def render(assigns) do
|
|
|
|
~H"""
|
|
|
|
<div class="p-6 max-w-4xl flex flex-col space-y-3">
|
|
|
|
<h3 class="text-2xl font-semibold text-gray-800">
|
|
|
|
Export
|
|
|
|
</h3>
|
|
|
|
<div class="w-full flex-col space-y-5">
|
|
|
|
<p class="text-gray-700">
|
|
|
|
Here you can preview and directly export the notebook source.
|
|
|
|
</p>
|
2021-07-28 19:40:36 +08:00
|
|
|
<div class="tabs">
|
2021-09-05 01:16:01 +08:00
|
|
|
<%= live_patch to: Routes.session_path(@socket, :export, @session.id, "livemd"),
|
2021-07-28 19:40:36 +08:00
|
|
|
class: "tab #{if(@tab == "livemd", do: "active")}" do %>
|
|
|
|
<span class="font-medium">
|
|
|
|
Live Markdown
|
2021-07-23 07:18:40 +08:00
|
|
|
</span>
|
2021-07-28 19:40:36 +08:00
|
|
|
<% end %>
|
2021-09-05 01:16:01 +08:00
|
|
|
<%= live_patch to: Routes.session_path(@socket, :export, @session.id, "exs"),
|
2021-07-28 19:40:36 +08:00
|
|
|
class: "tab #{if(@tab == "exs", do: "active")}" do %>
|
|
|
|
<span class="font-medium">
|
2022-04-25 19:37:15 +08:00
|
|
|
IEx session
|
2021-07-28 19:40:36 +08:00
|
|
|
</span>
|
|
|
|
<% end %>
|
2021-07-23 07:18:40 +08:00
|
|
|
</div>
|
2021-07-28 19:40:36 +08:00
|
|
|
<div>
|
2022-08-02 21:51:02 +08:00
|
|
|
<.live_component
|
|
|
|
module={component_for_tab(@tab)}
|
|
|
|
id={"export-notebook-#{@tab}"}
|
|
|
|
session={@session}
|
|
|
|
notebook={@notebook}
|
|
|
|
/>
|
2021-09-05 01:16:01 +08:00
|
|
|
</div>
|
2021-07-23 07:18:40 +08:00
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
"""
|
|
|
|
end
|
2021-07-28 19:40:36 +08:00
|
|
|
|
|
|
|
defp component_for_tab("livemd"), do: LivebookWeb.SessionLive.ExportLiveMarkdownComponent
|
|
|
|
defp component_for_tab("exs"), do: LivebookWeb.SessionLive.ExportElixirComponent
|
2021-07-23 07:18:40 +08:00
|
|
|
end
|