Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adding first modules #2

Merged
merged 4 commits into from
Apr 28, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
59 changes: 59 additions & 0 deletions lib/d2/backbone.ex
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
defmodule ExPlain.D2.Backbone do
@moduledoc """
Module to create backbone diagram
"""
alias ExPlain.Reader.ModuleUnit

@spec create_diagram(ModuleUnit.t()) :: String.t()
def create_diagram(%ModuleUnit{
name: module_name,
public_functions: public_functions,
private_functions: private_functions
}) do
classes = get_backbone_class()
header = get_header_title(module_name)
public_functions_boxes = get_public_functions_boxes(public_functions)
private_functions_boxes = get_private_functions_boxes(private_functions)

classes <> header <> public_functions_boxes <> private_functions_boxes
end

defp get_public_functions_boxes(public_functions) do
for fun <- public_functions, into: "", do: "#{fun}.class: public \n"
end

defp get_private_functions_boxes(private_functions) do
for fun <- private_functions, into: "", do: "#{fun}.class: private\n"
end

defp get_header_title(module_name) do
"""
explanation: |md
# #{module_name}
|
grid-columns: 3
"""
end

defp get_backbone_class do
"""
classes: {
public: {
style: {
stroke-width: 0
fill: "#85b4ff"
shadow: true
border-radius: 5
}
}

private: {
style: {
fill: "#fff585"
stroke: "#F69E03"
}
}
}
"""
end
end
7 changes: 7 additions & 0 deletions lib/d2/d2.ex
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
defmodule ExPlain.D2 do
@moduledoc """
Module to convert data into D2 diagrams
"""

### ExPlain Diagram I Module backbone diagram
end
15 changes: 15 additions & 0 deletions lib/reader/module_unit.ex
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
defmodule ExPlain.Reader.ModuleUnit do
@moduledoc """
Struct for module unit
"""
@type t() :: %__MODULE__{}
defstruct [:name, :public_functions, :private_functions]

def new(name, public_functions \\ [], private_functions \\ []) do
%__MODULE__{
name: name,
public_functions: public_functions,
private_functions: private_functions
}
end
end
8 changes: 8 additions & 0 deletions test/module_unit_test.exs
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
defmodule ExPlain.Reader.ModuleUnitTest do
use ExUnit.Case
alias ExPlain.Reader.ModuleUnit

test "create a module unit struct" do
assert %ModuleUnit{name: "MyModule"} = ModuleUnit.new("MyModule")
end
end