diff --git a/components/contextmapper/src/dinodoc/contextmapper.clj b/components/contextmapper/src/dinodoc/contextmapper.clj index a28bf2f..f61c465 100644 --- a/components/contextmapper/src/dinodoc/contextmapper.clj +++ b/components/contextmapper/src/dinodoc/contextmapper.clj @@ -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)) diff --git a/components/contextmapper/src/dinodoc/contextmapper/impl.clj b/components/contextmapper/src/dinodoc/contextmapper/impl.clj index 53db57a..82d70b5 100644 --- a/components/contextmapper/src/dinodoc/contextmapper/impl.clj +++ b/components/contextmapper/src/dinodoc/contextmapper/impl.clj @@ -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 diff --git a/examples/contextmapper/README.md b/examples/contextmapper/README.md index 03f1f86..14acc27 100644 --- a/examples/contextmapper/README.md +++ b/examples/contextmapper/README.md @@ -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 diff --git a/test/src/dinodoc/api_test.clj b/test/src/dinodoc/api_test.clj index 092746a..64349f0 100644 --- a/test/src/dinodoc/api_test.clj +++ b/test/src/dinodoc/api_test.clj @@ -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] @@ -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" @@ -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))))