Skip to content

Commit bb2f03f

Browse files
committed
move def of Choice tag, Ignorable attr
1 parent f56ca8f commit bb2f03f

File tree

4 files changed

+15
-18
lines changed

4 files changed

+15
-18
lines changed

src/stencil/model/numbering.clj

+1-5
Original file line numberDiff line numberDiff line change
@@ -28,18 +28,14 @@
2828
(defn- gen-abstract-numbering-id []
2929
(str (swap! (:counter2 *numbering*) inc)))
3030

31-
32-
(def ^:private ignorable-tag :xmlns.http%3A%2F%2Fschemas.openxmlformats.org%2Fmarkup-compatibility%2F2006/Ignorable)
33-
34-
3531
(defn -add-extra-elems [evaluated-model extra-elems]
3632
(-> evaluated-model
3733
(update-in [:main :stencil.model/numbering]
3834
(fn [nr#]
3935
(if (:stencil.model/path nr#)
4036
(dissoc nr# :source-file)
4137
(assoc nr#
42-
:parsed {:tag ooxml/tag-numbering :attrs {ignorable-tag ""} :content []}
38+
:parsed {:tag ooxml/tag-numbering :attrs {ooxml/ignorable ""} :content []}
4339
:stencil.model/path "word/numbering.xml"))))
4440
;; TODO: make it conditional
4541
(assoc-in [:content-types :parsed :stencil.model.content-types/override "/word/numbering.xml"]

src/stencil/ooxml.clj

+7-1
Original file line numberDiff line numberDiff line change
@@ -131,4 +131,10 @@
131131
;; drawing, binary large image or picture
132132
(def blip :xmlns.http%3A%2F%2Fschemas.openxmlformats.org%2Fdrawingml%2F2006%2Fmain/blip)
133133
;; hyperlinks
134-
(def hyperlink :xmlns.http%3A%2F%2Fschemas.openxmlformats.org%2Fwordprocessingml%2F2006%2Fmain/hyperlink)
134+
(def hyperlink :xmlns.http%3A%2F%2Fschemas.openxmlformats.org%2Fwordprocessingml%2F2006%2Fmain/hyperlink)
135+
136+
;; OOXML attribute holds list of ns aliases
137+
(def ignorable :xmlns.http%3A%2F%2Fschemas.openxmlformats.org%2Fmarkup-compatibility%2F2006/Ignorable)
138+
139+
;; OOXML tag, has Requires attribute which holds list of ns aliases
140+
(def choice :xmlns.http%3A%2F%2Fschemas.openxmlformats.org%2Fmarkup-compatibility%2F2006/Choice)

src/stencil/postprocess/ignored_tag.clj

+4-6
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,6 @@
66
[clojure.string :as s]
77
[stencil.ooxml :as ooxml]))
88

9-
(def ^:private ignorable-tag :xmlns.http%3A%2F%2Fschemas.openxmlformats.org%2Fmarkup-compatibility%2F2006/Ignorable)
10-
(def ^:private choice-tag :xmlns.http%3A%2F%2Fschemas.openxmlformats.org%2Fmarkup-compatibility%2F2006/Choice)
119

1210
;; like clojure.walk/postwalk but keeps metadata and calls fn only on nodes
1311
(defn- postwalk-xml [f xml-tree]
@@ -27,7 +25,7 @@
2725
"Updates the Requires attribute of a Choice tag with the fn"
2826
[elem f]
2927
(assert (ifn? f))
30-
(if (= (:tag elem) choice-tag)
28+
(if (= (:tag elem) ooxml/choice)
3129
(update-in elem [:attrs :Requires] f)
3230
elem))
3331

@@ -40,14 +38,14 @@
4038

4139
;; first call this
4240
(defn map-ignored-attr
43-
"Replaces values in ignorable-tag and requires-tag attributes to
41+
"Replaces values in Ignorable and Requires attributes to
4442
the namespace names they are aliased by."
4543
[xml-tree]
4644
(postwalk-xml
4745
(fn [form]
4846
(let [p->url (get-in (meta form) [:clojure.data.xml/nss :p->u])]
4947
(-> form
50-
(update-if-present [:attrs ignorable-tag] (partial map-str p->url))
48+
(update-if-present [:attrs ooxml/ignorable] (partial map-str p->url))
5149
(update-choice-requires (partial map-str p->url)))))
5250
xml-tree))
5351

@@ -67,7 +65,7 @@
6765
(when (contains? ooxml/default-aliases ns)
6866
(find! ns)))
6967
(-> form
70-
(update-if-present [:attrs ignorable-tag] (partial map-str find!))
68+
(update-if-present [:attrs ooxml/ignorable] (partial map-str find!))
7169
(update-choice-requires (partial map-str find!))))
7270
xml-tree)
7371
@found)))

test/stencil/ignored_tag_test.clj

+3-6
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,9 @@
11
(ns stencil.ignored-tag-test
22
(:require [clojure.data.xml :as xml]
3-
[clojure.java.io :as io]
4-
[clojure.walk :as walk]
5-
[clojure.test :refer [deftest is are testing]]
3+
[clojure.test :refer [deftest is testing]]
64
[stencil.tokenizer :as tokenizer]
75
[stencil.merger :as merger]
6+
[stencil.ooxml :as ooxml]
87
[stencil.postprocess.ignored-tag :refer :all]))
98

109
;; make all private maps public!
@@ -36,9 +35,7 @@
3635
(java.io.StringReader.) (merger/parse-to-tokens-seq) (tokenizer/tokens-seq->document)
3736
(clear-all-metas) (unmap-ignored-attr) (xml/emit-str) (xml/parse-str)
3837
(as-> *
39-
(let [ignorable-value
40-
(-> * :content first :attrs
41-
:xmlns.http%3A%2F%2Fschemas.openxmlformats.org%2Fmarkup-compatibility%2F2006/Ignorable)
38+
(let [ignorable-value (-> * :content first :attrs ooxml/ignorable)
4239
ignorable-ns (-> * meta :clojure.data.xml/nss :p->u (get ignorable-value))]
4340
(is (not (empty? ignorable-value)))
4441
(is (= "ns2" ignorable-ns)))))))

0 commit comments

Comments
 (0)