mirror of
https://github.com/livebook-dev/livebook.git
synced 2025-01-30 10:47:51 +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
|
||||
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)
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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;"
|
||||
|
|
Loading…
Reference in a new issue