Skip to content

Commit

Permalink
Adding first modules
Browse files Browse the repository at this point in the history
  • Loading branch information
carlogilmar committed Apr 19, 2024
1 parent b2f3a98 commit 158210d
Show file tree
Hide file tree
Showing 4 changed files with 82 additions and 0 deletions.
7 changes: 7 additions & 0 deletions lib/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
53 changes: 53 additions & 0 deletions lib/d2/backbone.ex
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
defmodule ExPlain.D2.Backbone do

Check warning on line 1 in lib/d2/backbone.ex

View workflow job for this annotation

GitHub Actions / Static Analysis

Modules should have a @moduledoc tag.
def create_diagram(%{
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
14 changes: 14 additions & 0 deletions lib/module_unit.ex
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
defmodule ExPlain.ModuleUnit do

Check warning on line 1 in lib/module_unit.ex

View workflow job for this annotation

GitHub Actions / Static Analysis

Modules should have a @moduledoc tag.
@doc """
Struct for module unit
"""
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 ExPlainTest do
use ExUnit.Case
alias ExPlain.ModuleUnit

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

0 comments on commit 158210d

Please sign in to comment.