Rename Elixir cell to Code cell (#1035)

This commit is contained in:
Jonatan Kłosko 2022-03-02 12:48:02 +01:00 committed by GitHub
parent aaeac6bb95
commit e27ff5a960
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
32 changed files with 410 additions and 410 deletions

View file

@ -4,7 +4,7 @@
Livebook is a web application for writing interactive and collaborative code notebooks for Elixir, built with [Phoenix LiveView](https://github.com/phoenixframework/phoenix_live_view). It features:
* Code notebooks with Markdown support and Elixir cells where code is evaluated on demand.
* Code notebooks with Markdown support and Code cells where Elixir code is evaluated on demand.
* Shareable: notebooks are stored in the `.livemd` format, which is a subset of Markdown with support for diagrams via [Mermaid](https://mermaid-js.github.io/mermaid) and for mathematical formulas via [KaTex](https://katex.org/). `.livemd` files can be easily shared and play well with version control.

View file

@ -24,14 +24,14 @@ const Cell = {
this.state = {
isFocused: false,
insertMode: false,
// For text cells (markdown or elixir)
// For text cells (markdown or code)
liveEditor: null,
markdown: null,
evaluationDigest: null,
};
// Setup action handlers
if (this.props.type === "elixir") {
if (this.props.type === "code") {
const amplifyButton = this.el.querySelector(
`[data-element="amplify-outputs-button"]`
);
@ -74,7 +74,7 @@ const Cell = {
// Setup the editor instance.
const language = {
markdown: "markdown",
elixir: "elixir",
code: "elixir",
smart: "elixir",
}[this.props.type];
const readOnly = this.props.type === "smart";

View file

@ -2,12 +2,12 @@
* Checks if the given cell type is eligible for evaluation.
*/
export function isEvaluable(cellType) {
return ["elixir", "smart"].includes(cellType);
return ["code", "smart"].includes(cellType);
}
/**
* Checks if the given cell type has editable editor.
*/
export function isDirectlyEditable(cellType) {
return ["markdown", "elixir"].includes(cellType);
return ["markdown", "code"].includes(cellType);
}

View file

@ -396,9 +396,9 @@ function handleDocumentKeyDown(hook, event) {
} else if (keyBuffer.tryMatch(["K"])) {
moveFocusedCell(hook, -1);
} else if (keyBuffer.tryMatch(["n"])) {
insertCellBelowFocused(hook, "elixir");
insertCellBelowFocused(hook, "code");
} else if (keyBuffer.tryMatch(["N"])) {
insertCellAboveFocused(hook, "elixir");
insertCellAboveFocused(hook, "code");
} else if (keyBuffer.tryMatch(["m"])) {
insertCellBelowFocused(hook, "markdown");
} else if (keyBuffer.tryMatch(["M"])) {

View file

@ -16,7 +16,7 @@ defmodule Livebook.LiveMarkdown do
#
# 2. Every *Heading 2* starts a new section
#
# 3. Every Elixir code block maps to an Elixir cell
# 3. Every Elixir code block maps to a Code cell
#
# 4. Adjacent regular Markdown text maps to a Markdown cell
#
@ -31,7 +31,7 @@ defmodule Livebook.LiveMarkdown do
#
# - `{"force_markdown":true}` - an annotation forcing the next Markdown
# block to be treated as part of Markdown cell (relevant for Elixir code
# blocks, which otherwise are interpreted as Elixir cells)
# blocks, which otherwise are interpreted as Code cells)
#
# - `{"break_markdown":true}` - an annotation splitting the markdown content
# into separate Markdown cells
@ -73,7 +73,7 @@ defmodule Livebook.LiveMarkdown do
# ```
#
# This file defines a notebook named *My Notebook* with two sections.
# The first section includes 3 cells and the second section includes 1 Elixir cell.
# The first section includes 3 cells and the second section includes 1 Code cell.
@doc """
The file extension used by Live Markdown files.

View file

@ -111,9 +111,9 @@ defmodule Livebook.LiveMarkdown.Export do
|> prepend_metadata(metadata)
end
defp render_cell(%Cell.Elixir{} = cell, ctx) do
defp render_cell(%Cell.Code{} = cell, ctx) do
delimiter = MarkdownHelpers.code_block_delimiter(cell.source)
code = get_elixir_cell_code(cell)
code = get_code_cell_code(cell)
outputs = if ctx.include_outputs?, do: render_outputs(cell, ctx), else: []
metadata = cell_metadata(cell)
@ -130,7 +130,7 @@ defmodule Livebook.LiveMarkdown.Export do
end
defp render_cell(%Cell.Smart{} = cell, ctx) do
%{Cell.Elixir.new() | source: cell.source, outputs: cell.outputs}
%{Cell.Code.new() | source: cell.source, outputs: cell.outputs}
|> render_cell(ctx)
|> prepend_metadata(%{
"livebook_object" => "smart_cell",
@ -139,11 +139,11 @@ defmodule Livebook.LiveMarkdown.Export do
})
end
defp cell_metadata(%Cell.Elixir{} = cell) do
defp cell_metadata(%Cell.Code{} = cell) do
put_unless_default(
%{},
Map.take(cell, [:disable_formatting, :reevaluate_automatically]),
Map.take(Cell.Elixir.new(), [:disable_formatting, :reevaluate_automatically])
Map.take(Cell.Code.new(), [:disable_formatting, :reevaluate_automatically])
)
end
@ -199,10 +199,10 @@ defmodule Livebook.LiveMarkdown.Export do
defp encode_js_data(data) when is_binary(data), do: {:ok, data}
defp encode_js_data(data), do: Jason.encode(data)
defp get_elixir_cell_code(%{source: source, disable_formatting: true}),
defp get_code_cell_code(%{source: source, disable_formatting: true}),
do: source
defp get_elixir_cell_code(%{source: source}), do: format_code(source)
defp get_code_cell_code(%{source: source}), do: format_code(source)
defp render_metadata(metadata) do
metadata_json = Jason.encode!(metadata)

View file

@ -150,7 +150,7 @@ defmodule Livebook.LiveMarkdown.Import do
elems
) do
{outputs, ast} = take_outputs(ast, [])
group_elements(ast, [{:cell, :elixir, source, outputs} | elems])
group_elements(ast, [{:cell, :code, source, outputs} | elems])
end
defp group_elements([ast_node | ast], [{:cell, :markdown, md_ast} | rest]) do
@ -218,7 +218,7 @@ defmodule Livebook.LiveMarkdown.Import do
end
defp build_notebook(
[{:cell, :elixir, source, outputs}, {:cell, :smart, data} | elems],
[{:cell, :code, source, outputs}, {:cell, :smart, data} | elems],
cells,
sections,
messages,
@ -239,16 +239,16 @@ defmodule Livebook.LiveMarkdown.Import do
end
defp build_notebook(
[{:cell, :elixir, source, outputs} | elems],
[{:cell, :code, source, outputs} | elems],
cells,
sections,
messages,
output_counter
) do
{metadata, elems} = grab_metadata(elems)
attrs = cell_metadata_to_attrs(:elixir, metadata)
attrs = cell_metadata_to_attrs(:code, metadata)
{outputs, output_counter} = Notebook.index_outputs(outputs, output_counter)
cell = %{Notebook.Cell.new(:elixir) | source: source, outputs: outputs} |> Map.merge(attrs)
cell = %{Notebook.Cell.new(:code) | source: source, outputs: outputs} |> Map.merge(attrs)
build_notebook(elems, [cell | cells], sections, messages, output_counter)
end
@ -392,7 +392,7 @@ defmodule Livebook.LiveMarkdown.Import do
end)
end
defp cell_metadata_to_attrs(:elixir, metadata) do
defp cell_metadata_to_attrs(:code, metadata) do
Enum.reduce(metadata, %{}, fn
{"disable_formatting", disable_formatting}, attrs ->
Map.put(attrs, :disable_formatting, disable_formatting)

View file

@ -12,9 +12,9 @@ defmodule Livebook.Notebook.Cell do
@type id :: Utils.id()
@type t :: Cell.Markdown.t() | Cell.Elixir.t() | Cell.Smart.t()
@type t :: Cell.Markdown.t() | Cell.Code.t() | Cell.Smart.t()
@type type :: :markdown | :elixir | :smart
@type type :: :markdown | :code | :smart
@type indexed_output :: {non_neg_integer(), Livebook.Runtime.output()}
@ -25,7 +25,7 @@ defmodule Livebook.Notebook.Cell do
def new(type)
def new(:markdown), do: Cell.Markdown.new()
def new(:elixir), do: Cell.Elixir.new()
def new(:code), do: Cell.Code.new()
def new(:smart), do: Cell.Smart.new()
@doc """
@ -34,7 +34,7 @@ defmodule Livebook.Notebook.Cell do
@spec type(t()) :: type()
def type(cell)
def type(%Cell.Elixir{}), do: :elixir
def type(%Cell.Code{}), do: :code
def type(%Cell.Markdown{}), do: :markdown
def type(%Cell.Smart{}), do: :smart
@ -44,7 +44,7 @@ defmodule Livebook.Notebook.Cell do
@spec evaluable?(t()) :: boolean()
def evaluable?(cell)
def evaluable?(%Cell.Elixir{}), do: true
def evaluable?(%Cell.Code{}), do: true
def evaluable?(%Cell.Smart{}), do: true
def evaluable?(_cell), do: false

View file

@ -1,4 +1,4 @@
defmodule Livebook.Notebook.Cell.Elixir do
defmodule Livebook.Notebook.Cell.Code do
@moduledoc false
# A cell with Elixir code.

View file

@ -146,7 +146,7 @@ Process.exit(self(), :kill)
## Evaluation vs compilation
Livebook automatically shows the execution time of each Elixir
Livebook automatically shows the execution time of each Code
cell on the bottom-right of the cell. After evaluation, the total
time can be seen by hovering the green dot.

View file

@ -18,12 +18,12 @@ and run them locally.
Each notebook consists of a number of cells, which serve as primary building blocks.
There are **Markdown** cells (such as this one) that allow you to describe your work
and **Elixir** cells to run your code!
and **Code** cells to run your Elixir code!
To insert a new cell move your cursor between cells and click one of the revealed buttons. 👇
```elixir
# This is an Elixir cell - as the name suggests that's where the code goes.
# This is a Code cell - as the name suggests that's where the code goes.
# To evaluate this cell, you can either press the "Evaluate" button above
# or use `Ctrl + Enter` (or Cmd + Enter on a Mac)!
@ -83,7 +83,7 @@ suited for running long computations "in background".
Process.sleep(300_000)
```
Having this cell running, feel free to insert another Elixir cell
Having this cell running, feel free to insert another Code cell
in the section below and see it evaluates immediately.
## Saving notebooks

View file

@ -205,7 +205,7 @@ shape of a tensor using the tensor's API instead of the struct).
Primarily, a tensor is a struct, and the
functions to access it go through a specific backend. We'll get to
the backend details in a moment. For now, use the IEx `h` helper
to get more documentation about tensors. We could also open an Elixir
to get more documentation about tensors. We could also open a Code
cell, type Nx.tensor, and hover the cursor over the word `tensor`
to see the help about that function.
@ -520,8 +520,8 @@ our code within a `defn` block.
To use Nx in a Mix project or a notebook, we need to include
the `:nx` dependency and import the `Nx.Defn` module. The
dependency is already included, so import it in an Elixir
cell, like this:
dependency is already included, so import it in a Code cell,
like this:
```elixir
import Nx.Defn
@ -572,7 +572,7 @@ Now, it's your turn. Add a `defn` to `TensorMath`
that accepts two tensors representing the lengths of sides of a
right triangle and uses the pythagorean theorem to return the
[length of the hypotenuse](https://www.mathsisfun.com/pythagoras.html).
Add your function directly to the previous Elixir cell.
Add your function directly to the previous Code cell.
The last major feature we'll cover is called auto-differentiation, or autograd.

View file

@ -106,7 +106,7 @@ this particular section as a branched section, which means
the main execution flow will not be interrupted. But it
is something you should keep in mind in the future. You
can also stop it by pressing the "Stop" button above the
Elixir cell.
Code cell.
<!-- livebook:{"branch_parent_index":0} -->

View file

@ -42,7 +42,7 @@ color dialogs, selects, and more. Feel free to explore them.
Given our notebooks already know how to render Markdown,
you won't be surprised to find we can also render Markdown
directly from our Elixir cells. This is done by wrapping
directly from our Code cells. This is done by wrapping
the Markdown contents in [`Kino.Markdown.new/1`](https://hexdocs.pm/kino/Kino.Markdown.html):
````elixir

View file

@ -47,8 +47,8 @@ defmodule Livebook.Notebook.Export.Elixir do
|> Enum.map_intersperse("\n", &comment_out/1)
end
defp render_cell(%Cell.Elixir{} = cell, section) do
code = get_elixir_cell_code(cell)
defp render_cell(%Cell.Code{} = cell, section) do
code = get_code_cell_code(cell)
if section.parent_id do
code
@ -61,7 +61,7 @@ defmodule Livebook.Notebook.Export.Elixir do
end
defp render_cell(%Cell.Smart{} = cell, ctx) do
render_cell(%{Cell.Elixir.new() | source: cell.source}, ctx)
render_cell(%{Cell.Code.new() | source: cell.source}, ctx)
end
defp render_cell(_cell, _section), do: []
@ -69,10 +69,10 @@ defmodule Livebook.Notebook.Export.Elixir do
defp comment_out(""), do: ""
defp comment_out(line), do: ["# ", line]
defp get_elixir_cell_code(%{source: source, disable_formatting: true}),
defp get_code_cell_code(%{source: source, disable_formatting: true}),
do: source
defp get_elixir_cell_code(%{source: source}), do: format_code(source)
defp get_code_cell_code(%{source: source}), do: format_code(source)
defp format_code(code) do
try do

View file

@ -550,7 +550,7 @@ defmodule Livebook.Session do
end
defp default_notebook() do
%{Notebook.new() | sections: [%{Section.new() | cells: [Cell.new(:elixir)]}]}
%{Notebook.new() | sections: [%{Section.new() | cells: [Cell.new(:code)]}]}
end
defp schedule_autosave(state) do
@ -707,7 +707,7 @@ defmodule Livebook.Session do
state
|> handle_operation({:delete_cell, client_pid, cell.id})
|> handle_operation(
{:insert_cell, client_pid, section.id, index, :elixir, Utils.random_id(), attrs}
{:insert_cell, client_pid, section.id, index, :code, Utils.random_id(), attrs}
)
else
_ -> state

View file

@ -58,13 +58,13 @@ defmodule Livebook.Session.Data do
evaluation_queue: list(Cell.id())
}
@type cell_info :: markdown_cell_info() | elixir_cell_info() | smart_cell_info()
@type cell_info :: markdown_cell_info() | code_cell_info() | smart_cell_info()
@type markdown_cell_info :: %{
source: cell_source_info()
}
@type elixir_cell_info :: %{
@type code_cell_info :: %{
source: cell_source_info(),
eval: cell_eval_info()
}
@ -159,7 +159,7 @@ defmodule Livebook.Session.Data do
| {:evaluation_started, pid(), Cell.id(), binary()}
| {:add_cell_evaluation_output, pid(), Cell.id(), term()}
| {:add_cell_evaluation_response, pid(), Cell.id(), term(), metadata :: map()}
| {:bind_input, pid(), elixir_cell_id :: Cell.id(), input_id()}
| {:bind_input, pid(), code_cell_id :: Cell.id(), input_id()}
| {:reflect_main_evaluation_failure, pid()}
| {:reflect_evaluation_failure, pid(), Section.id()}
| {:cancel_cell_evaluation, pid(), Cell.id()}
@ -1466,7 +1466,7 @@ defmodule Livebook.Session.Data do
}
end
defp new_cell_info(%Cell.Elixir{}, clients_map) do
defp new_cell_info(%Cell.Code{}, clients_map) do
%{
source: new_source_info(clients_map),
eval: new_eval_info()

View file

@ -527,8 +527,8 @@ defmodule LivebookWeb.SessionLive do
"""
end
defp settings_component_for(%Cell.Elixir{}),
do: LivebookWeb.SessionLive.ElixirCellSettingsComponent
defp settings_component_for(%Cell.Code{}),
do: LivebookWeb.SessionLive.CodeCellSettingsComponent
defp branching_tooltip_attrs(name, parent_name) do
direction = if String.length(name) >= 16, do: "left", else: "right"
@ -1258,7 +1258,7 @@ defmodule LivebookWeb.SessionLive do
end
defp cell_type_and_attrs_from_params(%{"type" => "markdown"}), do: {:markdown, %{}}
defp cell_type_and_attrs_from_params(%{"type" => "elixir"}), do: {:elixir, %{}}
defp cell_type_and_attrs_from_params(%{"type" => "code"}), do: {:code, %{}}
defp cell_type_and_attrs_from_params(%{"type" => "smart", "kind" => kind}) do
{:smart, %{kind: kind}}
@ -1420,12 +1420,12 @@ defmodule LivebookWeb.SessionLive do
}
end
defp cell_to_view(%Cell.Elixir{} = cell, data) do
defp cell_to_view(%Cell.Code{} = cell, data) do
info = data.cell_infos[cell.id]
%{
id: cell.id,
type: :elixir,
type: :code,
source_view: cell_source_view(cell, info),
eval: eval_info_to_view(cell, info.eval, data),
reevaluate_automatically: cell.reevaluate_automatically

View file

@ -123,7 +123,7 @@ defmodule LivebookWeb.SessionLive.BinComponent do
"""
end
defp cell_icon(%{cell_type: :elixir} = assigns) do
defp cell_icon(%{cell_type: :code} = assigns) do
~H"""
<div class="flex w-6 h-6 bg-purple-100 rounded items-center justify-center mr-1">
<svg width="11" height="15" viewBox="0 0 11 15" fill="none" xmlns="http://www.w3.org/2000/svg">
@ -159,7 +159,7 @@ defmodule LivebookWeb.SessionLive.BinComponent do
end
defp cell_language(%Cell.Markdown{}), do: "markdown"
defp cell_language(%Cell.Elixir{}), do: "elixir"
defp cell_language(%Cell.Code{}), do: "elixir"
defp cell_language(%Cell.Smart{}), do: "elixir"
defp format_date_relatively(date) do

View file

@ -66,7 +66,7 @@ defmodule LivebookWeb.SessionLive.CellComponent do
"""
end
defp render_cell(%{cell_view: %{type: :elixir}} = assigns) do
defp render_cell(%{cell_view: %{type: :code}} = assigns) do
~H"""
<.cell_actions>
<:primary>
@ -268,7 +268,7 @@ defmodule LivebookWeb.SessionLive.CellComponent do
defp convert_smart_cell_button(assigns) do
~H"""
<span class="tooltip top" data-tooltip="Convert to Elixir cell">
<span class="tooltip top" data-tooltip="Convert to Code cell">
<button class="icon-button"
aria-label="toggle source"
phx-click={

View file

@ -1,4 +1,4 @@
defmodule LivebookWeb.SessionLive.ElixirCellSettingsComponent do
defmodule LivebookWeb.SessionLive.CodeCellSettingsComponent do
use LivebookWeb, :live_component
alias Livebook.Session

View file

@ -16,10 +16,10 @@ defmodule LivebookWeb.SessionLive.InsertButtonsComponent do
>+ Markdown</button>
<button class="button-base button-small"
phx-click="insert_cell_below"
phx-value-type="elixir"
phx-value-type="code"
phx-value-section_id={@section_id}
phx-value-cell_id={@cell_id}
>+ Elixir</button>
>+ Code</button>
<button class="button-base button-small"
phx-click="insert_section_below"
phx-value-section_id={@section_id}

View file

@ -87,9 +87,9 @@ defmodule LivebookWeb.SessionLive.ShortcutsComponent do
%{seq: ["J"], desc: "Move cell down"},
%{seq: ["K"], desc: "Move cell up"},
%{seq: ["i"], desc: "Switch to insert mode", basic: true},
%{seq: ["n"], desc: "Insert Elixir cell below", basic: true},
%{seq: ["n"], desc: "Insert Code cell below", basic: true},
%{seq: ["m"], desc: "Insert Markdown cell below", basic: true},
%{seq: ["N"], desc: "Insert Elixir cell above"},
%{seq: ["N"], desc: "Insert Code cell above"},
%{seq: ["M"], desc: "Insert Markdown cell above"},
%{seq: ["d", "d"], desc: "Delete cell", basic: true},
%{seq: ["e", "e"], desc: "Evaluate cell"},

View file

@ -26,7 +26,7 @@ defmodule Livebook.LiveMarkdown.ExportTest do
"""
},
%{
Notebook.Cell.new(:elixir)
Notebook.Cell.new(:code)
| disable_formatting: true,
reevaluate_automatically: true,
source: """
@ -47,7 +47,7 @@ defmodule Livebook.LiveMarkdown.ExportTest do
name: "Section 2",
cells: [
%{
Notebook.Cell.new(:elixir)
Notebook.Cell.new(:code)
| source: """
IO.gets("length: ")\
"""
@ -60,7 +60,7 @@ defmodule Livebook.LiveMarkdown.ExportTest do
parent_id: "s2",
cells: [
%{
Notebook.Cell.new(:elixir)
Notebook.Cell.new(:code)
| source: """
Process.info()\
"""
@ -311,7 +311,7 @@ defmodule Livebook.LiveMarkdown.ExportTest do
assert expected_document == document
end
test "formats code in Elixir cells" do
test "formats code in Code cells" do
notebook = %{
Notebook.new()
| name: "My Notebook",
@ -321,7 +321,7 @@ defmodule Livebook.LiveMarkdown.ExportTest do
| name: "Section 1",
cells: [
%{
Notebook.Cell.new(:elixir)
Notebook.Cell.new(:code)
| source: """
[1,2,3] # Comment
"""
@ -347,7 +347,7 @@ defmodule Livebook.LiveMarkdown.ExportTest do
assert expected_document == document
end
test "does not format code in Elixir cells which have formatting disabled" do
test "does not format code in Code cells which have formatting disabled" do
notebook = %{
Notebook.new()
| name: "My Notebook",
@ -357,7 +357,7 @@ defmodule Livebook.LiveMarkdown.ExportTest do
| name: "Section 1",
cells: [
%{
Notebook.Cell.new(:elixir)
Notebook.Cell.new(:code)
| disable_formatting: true,
source: """
[1,2,3] # Comment\
@ -395,7 +395,7 @@ defmodule Livebook.LiveMarkdown.ExportTest do
| name: "Section 1",
cells: [
%{
Notebook.Cell.new(:elixir)
Notebook.Cell.new(:code)
| source: """
\"\"\"
```elixir
@ -540,7 +540,7 @@ defmodule Livebook.LiveMarkdown.ExportTest do
| name: "Section 1",
cells: [
%{
Notebook.Cell.new(:elixir)
Notebook.Cell.new(:code)
| source: """
IO.puts("hey")\
""",
@ -578,7 +578,7 @@ defmodule Livebook.LiveMarkdown.ExportTest do
| name: "Section 1",
cells: [
%{
Notebook.Cell.new(:elixir)
Notebook.Cell.new(:code)
| source: """
IO.puts("hey")\
""",
@ -620,7 +620,7 @@ defmodule Livebook.LiveMarkdown.ExportTest do
| name: "Section 1",
cells: [
%{
Notebook.Cell.new(:elixir)
Notebook.Cell.new(:code)
| source: """
IO.puts("hey")\
""",
@ -668,7 +668,7 @@ defmodule Livebook.LiveMarkdown.ExportTest do
| name: "Section 1",
cells: [
%{
Notebook.Cell.new(:elixir)
Notebook.Cell.new(:code)
| source: """
IO.puts("hey")\
""",
@ -704,7 +704,7 @@ defmodule Livebook.LiveMarkdown.ExportTest do
| name: "Section 1",
cells: [
%{
Notebook.Cell.new(:elixir)
Notebook.Cell.new(:code)
| source: ":ok",
outputs: [
{0,
@ -749,7 +749,7 @@ defmodule Livebook.LiveMarkdown.ExportTest do
| name: "Section 1",
cells: [
%{
Notebook.Cell.new(:elixir)
Notebook.Cell.new(:code)
| source: ":ok",
outputs: [
{0,
@ -801,7 +801,7 @@ defmodule Livebook.LiveMarkdown.ExportTest do
| name: "Section 1",
cells: [
%{
Notebook.Cell.new(:elixir)
Notebook.Cell.new(:code)
| source: ":ok",
outputs: [
{0,
@ -852,7 +852,7 @@ defmodule Livebook.LiveMarkdown.ExportTest do
| name: "Section 1",
cells: [
%{
Notebook.Cell.new(:elixir)
Notebook.Cell.new(:code)
| source: ":ok",
outputs: [
{0,
@ -909,7 +909,7 @@ defmodule Livebook.LiveMarkdown.ExportTest do
| name: "Section 1",
cells: [
%{
Notebook.Cell.new(:elixir)
Notebook.Cell.new(:code)
| source: """
IO.puts("hey")\
""",
@ -954,7 +954,7 @@ defmodule Livebook.LiveMarkdown.ExportTest do
| name: "Section 1",
cells: [
%{
Notebook.Cell.new(:elixir)
Notebook.Cell.new(:code)
| source: """
IO.puts("hey")\
""",

View file

@ -69,7 +69,7 @@ defmodule Livebook.LiveMarkdown.ImportTest do
$x_{i} + y_{i}$\
"""
},
%Cell.Elixir{
%Cell.Code{
disable_formatting: true,
reevaluate_automatically: true,
source: """
@ -87,7 +87,7 @@ defmodule Livebook.LiveMarkdown.ImportTest do
id: section2_id,
name: "Section 2",
cells: [
%Cell.Elixir{
%Cell.Code{
source: """
IO.gets("length: ")\
"""
@ -98,7 +98,7 @@ defmodule Livebook.LiveMarkdown.ImportTest do
name: "Section 3",
parent_id: section2_id,
cells: [
%Cell.Elixir{
%Cell.Code{
source: """
Process.info()\
"""
@ -284,7 +284,7 @@ defmodule Livebook.LiveMarkdown.ImportTest do
%Notebook.Section{
name: "Section",
cells: [
%Cell.Elixir{
%Cell.Code{
source: """
Enum.to_list(1..10)\
"""
@ -379,7 +379,7 @@ defmodule Livebook.LiveMarkdown.ImportTest do
```\
"""
},
%Cell.Elixir{
%Cell.Code{
source: """
Enum.to_list(1..10)\
"""
@ -606,7 +606,7 @@ defmodule Livebook.LiveMarkdown.ImportTest do
%Notebook.Section{
name: "Section 1",
cells: [
%Cell.Elixir{
%Cell.Code{
source: """
IO.puts("hey")\
""",
@ -652,19 +652,19 @@ defmodule Livebook.LiveMarkdown.ImportTest do
%Notebook.Section{
name: "Section 1",
cells: [
%Cell.Elixir{
%Cell.Code{
source: """
IO.puts("hey")\
""",
outputs: []
},
%Cell.Elixir{
%Cell.Code{
source: """
plot()\
""",
outputs: []
},
%Cell.Elixir{
%Cell.Code{
source: """
:ok\
""",
@ -766,7 +766,7 @@ defmodule Livebook.LiveMarkdown.ImportTest do
%Notebook.Section{
name: "Section 1",
cells: [
%Cell.Elixir{
%Cell.Code{
source: """
IO.puts("hey")\
""",

View file

@ -24,7 +24,7 @@ defmodule Livebook.Notebook.Export.ElixirTest do
"""
},
%{
Notebook.Cell.new(:elixir)
Notebook.Cell.new(:code)
| disable_formatting: true,
source: """
Enum.to_list(1..10)\
@ -44,7 +44,7 @@ defmodule Livebook.Notebook.Export.ElixirTest do
name: "Section 2",
cells: [
%{
Notebook.Cell.new(:elixir)
Notebook.Cell.new(:code)
| source: """
IO.gets("length: ")\
"""
@ -65,7 +65,7 @@ defmodule Livebook.Notebook.Export.ElixirTest do
parent_id: "s2",
cells: [
%{
Notebook.Cell.new(:elixir)
Notebook.Cell.new(:code)
| source: """
Process.info()\
"""

View file

@ -74,7 +74,7 @@ defmodule Livebook.NotebookTest do
| id: "s1",
cells: [
%{Cell.new(:markdown) | id: "c1"},
%{Cell.new(:elixir) | id: "c2"}
%{Cell.new(:code) | id: "c2"}
]
},
%{
@ -82,7 +82,7 @@ defmodule Livebook.NotebookTest do
| id: "s2",
cells: [
%{Cell.new(:markdown) | id: "c3"},
%{Cell.new(:elixir) | id: "c4"}
%{Cell.new(:code) | id: "c4"}
]
}
]
@ -100,9 +100,9 @@ defmodule Livebook.NotebookTest do
notebook = %{
Notebook.new()
| sections: [
%{Section.new() | id: "s1", cells: [%{Cell.new(:elixir) | id: "c1"}]},
%{Section.new() | id: "s1", cells: [%{Cell.new(:code) | id: "c1"}]},
%{Section.new() | id: "s2", cells: []},
%{Section.new() | id: "s3", cells: [%{Cell.new(:elixir) | id: "c2"}]}
%{Section.new() | id: "s3", cells: [%{Cell.new(:code) | id: "c2"}]}
]
}
@ -120,8 +120,8 @@ defmodule Livebook.NotebookTest do
Section.new()
| id: "s1",
cells: [
%{Cell.new(:elixir) | id: "c1"},
%{Cell.new(:elixir) | id: "c2"}
%{Cell.new(:code) | id: "c1"},
%{Cell.new(:code) | id: "c2"}
]
},
%{
@ -129,16 +129,16 @@ defmodule Livebook.NotebookTest do
| id: "s2",
parent_id: "s1",
cells: [
%{Cell.new(:elixir) | id: "c3"},
%{Cell.new(:elixir) | id: "c4"}
%{Cell.new(:code) | id: "c3"},
%{Cell.new(:code) | id: "c4"}
]
},
%{
Section.new()
| id: "s3",
cells: [
%{Cell.new(:elixir) | id: "c5"},
%{Cell.new(:elixir) | id: "c6"}
%{Cell.new(:code) | id: "c5"},
%{Cell.new(:code) | id: "c6"}
]
}
]
@ -162,7 +162,7 @@ defmodule Livebook.NotebookTest do
Section.new()
| id: "s1",
cells: [
%{Cell.new(:elixir) | id: "c1"}
%{Cell.new(:code) | id: "c1"}
]
},
%{
@ -175,7 +175,7 @@ defmodule Livebook.NotebookTest do
| id: "s3",
parent_id: "s2",
cells: [
%{Cell.new(:elixir) | id: "c2"}
%{Cell.new(:code) | id: "c2"}
]
}
]
@ -195,14 +195,14 @@ defmodule Livebook.NotebookTest do
Section.new()
| id: "s1",
cells: [
%{Cell.new(:elixir) | id: "c1"}
%{Cell.new(:code) | id: "c1"}
]
},
%{
Section.new()
| id: "s2",
cells: [
%{Cell.new(:elixir) | id: "c2"}
%{Cell.new(:code) | id: "c2"}
]
},
%{
@ -210,14 +210,14 @@ defmodule Livebook.NotebookTest do
| id: "s3",
parent_id: "s1",
cells: [
%{Cell.new(:elixir) | id: "c3"}
%{Cell.new(:code) | id: "c3"}
]
},
%{
Section.new()
| id: "s4",
cells: [
%{Cell.new(:elixir) | id: "c4"}
%{Cell.new(:code) | id: "c4"}
]
}
]
@ -239,9 +239,9 @@ defmodule Livebook.NotebookTest do
Section.new()
| id: "s1",
cells: [
%{Cell.new(:elixir) | id: "c1"},
%{Cell.new(:code) | id: "c1"},
%{Cell.new(:markdown) | id: "c2"},
%{Cell.new(:elixir) | id: "c3"}
%{Cell.new(:code) | id: "c3"}
]
}
]
@ -263,7 +263,7 @@ defmodule Livebook.NotebookTest do
notebook = %{
Notebook.new()
| sections: [%{Section.new() | cells: [%{Cell.new(:elixir) | outputs: [{0, output}]}]}]
| sections: [%{Section.new() | cells: [%{Cell.new(:code) | outputs: [{0, output}]}]}]
}
assert ^assets_info = Notebook.find_asset_info(notebook, "abcd")
@ -284,7 +284,7 @@ defmodule Livebook.NotebookTest do
Section.new()
| id: "s1",
cells: [
%{Cell.new(:elixir) | id: "c1", outputs: [{0, {:stdout, "Hola"}}]}
%{Cell.new(:code) | id: "c1", outputs: [{0, {:stdout, "Hola"}}]}
]
}
],
@ -308,7 +308,7 @@ defmodule Livebook.NotebookTest do
Section.new()
| id: "s1",
cells: [
%{Cell.new(:elixir) | id: "c1", outputs: []}
%{Cell.new(:code) | id: "c1", outputs: []}
]
}
],
@ -332,7 +332,7 @@ defmodule Livebook.NotebookTest do
Section.new()
| id: "s1",
cells: [
%{Cell.new(:elixir) | id: "c1", outputs: [{0, {:stdout, "Hola"}}]}
%{Cell.new(:code) | id: "c1", outputs: [{0, {:stdout, "Hola"}}]}
]
}
],
@ -357,12 +357,12 @@ defmodule Livebook.NotebookTest do
| id: "s1",
cells: [
%{
Cell.new(:elixir)
Cell.new(:code)
| id: "c1",
outputs: [{0, {:frame, [], %{ref: "1", type: :default}}}]
},
%{
Cell.new(:elixir)
Cell.new(:code)
| id: "c2",
outputs: [{1, {:frame, [], %{ref: "1", type: :default}}}]
}

File diff suppressed because it is too large Load diff

View file

@ -57,8 +57,8 @@ defmodule Livebook.SessionTest do
Session.insert_section(session.pid, 0)
assert_receive {:operation, {:insert_section, ^pid, 0, section_id}}
Session.insert_cell(session.pid, section_id, 0, :elixir)
assert_receive {:operation, {:insert_cell, ^pid, ^section_id, 0, :elixir, _id, _attrs}}
Session.insert_cell(session.pid, section_id, 0, :code)
assert_receive {:operation, {:insert_cell, ^pid, ^section_id, 0, :code, _id, _attrs}}
end
end
@ -118,7 +118,7 @@ defmodule Livebook.SessionTest do
assert_receive {:operation, {:delete_cell, ^pid, ^cell_id}}
assert_receive {:operation,
{:insert_cell, ^pid, ^section_id, 0, :elixir, _id,
{:insert_cell, ^pid, ^section_id, 0, :code, _id,
%{source: "content", outputs: []}}}
end
end
@ -505,20 +505,20 @@ defmodule Livebook.SessionTest do
describe "user input" do
test "replies to runtime input request" do
input_elixir_cell = %{Notebook.Cell.new(:elixir) | source: @livebook_put_input_code}
input_code_cell = %{Notebook.Cell.new(:code) | source: @livebook_put_input_code}
elixir_cell = %{Notebook.Cell.new(:elixir) | source: @livebook_get_input_value_code}
code_cell = %{Notebook.Cell.new(:code) | source: @livebook_get_input_value_code}
notebook = %{
Notebook.new()
| sections: [
%{Notebook.Section.new() | cells: [input_elixir_cell, elixir_cell]}
%{Notebook.Section.new() | cells: [input_code_cell, code_cell]}
]
}
session = start_session(notebook: notebook)
cell_id = elixir_cell.id
cell_id = code_cell.id
Phoenix.PubSub.subscribe(Livebook.PubSub, "sessions:#{session.id}")
Session.queue_cell_evaluation(session.pid, cell_id)
@ -531,18 +531,18 @@ defmodule Livebook.SessionTest do
end
test "replies with error when no matching input is found" do
elixir_cell = %{Notebook.Cell.new(:elixir) | source: @livebook_get_input_value_code}
code_cell = %{Notebook.Cell.new(:code) | source: @livebook_get_input_value_code}
notebook = %{
Notebook.new()
| sections: [
%{Notebook.Section.new() | cells: [elixir_cell]}
%{Notebook.Section.new() | cells: [code_cell]}
]
}
session = start_session(notebook: notebook)
cell_id = elixir_cell.id
cell_id = code_cell.id
Phoenix.PubSub.subscribe(Livebook.PubSub, "sessions:#{session.id}")
Session.queue_cell_evaluation(session.pid, cell_id)
@ -588,12 +588,12 @@ defmodule Livebook.SessionTest do
end
describe "find_prev_locator/3" do
test "given cell in main flow returns previous Elixir cell" do
cell1 = %{Cell.new(:elixir) | id: "c1"}
test "given cell in main flow returns previous Code cell" do
cell1 = %{Cell.new(:code) | id: "c1"}
cell2 = %{Cell.new(:markdown) | id: "c2"}
section1 = %{Section.new() | id: "s1", cells: [cell1, cell2]}
cell3 = %{Cell.new(:elixir) | id: "c3"}
cell3 = %{Cell.new(:code) | id: "c3"}
section2 = %{Section.new() | id: "s2", cells: [cell3]}
notebook = %{Notebook.new() | sections: [section1, section2]}
@ -601,12 +601,12 @@ defmodule Livebook.SessionTest do
assert {:main_flow, "c1"} = Session.find_prev_locator(notebook, cell3, section2)
end
test "given cell in branching section returns previous Elixir cell in that section" do
test "given cell in branching section returns previous Code cell in that section" do
section1 = %{Section.new() | id: "s1"}
cell1 = %{Cell.new(:elixir) | id: "c1"}
cell1 = %{Cell.new(:code) | id: "c1"}
cell2 = %{Cell.new(:markdown) | id: "c2"}
cell3 = %{Cell.new(:elixir) | id: "c3"}
cell3 = %{Cell.new(:code) | id: "c3"}
section2 = %{
Section.new()
@ -624,7 +624,7 @@ defmodule Livebook.SessionTest do
cell1 = %{Cell.new(:markdown) | id: "c1"}
section1 = %{Section.new() | id: "s1", cells: [cell1]}
cell2 = %{Cell.new(:elixir) | id: "c2"}
cell2 = %{Cell.new(:code) | id: "c2"}
section2 = %{Section.new() | id: "s2", cells: [cell2]}
notebook = %{Notebook.new() | sections: [section1, section2]}
@ -636,7 +636,7 @@ defmodule Livebook.SessionTest do
cell1 = %{Cell.new(:markdown) | id: "c1"}
section1 = %{Section.new() | id: "s1", cells: [cell1]}
cell2 = %{Cell.new(:elixir) | id: "c2"}
cell2 = %{Cell.new(:code) | id: "c2"}
section2 = %{
Section.new()
@ -696,8 +696,8 @@ defmodule Livebook.SessionTest do
defp insert_section_and_cell(session_pid) do
Session.insert_section(session_pid, 0)
assert_receive {:operation, {:insert_section, _, 0, section_id}}
Session.insert_cell(session_pid, section_id, 0, :elixir)
assert_receive {:operation, {:insert_cell, _, ^section_id, 0, :elixir, cell_id, _attrs}}
Session.insert_cell(session_pid, section_id, 0, :code)
assert_receive {:operation, {:insert_cell, _, ^section_id, 0, :code, cell_id, _attrs}}
{section_id, cell_id}
end

View file

@ -86,7 +86,7 @@ defmodule LivebookWeb.SessionControllerTest do
| name: "Section 1",
cells: [
%{
Notebook.Cell.new(:elixir)
Notebook.Cell.new(:code)
| source: """
IO.puts("hey")\
""",
@ -213,7 +213,7 @@ defmodule LivebookWeb.SessionControllerTest do
| sections: [
%{
Notebook.Section.new()
| cells: [%{Notebook.Cell.new(:elixir) | outputs: [{0, output}]}]
| cells: [%{Notebook.Cell.new(:code) | outputs: [{0, output}]}]
}
]
}

View file

@ -115,7 +115,7 @@ defmodule LivebookWeb.SessionLiveTest do
test "queueing cell evaluation", %{conn: conn, session: session} do
section_id = insert_section(session.pid)
cell_id = insert_text_cell(session.pid, section_id, :elixir, "Process.sleep(50)")
cell_id = insert_text_cell(session.pid, section_id, :code, "Process.sleep(50)")
{:ok, view, _} = live(conn, "/sessions/#{session.id}")
@ -129,7 +129,7 @@ defmodule LivebookWeb.SessionLiveTest do
test "cancelling cell evaluation", %{conn: conn, session: session} do
section_id = insert_section(session.pid)
cell_id = insert_text_cell(session.pid, section_id, :elixir, "Process.sleep(2000)")
cell_id = insert_text_cell(session.pid, section_id, :code, "Process.sleep(2000)")
{:ok, view, _} = live(conn, "/sessions/#{session.id}")
@ -147,7 +147,7 @@ defmodule LivebookWeb.SessionLiveTest do
test "inserting a cell below the given cell", %{conn: conn, session: session} do
section_id = insert_section(session.pid)
cell_id = insert_text_cell(session.pid, section_id, :elixir)
cell_id = insert_text_cell(session.pid, section_id, :code)
{:ok, view, _} = live(conn, "/sessions/#{session.id}")
@ -161,7 +161,7 @@ defmodule LivebookWeb.SessionLiveTest do
test "inserting a cell at section start", %{conn: conn, session: session} do
section_id = insert_section(session.pid)
_cell_id = insert_text_cell(session.pid, section_id, :elixir)
_cell_id = insert_text_cell(session.pid, section_id, :code)
{:ok, view, _} = live(conn, "/sessions/#{session.id}")
@ -175,7 +175,7 @@ defmodule LivebookWeb.SessionLiveTest do
test "deleting the given cell", %{conn: conn, session: session} do
section_id = insert_section(session.pid)
cell_id = insert_text_cell(session.pid, section_id, :elixir)
cell_id = insert_text_cell(session.pid, section_id, :code)
{:ok, view, _} = live(conn, "/sessions/#{session.id}")
@ -188,7 +188,7 @@ defmodule LivebookWeb.SessionLiveTest do
test "restoring a deleted cell", %{conn: conn, session: session} do
section_id = insert_section(session.pid)
cell_id = insert_text_cell(session.pid, section_id, :elixir)
cell_id = insert_text_cell(session.pid, section_id, :code)
Session.delete_cell(session.pid, cell_id)
@ -315,7 +315,7 @@ defmodule LivebookWeb.SessionLiveTest do
describe "outputs" do
test "stdout output update", %{conn: conn, session: session} do
section_id = insert_section(session.pid)
cell_id = insert_text_cell(session.pid, section_id, :elixir)
cell_id = insert_text_cell(session.pid, section_id, :code)
Session.queue_cell_evaluation(session.pid, cell_id)
@ -333,7 +333,7 @@ defmodule LivebookWeb.SessionLiveTest do
test "frame output update", %{conn: conn, session: session} do
section_id = insert_section(session.pid)
cell_id = insert_text_cell(session.pid, section_id, :elixir)
cell_id = insert_text_cell(session.pid, section_id, :code)
Session.queue_cell_evaluation(session.pid, cell_id)
@ -484,7 +484,7 @@ defmodule LivebookWeb.SessionLiveTest do
test "replies with nil completion reference when no runtime is started",
%{conn: conn, session: session} do
section_id = insert_section(session.pid)
cell_id = insert_text_cell(session.pid, section_id, :elixir, "Process.sleep(10)")
cell_id = insert_text_cell(session.pid, section_id, :code, "Process.sleep(10)")
{:ok, view, _} = live(conn, "/sessions/#{session.id}")
@ -503,7 +503,7 @@ defmodule LivebookWeb.SessionLiveTest do
test "replies with completion reference and then sends asynchronous response",
%{conn: conn, session: session} do
section_id = insert_section(session.pid)
cell_id = insert_text_cell(session.pid, section_id, :elixir, "Process.sleep(10)")
cell_id = insert_text_cell(session.pid, section_id, :code, "Process.sleep(10)")
{:ok, runtime} = Livebook.Runtime.Embedded.init()
Session.connect_runtime(session.pid, runtime)
@ -907,7 +907,7 @@ defmodule LivebookWeb.SessionLiveTest do
end
|> Macro.to_string()
cell_id = insert_text_cell(session_pid, section_id, :elixir, code)
cell_id = insert_text_cell(session_pid, section_id, :code, code)
Session.queue_cell_evaluation(session_pid, cell_id)
assert_receive {:operation, {:add_cell_evaluation_response, _, ^cell_id, _, _}}
cell_id

View file

@ -2,7 +2,7 @@
## First section
One Elixir cell below.
One Code cell below.
```elixir
length([1, 2, 3])