Skip to content

Commit 42f11b5

Browse files
committed
Vector drawing bootstrapping
1 parent 0e59ed5 commit 42f11b5

File tree

5 files changed

+51
-4
lines changed

5 files changed

+51
-4
lines changed

lib/mudbrick/drawing.ex

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
defmodule Mudbrick.Drawing do
2+
defstruct lines: []
3+
4+
def new() do
5+
struct!(__MODULE__, [])
6+
end
7+
8+
defmodule Path do
9+
@enforce_keys [:from, :to]
10+
defstruct [:from, :to]
11+
12+
def new(drawing, opts) do
13+
Map.update!(drawing, :lines, fn lines ->
14+
[struct!(__MODULE__, opts) | lines]
15+
end)
16+
end
17+
end
18+
end

lib/mudbrick/drawing/output.ex

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
defmodule Mudbrick.Drawing.Output do
2+
defstruct operations: []
3+
4+
def from(_) do
5+
%__MODULE__{}
6+
end
7+
end

test/mudbrick/drawing_test.exs

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
defmodule Mudbrick.DrawingTest do
2+
use ExUnit.Case, async: true
3+
4+
import Mudbrick.TestHelper, only: [output: 2]
5+
6+
alias Mudbrick.Drawing
7+
8+
test "can make an empty line drawing" do
9+
assert [] =
10+
output(fn ->
11+
Drawing.new()
12+
end)
13+
|> operations()
14+
end
15+
16+
defp output(f), do: output(fn _ -> f.() end, Mudbrick.Drawing.Output)
17+
18+
defp operations(ops) do
19+
Enum.map(ops, &Mudbrick.TestHelper.show/1)
20+
end
21+
end

test/mudbrick/text_block_test.exs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
defmodule Mudbrick.TextBlockTest do
22
use ExUnit.Case, async: true
33

4-
import Mudbrick.TestHelper, only: [output: 1]
4+
import Mudbrick.TestHelper, only: [output: 2]
55

66
alias Mudbrick.TextBlock
77
alias Mudbrick.TextBlock.Line
@@ -283,6 +283,8 @@ defmodule Mudbrick.TextBlockTest do
283283
end
284284
end
285285

286+
defp output(f), do: output(f, Mudbrick.TextBlock.Output)
287+
286288
defp operations(ops) do
287289
Enum.map(ops, &Mudbrick.TestHelper.show/1)
288290
end

test/test_helper.exs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@ defmodule Mudbrick.TestHelper do
66
@example_png Path.join(__DIR__, "fixtures/Example.png") |> File.read!()
77

88
alias Mudbrick.Page
9-
alias Mudbrick.TextBlock.Output
109

1110
def show(o) do
1211
Mudbrick.Object.from(o) |> to_string()
@@ -38,7 +37,7 @@ defmodule Mudbrick.TestHelper do
3837
@example_png
3938
end
4039

41-
def output(f) when is_function(f) do
40+
def output(f, output_mod) when is_function(f) do
4241
import Mudbrick
4342

4443
{doc, _contents_obj} =
@@ -65,7 +64,7 @@ defmodule Mudbrick.TestHelper do
6564
}
6665
})
6766

68-
ops = Output.from(block).operations
67+
ops = output_mod.from(block).operations
6968

7069
context
7170
|> Mudbrick.ContentStream.put(operations: ops)

0 commit comments

Comments
 (0)