mirror of
https://github.com/livebook-dev/livebook.git
synced 2024-09-20 01:55:56 +08:00
Update instructions in the Elixir export (#1144)
This commit is contained in:
parent
94dc3862a3
commit
f39699b65e
|
@ -15,11 +15,13 @@ defmodule Livebook.Notebook.Export.Elixir do
|
|||
defp render_notebook(notebook) do
|
||||
%{setup_section: %{cells: [setup_cell]} = setup_section} = notebook
|
||||
|
||||
prelude = "# Run as: iex --dot-iex path/to/notebook.exs"
|
||||
|
||||
name = ["# Title: ", notebook.name]
|
||||
setup_cell = render_setup_cell(setup_cell, setup_section)
|
||||
sections = Enum.map(notebook.sections, &render_section(&1, notebook))
|
||||
|
||||
[name, setup_cell | sections]
|
||||
[prelude, name, setup_cell | sections]
|
||||
|> Enum.reject(&is_nil/1)
|
||||
|> Enum.intersperse("\n\n")
|
||||
end
|
||||
|
|
|
@ -41,7 +41,7 @@ defmodule LivebookWeb.SessionLive.ExportComponent do
|
|||
<%= live_patch to: Routes.session_path(@socket, :export, @session.id, "exs"),
|
||||
class: "tab #{if(@tab == "exs", do: "active")}" do %>
|
||||
<span class="font-medium">
|
||||
Elixir Script
|
||||
IEx session
|
||||
</span>
|
||||
<% end %>
|
||||
</div>
|
||||
|
|
|
@ -17,16 +17,6 @@ defmodule LivebookWeb.SessionLive.ExportElixirComponent do
|
|||
def render(assigns) do
|
||||
~H"""
|
||||
<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 justify-between items-center">
|
||||
<span class="text-sm text-gray-700 font-semibold">
|
||||
|
|
|
@ -76,6 +76,8 @@ defmodule Livebook.Notebook.Export.ElixirTest do
|
|||
}
|
||||
|
||||
expected_document = """
|
||||
# Run as: iex --dot-iex path/to/notebook.exs
|
||||
|
||||
# Title: My Notebook
|
||||
|
||||
# ── Section 1 ──
|
||||
|
@ -117,6 +119,8 @@ defmodule Livebook.Notebook.Export.ElixirTest do
|
|||
|> Notebook.put_setup_cell(%{Notebook.Cell.new(:code) | source: "Mix.install([...])"})
|
||||
|
||||
expected_document = """
|
||||
# Run as: iex --dot-iex path/to/notebook.exs
|
||||
|
||||
# Title: My Notebook
|
||||
|
||||
Mix.install([...])
|
||||
|
|
|
@ -15,6 +15,8 @@ defmodule LivebookTest do
|
|||
"""
|
||||
|
||||
assert Livebook.live_markdown_to_elixir(markdown) == """
|
||||
# Run as: iex --dot-iex path/to/notebook.exs
|
||||
|
||||
# Title: Lists
|
||||
|
||||
# ── Introduction ──
|
||||
|
|
|
@ -133,6 +133,8 @@ defmodule LivebookWeb.SessionControllerTest do
|
|||
assert get_resp_header(conn, "content-type") == ["text/plain"]
|
||||
|
||||
assert conn.resp_body == """
|
||||
# Run as: iex --dot-iex path/to/notebook.exs
|
||||
|
||||
# Title: Untitled notebook
|
||||
|
||||
# ── Section ──
|
||||
|
|
Loading…
Reference in a new issue