Skip to content

Commit

Permalink
Merge pull request #2 from visualpartnership/explain_elixir_module
Browse files Browse the repository at this point in the history
Adding first modules
  • Loading branch information
carlogilmar authored Apr 28, 2024
2 parents b2f3a98 + f0c9df8 commit c2dddaf
Show file tree
Hide file tree
Showing 4 changed files with 89 additions and 0 deletions.
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

0 comments on commit c2dddaf

Please sign in to comment.