-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #2 from visualpartnership/explain_elixir_module
Adding first modules
- Loading branch information
Showing
4 changed files
with
89 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |