Refactoring codes (#1097)

* refactoring codes

* Apply suggestions from code review

Co-authored-by: Jonatan Kłosko <jonatanklosko@gmail.com>
This commit is contained in:
ByeongUk Choi 2022-04-09 22:53:17 +09:00 committed by GitHub
parent 28e8a04a99
commit a2802248ab
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
4 changed files with 9 additions and 14 deletions

View file

@ -323,8 +323,7 @@ defimpl Livebook.FileSystem, for: Livebook.FileSystem.S3 do
defp encode_key(key) do
key
|> String.split("/")
|> Enum.map(fn segment -> URI.encode(segment, &URI.char_unreserved?/1) end)
|> Enum.join("/")
|> Enum.map_join("/", fn segment -> URI.encode(segment, &URI.char_unreserved?/1) end)
end
defp request_response_to_error(error)

View file

@ -38,9 +38,7 @@ defmodule Livebook.LiveMarkdown.MarkdownHelpers do
def text_from_ast(ast)
def text_from_ast(ast) when is_list(ast) do
ast
|> Enum.map(&text_from_ast/1)
|> Enum.join("")
Enum.map_join(ast, &text_from_ast/1)
end
def text_from_ast(ast) when is_binary(ast), do: ast

View file

@ -1073,17 +1073,17 @@ defmodule Livebook.Session do
with {:ok, source_exists?} <- FileSystem.File.exists?(source) do
if source_exists? do
with {:ok, destination_exists?} <- FileSystem.File.exists?(images_dir) do
if not 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 destination_exists? do
# If the directory exists, we use copy to place
# the images there
with :ok <- FileSystem.File.copy(source, images_dir) do
FileSystem.File.remove(source)
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
else

View file

@ -31,9 +31,7 @@ defmodule LivebookWeb.Helpers.ANSI do
end
defp modifiers_to_css(modifiers) do
modifiers
|> Enum.map(&modifier_to_css/1)
|> Enum.join()
Enum.map_join(modifiers, &modifier_to_css/1)
end
defp modifier_to_css({:font_weight, :bold}), do: "font-weight: 600;"