Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix loop numbering #145

Draft
wants to merge 10 commits into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
fix: numberings in loops are reset
  • Loading branch information
erdos committed Dec 16, 2022
commit 0a74291cae20b3b729b485b487a36eec40680c8b
9 changes: 9 additions & 0 deletions src/stencil/model.clj
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
(:require [clojure.data.xml :as xml]
[clojure.java.io :as io :refer [file]]
[stencil.eval :as eval]
[stencil.ooxml :as ooxml]
[stencil.merger :as merger]
[stencil.model.numbering :as numbering]
[stencil.types :refer [->FragmentInvoke ->ReplaceImage]]
Expand Down Expand Up @@ -52,10 +53,18 @@
{:source-file cts
::path (.getName cts)})

(defn- add-unique-index
"Annotates some elements with an unique id.
These elements need special care when rendering duplicates them.
For example, numberings need to be reset to start from 1 again."
[elem]
(when (= (:open+close elem) ooxml/attr-numId)
(update elem :attrs assoc ::unique (gensym "uniq"))))

(defn ->exec [xml-streamable]
(with-open [stream (io/input-stream xml-streamable)]
(-> (merger/parse-to-tokens-seq stream)
(->> (map (some-fn add-unique-index identity)))
(cleanup/process)
(select-keys [:variables :dynamic? :executable :fragments]))))

Expand Down
18 changes: 18 additions & 0 deletions src/stencil/postprocess/list_ref.clj
Original file line number Diff line number Diff line change
Expand Up @@ -307,3 +307,21 @@
(let [xml-tree (enrich-dirty-refs-meta xml-tree)
bookmark-meta (get-bookmark-meta xml-tree)]
(rerender-refs xml-tree bookmark-meta)))

;; finds nodes with unique id and if these are not unique anymore, replace the numbering id with a duplicate numbering definition
(defn fix-numbering-reset [xml-tree]
(let [found (atom #{})
last-val (atom nil)
edit-attrs (fn [attrs]
(let [old-id (ooxml/val attrs)
unq-id (:stencil.model/unique attrs)
new-id old-id] ;; TODO
;; ha az unique id benne van a found set-ben
;; akkor uj value-t szamolunk es beallitjuk a last-val-t.
;; egyebkent ha a last-val nem ugyanaz mint a mostani, akkor beallitjuk a last val-t (?)
(-> attrs
(dissoc :stencil.model/unique)
(assoc ooxml/val new-id))))]
;; find nodes with unique id in attrs
(dfs-walk-xml-node xml-tree (fn [n] (and (map? n) (:stencil.model/unique (:attrs n))))
(fn [n] (zip/edit n update :attrs edit-attrs)))))
2 changes: 2 additions & 0 deletions src/stencil/tree_postprocess.clj
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@

#'fix-list-dirty-refs

#'fix-numbering-reset

#'replace-images

;; call this first. includes fragments and evaluates them too.
Expand Down