From 158210d630e63db1336d718dad951799ad7e5ab7 Mon Sep 17 00:00:00 2001 From: Carlo Gilmar Date: Fri, 19 Apr 2024 13:03:02 -0600 Subject: [PATCH] Adding first modules --- lib/d2.ex | 7 ++++++ lib/d2/backbone.ex | 53 +++++++++++++++++++++++++++++++++++++++ lib/module_unit.ex | 14 +++++++++++ test/module_unit_test.exs | 8 ++++++ 4 files changed, 82 insertions(+) create mode 100644 lib/d2.ex create mode 100644 lib/d2/backbone.ex create mode 100644 lib/module_unit.ex create mode 100644 test/module_unit_test.exs diff --git a/lib/d2.ex b/lib/d2.ex new file mode 100644 index 0000000..47f95a2 --- /dev/null +++ b/lib/d2.ex @@ -0,0 +1,7 @@ +defmodule ExPlain.D2 do + @moduledoc """ + Module to convert data into D2 diagrams + """ + + ### ExPlain Diagram I Module backbone diagram +end diff --git a/lib/d2/backbone.ex b/lib/d2/backbone.ex new file mode 100644 index 0000000..128af2d --- /dev/null +++ b/lib/d2/backbone.ex @@ -0,0 +1,53 @@ +defmodule ExPlain.D2.Backbone do + 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 diff --git a/lib/module_unit.ex b/lib/module_unit.ex new file mode 100644 index 0000000..f0dce21 --- /dev/null +++ b/lib/module_unit.ex @@ -0,0 +1,14 @@ +defmodule ExPlain.ModuleUnit do + @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 diff --git a/test/module_unit_test.exs b/test/module_unit_test.exs new file mode 100644 index 0000000..a4f89c0 --- /dev/null +++ b/test/module_unit_test.exs @@ -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