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
Prev Previous commit
Next Next commit
wip
  • Loading branch information
erdos committed Dec 25, 2022
commit 23d0a3504f7fcd07362e1a4b24bcbf5044d8f9ab
17 changes: 0 additions & 17 deletions src/stencil/cleanup.clj
Original file line number Diff line number Diff line change
Expand Up @@ -211,22 +211,6 @@
:when (= :cmd/include (:cmd item))]
(:name item))))

;; Calculate for each numbering how many for loops deep it is.
(defn- numid->depth [ast]
(let [cache (volatile! {})]
;; visit all nodes and set up a cache.
(doseq [e ast]
((fn f [d node]
(assert (map? node))
(when (= ooxml/attr-numId (:open+close node))
(vswap! cache update (ooxml/val (:attrs node)) (fnil conj #{}) d))
(let [d (if (= :for (:cmd node)) (cons (gensym "x") d) d)]
(doseq [block (::blocks node)
b (::children block)]
(f d b)))) () e))
(into {} (for [[k v] @cache]
[k (count (take-while true? (apply map = (map reverse v))))]))))

;; add ::depth to ooxml/numId elements
(defn- ast-numbering-depths [ast]
(let [numid->paths (volatile! {})
Expand Down Expand Up @@ -263,7 +247,6 @@
executable (mapv control-ast-normalize (annotate-environments ast))]
{:variables (find-variables ast)
:fragments (find-fragments ast)
:num-depth (numid->depth ast)
:dynamic? (boolean (some :cmd executable))
:executable executable}))

Expand Down
10 changes: 0 additions & 10 deletions src/stencil/model.clj
Original file line number Diff line number Diff line change
Expand Up @@ -53,19 +53,9 @@
{: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