Skip to content

Commit

Permalink
Refactor
Browse files Browse the repository at this point in the history
  • Loading branch information
camelpunch committed Oct 14, 2024
1 parent bbef004 commit 8a658ea
Show file tree
Hide file tree
Showing 5 changed files with 20 additions and 22 deletions.
12 changes: 12 additions & 0 deletions lib/mudbrick.ex
Original file line number Diff line number Diff line change
Expand Up @@ -115,4 +115,16 @@ defmodule Mudbrick do
|> Integer.to_string(16)
|> String.pad_leading(4, "0")
end

def join(a, separator \\ " ")

def join(tuple, separator) when is_tuple(tuple) do
tuple
|> Tuple.to_list()
|> join(separator)
end

def join(list, separator) do
Enum.map_join(list, separator, &Mudbrick.Object.from/1)
end
end
2 changes: 1 addition & 1 deletion lib/mudbrick/content_stream.ex
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@ defmodule Mudbrick.ContentStream do
"BT\n",
content_stream.operations
|> Enum.reverse()
|> Enum.map_join("\n", &Mudbrick.Object.from/1),
|> Mudbrick.join("\n"),
"\nET"
]
)
Expand Down
6 changes: 3 additions & 3 deletions lib/mudbrick/font/cmap.ex
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,9 @@ defmodule Mudbrick.Font.CMap do
12 dict begin
begincmap
/CIDSystemInfo
<< /Registry (Adobe)
/Ordering (UCS)
/Supplement 0
<</Registry (Adobe)
/Ordering (UCS)
/Supplement 0
>> def
/CMapName /Adobe-Identity-UCS def
/CMapType 2 def
Expand Down
16 changes: 2 additions & 14 deletions lib/mudbrick/serialisation/object.ex
Original file line number Diff line number Diff line change
Expand Up @@ -66,13 +66,7 @@ end

defimpl Mudbrick.Object, for: List do
def from(list) do
[
?[,
list
|> Enum.map(&Mudbrick.Object.from(&1))
|> Enum.intersperse(?\s),
?]
]
[?[, Mudbrick.join(list), ?]]
end
end

Expand All @@ -94,12 +88,6 @@ defimpl Mudbrick.Object, for: Map do
end

defp format_kvs(kvs) do
kvs
|> Enum.map(fn {k, v} -> pair(k, v) end)
|> Enum.intersperse("\n ")
end

defp pair(k, v) do
[Mudbrick.Object.from(k), ?\s, Mudbrick.Object.from(v)]
Enum.map_join(kvs, "\n ", &Mudbrick.join/1)
end
end
6 changes: 2 additions & 4 deletions test/mudbrick/content_stream_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ defmodule Mudbrick.ContentStreamTest do
alias Mudbrick.ContentStream.Tj
alias Mudbrick.Font
alias Mudbrick.Indirect
alias Mudbrick.Object

@font_data System.fetch_env!("FONT_LIBRE_BODONI_REGULAR") |> File.read!()

Expand Down Expand Up @@ -110,8 +109,7 @@ defmodule Mudbrick.ContentStreamTest do
ops
|> Enum.take(n)
|> Enum.reverse()
|> Enum.map_join("\n", fn op ->
Object.from(op) |> to_string()
end)
|> Mudbrick.join("\n")
|> to_string()
end
end

0 comments on commit 8a658ea

Please sign in to comment.