mirror of
https://github.com/livebook-dev/livebook.git
synced 2025-12-17 21:50:25 +08:00
Update instructions in the Elixir export (#1144)
This commit is contained in:
parent
94dc3862a3
commit
f39699b65e
6 changed files with 12 additions and 12 deletions
|
|
@ -15,11 +15,13 @@ defmodule Livebook.Notebook.Export.Elixir do
|
||||||
defp render_notebook(notebook) do
|
defp render_notebook(notebook) do
|
||||||
%{setup_section: %{cells: [setup_cell]} = setup_section} = notebook
|
%{setup_section: %{cells: [setup_cell]} = setup_section} = notebook
|
||||||
|
|
||||||
|
prelude = "# Run as: iex --dot-iex path/to/notebook.exs"
|
||||||
|
|
||||||
name = ["# Title: ", notebook.name]
|
name = ["# Title: ", notebook.name]
|
||||||
setup_cell = render_setup_cell(setup_cell, setup_section)
|
setup_cell = render_setup_cell(setup_cell, setup_section)
|
||||||
sections = Enum.map(notebook.sections, &render_section(&1, notebook))
|
sections = Enum.map(notebook.sections, &render_section(&1, notebook))
|
||||||
|
|
||||||
[name, setup_cell | sections]
|
[prelude, name, setup_cell | sections]
|
||||||
|> Enum.reject(&is_nil/1)
|
|> Enum.reject(&is_nil/1)
|
||||||
|> Enum.intersperse("\n\n")
|
|> Enum.intersperse("\n\n")
|
||||||
end
|
end
|
||||||
|
|
|
||||||
|
|
@ -41,7 +41,7 @@ defmodule LivebookWeb.SessionLive.ExportComponent do
|
||||||
<%= live_patch to: Routes.session_path(@socket, :export, @session.id, "exs"),
|
<%= live_patch to: Routes.session_path(@socket, :export, @session.id, "exs"),
|
||||||
class: "tab #{if(@tab == "exs", do: "active")}" do %>
|
class: "tab #{if(@tab == "exs", do: "active")}" do %>
|
||||||
<span class="font-medium">
|
<span class="font-medium">
|
||||||
Elixir Script
|
IEx session
|
||||||
</span>
|
</span>
|
||||||
<% end %>
|
<% end %>
|
||||||
</div>
|
</div>
|
||||||
|
|
|
||||||
|
|
@ -17,16 +17,6 @@ defmodule LivebookWeb.SessionLive.ExportElixirComponent do
|
||||||
def render(assigns) do
|
def render(assigns) do
|
||||||
~H"""
|
~H"""
|
||||||
<div class="flex flex-col space-y-6">
|
<div class="flex flex-col space-y-6">
|
||||||
<p class="text-gray-700">
|
|
||||||
<span class="font-semibold">Note:</span>
|
|
||||||
the script export is available as a convenience, rather than
|
|
||||||
an exact reproduction of the notebook and in some cases it may
|
|
||||||
not even compile. For example, if you define a macro in one cell
|
|
||||||
and import it in another cell, it works fine in Livebook,
|
|
||||||
because each cell is compiled separately. However, when running
|
|
||||||
the script it gets compiled as a whole and consequently doing so
|
|
||||||
doesn't work. Additionally, branching sections are commented out.
|
|
||||||
</p>
|
|
||||||
<div class="flex flex-col space-y-1">
|
<div class="flex flex-col space-y-1">
|
||||||
<div class="flex justify-between items-center">
|
<div class="flex justify-between items-center">
|
||||||
<span class="text-sm text-gray-700 font-semibold">
|
<span class="text-sm text-gray-700 font-semibold">
|
||||||
|
|
|
||||||
|
|
@ -76,6 +76,8 @@ defmodule Livebook.Notebook.Export.ElixirTest do
|
||||||
}
|
}
|
||||||
|
|
||||||
expected_document = """
|
expected_document = """
|
||||||
|
# Run as: iex --dot-iex path/to/notebook.exs
|
||||||
|
|
||||||
# Title: My Notebook
|
# Title: My Notebook
|
||||||
|
|
||||||
# ── Section 1 ──
|
# ── Section 1 ──
|
||||||
|
|
@ -117,6 +119,8 @@ defmodule Livebook.Notebook.Export.ElixirTest do
|
||||||
|> Notebook.put_setup_cell(%{Notebook.Cell.new(:code) | source: "Mix.install([...])"})
|
|> Notebook.put_setup_cell(%{Notebook.Cell.new(:code) | source: "Mix.install([...])"})
|
||||||
|
|
||||||
expected_document = """
|
expected_document = """
|
||||||
|
# Run as: iex --dot-iex path/to/notebook.exs
|
||||||
|
|
||||||
# Title: My Notebook
|
# Title: My Notebook
|
||||||
|
|
||||||
Mix.install([...])
|
Mix.install([...])
|
||||||
|
|
|
||||||
|
|
@ -15,6 +15,8 @@ defmodule LivebookTest do
|
||||||
"""
|
"""
|
||||||
|
|
||||||
assert Livebook.live_markdown_to_elixir(markdown) == """
|
assert Livebook.live_markdown_to_elixir(markdown) == """
|
||||||
|
# Run as: iex --dot-iex path/to/notebook.exs
|
||||||
|
|
||||||
# Title: Lists
|
# Title: Lists
|
||||||
|
|
||||||
# ── Introduction ──
|
# ── Introduction ──
|
||||||
|
|
|
||||||
|
|
@ -133,6 +133,8 @@ defmodule LivebookWeb.SessionControllerTest do
|
||||||
assert get_resp_header(conn, "content-type") == ["text/plain"]
|
assert get_resp_header(conn, "content-type") == ["text/plain"]
|
||||||
|
|
||||||
assert conn.resp_body == """
|
assert conn.resp_body == """
|
||||||
|
# Run as: iex --dot-iex path/to/notebook.exs
|
||||||
|
|
||||||
# Title: Untitled notebook
|
# Title: Untitled notebook
|
||||||
|
|
||||||
# ── Section ──
|
# ── Section ──
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue