Persist show-source app option (#1859)

This commit is contained in:
Jonatan Kłosko 2023-04-13 17:02:03 +02:00 committed by GitHub
parent 01bcf1fd1a
commit f9efd2079c
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
4 changed files with 13 additions and 5 deletions

View file

@ -86,7 +86,7 @@ defmodule Livebook.LiveMarkdown.Export do
end end
defp app_settings_metadata(app_settings) do defp app_settings_metadata(app_settings) do
keys = [:slug, :access_type] keys = [:slug, :access_type, :show_source]
put_unless_default( put_unless_default(
%{}, %{},

View file

@ -404,6 +404,9 @@ defmodule Livebook.LiveMarkdown.Import do
{"slug", slug}, attrs -> {"slug", slug}, attrs ->
Map.put(attrs, :slug, slug) Map.put(attrs, :slug, slug)
{"show_source", show_source}, attrs ->
Map.put(attrs, :show_source, show_source)
{"access_type", access_type}, attrs when access_type in ["public", "protected"] -> {"access_type", access_type}, attrs when access_type in ["public", "protected"] ->
Map.put(attrs, :access_type, String.to_atom(access_type)) Map.put(attrs, :access_type, String.to_atom(access_type))

View file

@ -1146,11 +1146,16 @@ defmodule Livebook.LiveMarkdown.ExportTest do
notebook = %{ notebook = %{
Notebook.new() Notebook.new()
| name: "My Notebook", | name: "My Notebook",
app_settings: %{Notebook.AppSettings.new() | slug: "app", access_type: :public} app_settings: %{
Notebook.AppSettings.new()
| slug: "app",
access_type: :public,
show_source: true
}
} }
expected_document = """ expected_document = """
<!-- livebook:{"app_settings":{"access_type":"public","slug":"app"}} --> <!-- livebook:{"app_settings":{"access_type":"public","show_source":true,"slug":"app"}} -->
# My Notebook # My Notebook
""" """

View file

@ -750,7 +750,7 @@ defmodule Livebook.LiveMarkdown.ImportTest do
describe "app settings" do describe "app settings" do
test "imports settings" do test "imports settings" do
markdown = """ markdown = """
<!-- livebook:{"app_settings":{"access_type":"public","slug":"app"}} --> <!-- livebook:{"app_settings":{"access_type":"public","show_source":true,"slug":"app"}} -->
# My Notebook # My Notebook
""" """
@ -759,7 +759,7 @@ defmodule Livebook.LiveMarkdown.ImportTest do
assert %Notebook{ assert %Notebook{
name: "My Notebook", name: "My Notebook",
app_settings: %{slug: "app", access_type: :public} app_settings: %{slug: "app", access_type: :public, show_source: true}
} = notebook } = notebook
end end