mirror of
https://github.com/livebook-dev/livebook.git
synced 2025-10-12 06:25:56 +08:00
Refactoring codes (#1097)
* refactoring codes * Apply suggestions from code review Co-authored-by: Jonatan Kłosko <jonatanklosko@gmail.com>
This commit is contained in:
parent
28e8a04a99
commit
a2802248ab
4 changed files with 9 additions and 14 deletions
|
@ -323,8 +323,7 @@ defimpl Livebook.FileSystem, for: Livebook.FileSystem.S3 do
|
||||||
defp encode_key(key) do
|
defp encode_key(key) do
|
||||||
key
|
key
|
||||||
|> String.split("/")
|
|> String.split("/")
|
||||||
|> Enum.map(fn segment -> URI.encode(segment, &URI.char_unreserved?/1) end)
|
|> Enum.map_join("/", fn segment -> URI.encode(segment, &URI.char_unreserved?/1) end)
|
||||||
|> Enum.join("/")
|
|
||||||
end
|
end
|
||||||
|
|
||||||
defp request_response_to_error(error)
|
defp request_response_to_error(error)
|
||||||
|
|
|
@ -38,9 +38,7 @@ defmodule Livebook.LiveMarkdown.MarkdownHelpers do
|
||||||
def text_from_ast(ast)
|
def text_from_ast(ast)
|
||||||
|
|
||||||
def text_from_ast(ast) when is_list(ast) do
|
def text_from_ast(ast) when is_list(ast) do
|
||||||
ast
|
Enum.map_join(ast, &text_from_ast/1)
|
||||||
|> Enum.map(&text_from_ast/1)
|
|
||||||
|> Enum.join("")
|
|
||||||
end
|
end
|
||||||
|
|
||||||
def text_from_ast(ast) when is_binary(ast), do: ast
|
def text_from_ast(ast) when is_binary(ast), do: ast
|
||||||
|
|
|
@ -1073,17 +1073,17 @@ defmodule Livebook.Session do
|
||||||
with {:ok, source_exists?} <- FileSystem.File.exists?(source) do
|
with {:ok, source_exists?} <- FileSystem.File.exists?(source) do
|
||||||
if source_exists? do
|
if source_exists? do
|
||||||
with {:ok, destination_exists?} <- FileSystem.File.exists?(images_dir) do
|
with {:ok, destination_exists?} <- FileSystem.File.exists?(images_dir) do
|
||||||
if not destination_exists? do
|
if destination_exists? do
|
||||||
# If the directory doesn't exist, we can just change
|
|
||||||
# the directory name, which is more efficient if
|
|
||||||
# available in the given file system
|
|
||||||
FileSystem.File.rename(source, images_dir)
|
|
||||||
else
|
|
||||||
# If the directory exists, we use copy to place
|
# If the directory exists, we use copy to place
|
||||||
# the images there
|
# the images there
|
||||||
with :ok <- FileSystem.File.copy(source, images_dir) do
|
with :ok <- FileSystem.File.copy(source, images_dir) do
|
||||||
FileSystem.File.remove(source)
|
FileSystem.File.remove(source)
|
||||||
end
|
end
|
||||||
|
else
|
||||||
|
# If the directory doesn't exist, we can just change
|
||||||
|
# the directory name, which is more efficient if
|
||||||
|
# available in the given file system
|
||||||
|
FileSystem.File.rename(source, images_dir)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
else
|
else
|
||||||
|
|
|
@ -31,9 +31,7 @@ defmodule LivebookWeb.Helpers.ANSI do
|
||||||
end
|
end
|
||||||
|
|
||||||
defp modifiers_to_css(modifiers) do
|
defp modifiers_to_css(modifiers) do
|
||||||
modifiers
|
Enum.map_join(modifiers, &modifier_to_css/1)
|
||||||
|> Enum.map(&modifier_to_css/1)
|
|
||||||
|> Enum.join()
|
|
||||||
end
|
end
|
||||||
|
|
||||||
defp modifier_to_css({:font_weight, :bold}), do: "font-weight: 600;"
|
defp modifier_to_css({:font_weight, :bold}), do: "font-weight: 600;"
|
||||||
|
|
Loading…
Add table
Reference in a new issue