Skip to content

Commit

Permalink
implement contextmapper linking
Browse files Browse the repository at this point in the history
  • Loading branch information
dundalek committed Apr 24, 2024
1 parent 6c9abb2 commit 0641d03
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 14 deletions.
17 changes: 10 additions & 7 deletions components/contextmapper/src/dinodoc/contextmapper.clj
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,17 @@
[dinodoc.contextmapper.impl :as impl]
[dinodoc.generator :as generator]))

(deftype ContextMapperGenerator [opts]
(deftype ContextMapperGenerator [opts ^:volatile-mutable jmodel ^:volatile-mutable index]
generator/Generator
(prepare-index [_])
(resolve-link [_ target])
(generate [_ {:keys [output-path]}]
(prepare-index [_]
(let [{:keys [model-file]} opts]
(impl/generate {:model-file model-file
:output-path output-path}))))
(set! jmodel (impl/load-model model-file))
(set! index (impl/build-index jmodel))))
(resolve-link [_ target]
(get index target))
(generate [_ {:keys [output-path]}]
(impl/render-model {:jmodel jmodel
:output-path output-path})))

(defn make-generator [opts]
(->ContextMapperGenerator opts))
(->ContextMapperGenerator opts nil nil))
11 changes: 7 additions & 4 deletions components/contextmapper/src/dinodoc/contextmapper/impl.clj
Original file line number Diff line number Diff line change
Expand Up @@ -201,10 +201,13 @@
(when (fs/directory? (str output-path "/contexts"))
(spit (str output-path "/contexts/_category_.json") "{\"position\":2,\"label\":\"Contexts\"}"))))

(defn generate [{:keys [model-file output-path]}]
(let [jmodel (load-model model-file)]
(render-model {:jmodel jmodel
:output-path output-path})))
(defn build-index [jmodel]
(let [model (j/from-java jmodel)]
(->> (concat (->> (bounded-contexts-without-teams model)
(map (juxt :name bounded-context-path)))
(->> (:domains model)
(map (juxt :name domain-path))))
(into {}))))

(comment
(do
Expand Down
1 change: 1 addition & 0 deletions examples/contextmapper/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ Example of rendering documentation for Domain Driven Design (DDD) model using [C
defined [CML](https://contextmapper.org/docs/language-reference/) model.

See the rendered [example](https://dinodoc.pages.dev/examples/contextmapper/insurance-map/).
Example of linking to a specific domain [[InsuranceDomain]] or a bounded context [[RiskManagementContext]].

### Considerations

Expand Down
14 changes: 11 additions & 3 deletions test/src/dinodoc/api_test.clj
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
[clojure.test :refer [deftest is testing]]
[dinodoc.api :as dinodoc]
[dinodoc.approval-helpers :as approval]
[dinodoc.contextmapper :as contextmapper]
[dinodoc.fs-helpers :as fsh :refer [fsdata with-temp-dir]]
[dinodoc.impl.fs :as fsi]
[dinodoc.impl.javadoc :as javadoc]
Expand Down Expand Up @@ -500,7 +501,9 @@
(str "- java: [[demo.Greeter.greet]]\n"
"- rust: [[example::greeting::greet]]\n"
"- dbschema: [[Album]]\n"
"- namespaced dbschema: [[chinook:Album]]\n"))
"- namespaced dbschema: [[chinook:Album]]\n"
"- contextmapper domain: [[DomainA]]\n"
"- contextmapper context: [[ContextB]]\n"))
(let [output-path (str dir "/docs")
_ (dinodoc/generate {:output-path output-path
:github/repo "repo"
Expand All @@ -518,12 +521,17 @@
:generator (tbls/make-generator
{:dsn (str "sqlite:" (fs/absolutize "examples/dbschema/chinook/ChinookDatabase/DataSources/Chinook_Sqlite.sqlite"))
:title "_REPLACED_TITLE_SENTINEL_"
:UNSTABLE_prefix "chinook"})}]})
:UNSTABLE_prefix "chinook"})}
{:output-path "contextmapper"
:generator (contextmapper/make-generator
{:model-file "components/contextmapper/test/resources/example.cml"})}]})
data (fsdata output-path)]
(is (= ["- java: [`demo.Greeter.greet`](pathname://./javadoc/demo/Greeter.html#greet(java.lang.String))"
"- rust: [`example::greeting::greet`](pathname://./rustdoc/example/greeting/fn.greet.html)"
"- dbschema: [`Album`](./dbschema/Album.md)"
"- namespaced dbschema: [`chinook:Album`](./dbschema/Album.md)"]
"- namespaced dbschema: [`chinook:Album`](./dbschema/Album.md)"
"- contextmapper domain: [`DomainA`](./contextmapper/domains/DomainA/)"
"- contextmapper context: [`ContextB`](./contextmapper/contexts/ContextB/)"]
(-> (get-in data ["index.md"])
(naively-strip-front-matter)
(str/split-lines))))
Expand Down

0 comments on commit 0641d03

Please sign in to comment.