diff --git a/src/stencil/functions.clj b/src/stencil/functions.clj index 5f3eaa71..f4c45a42 100644 --- a/src/stencil/functions.clj +++ b/src/stencil/functions.clj @@ -1,8 +1,6 @@ (ns stencil.functions "Function definitions" (:require [clojure.string] - [stencil.ooxml :as ooxml] - [stencil.types :refer [->FragmentInvoke]] [stencil.util :refer [fail find-first]])) (set! *warn-on-reflection* true) @@ -102,8 +100,3 @@ (defmethod call-fn "replace" [_ text pattern replacement] (clojure.string/replace (str text) (str pattern) (str replacement))) - -;; inserts a page break at the current run. -(let [br {:tag ooxml/br :attrs {ooxml/type "page"}} - page-break (->FragmentInvoke {:frag-evaled-parts [br]})] - (defmethod call-fn "pageBreak" [_] page-break)) diff --git a/src/stencil/grammar.clj b/src/stencil/grammar.clj index 20d0aa34..223deccd 100644 --- a/src/stencil/grammar.clj +++ b/src/stencil/grammar.clj @@ -68,7 +68,7 @@ dotted (mapping (all (guarded #{:dot}) iden) (comp name second)) bracketed (mapping (all (guarded #{:open-bracket}) expression (guarded #{:close-bracket})) second) args (mapping (optional (chained (all expression) (all (guarded #{:comma}) expression) into)) - (fn [x] (take-nth 2 x))) + (partial take-nth 2)) args-suffix (parenthesed args) iden-or-fncall (mapping (all iden (optional args-suffix)) (fn [[id xs]] (if xs (list* :fncall id xs) id))) diff --git a/src/stencil/log.clj b/src/stencil/log.clj index a8954f9d..e53d99b3 100644 --- a/src/stencil/log.clj +++ b/src/stencil/log.clj @@ -20,10 +20,10 @@ (list 'to-array) (list '. (list 'stencil.log/get-logger (str *ns*)) '~level msg#))))) -(declare trace debug info warn error) - (def-log-level trace) (def-log-level debug) (def-log-level info) (def-log-level warn) (def-log-level error) + +(ns-unmap *ns* 'def-log-level) \ No newline at end of file diff --git a/src/stencil/model.clj b/src/stencil/model.clj index ebf7899b..9a9bf31b 100644 --- a/src/stencil/model.clj +++ b/src/stencil/model.clj @@ -7,7 +7,6 @@ [stencil.eval :as eval] [stencil.infix :refer [eval-rpn]] [stencil.merger :as merger] - [stencil.types :refer [->FragmentInvoke]] [stencil.util :refer [unlazy-tree]] [stencil.model.common :refer [->xml-writer resource-copier]] [stencil.ooxml :as ooxml] @@ -206,4 +205,4 @@ (map (partial style/xml-rename-style-ids style-ids-rename)) (doall))] (run! relations/add-extra-file! relation-ids-rename) - [{:text (->FragmentInvoke {:frag-evaled-parts evaled-parts})}])) + [{:text (fragments/->FragmentInvoke {:frag-evaled-parts evaled-parts})}])) diff --git a/src/stencil/model/fragments.clj b/src/stencil/model/fragments.clj index 1e98d2df..4b834c70 100644 --- a/src/stencil/model/fragments.clj +++ b/src/stencil/model/fragments.clj @@ -1,5 +1,9 @@ (ns stencil.model.fragments - (:require [stencil.util :refer [eval-exception]])) + (:require [stencil.util :refer [eval-exception]] + [stencil.functions :refer [call-fn]] + [stencil.types :refer [ControlMarker]] + [stencil.ooxml :as ooxml] + [clojure.data.xml :as xml])) ;; all insertable fragments. map of id to frag def. (def ^:dynamic *all-fragments* nil) @@ -24,3 +28,17 @@ [~body @*inserted-fragments*])] (swap! *inserted-fragments* into fragments#) [result# fragments#])) + +;; Invocation of a fragment by name +(defrecord FragmentInvoke [result] ControlMarker) + +;; custom XML content +(defmethod call-fn "xml" [_ content] + (assert (string? content)) + (let [content (:content (xml/parse-str (str "" content "")))] + (->FragmentInvoke {:frag-evaled-parts content}))) + +;; inserts a page break at the current run. +(let [br {:tag ooxml/br :attrs {ooxml/type "page"}} + page-break (->FragmentInvoke {:frag-evaled-parts [br]})] + (defmethod call-fn "pageBreak" [_] page-break)) diff --git a/src/stencil/postprocess/fragments.clj b/src/stencil/postprocess/fragments.clj index 4876d06f..f6482372 100644 --- a/src/stencil/postprocess/fragments.clj +++ b/src/stencil/postprocess/fragments.clj @@ -1,14 +1,12 @@ (ns stencil.postprocess.fragments "Inserts contents of fragments." - (:import [stencil.types FragmentInvoke]) + (:require [stencil.model.fragments]) + (:import [stencil.model.fragments FragmentInvoke]) (:require [clojure.zip :as zip] - [clojure.data.xml :as xml] - [stencil.types :refer [->FragmentInvoke control?]] + [stencil.types :refer [control?]] [stencil.ooxml :as ooxml] - [stencil.functions :refer [call-fn]] [stencil.util :refer :all])) - (defn- remove+up "Removes current node and moves pointer to parent node." [loc] @@ -167,9 +165,3 @@ "Walks the tree (Depth First) and evaluates FragmentInvoke objects." [xml-tree] (dfs-walk-xml-node xml-tree (partial instance? FragmentInvoke) unpack-fragment)) - -;; custom XML content -(defmethod call-fn "xml" [_ content] - (assert (string? content)) - (let [content (:content (xml/parse-str (str "" content "")))] - (->FragmentInvoke {:frag-evaled-parts content}))) diff --git a/src/stencil/types.clj b/src/stencil/types.clj index 944321a2..1a8af653 100644 --- a/src/stencil/types.clj +++ b/src/stencil/types.clj @@ -7,7 +7,4 @@ (defprotocol ControlMarker) -;; Invocation of a fragment by name -(defrecord FragmentInvoke [result] ControlMarker) - (defn control? [x] (satisfies? ControlMarker x))