From 8306f4f17091490901e7da75df33b8deb2603ad9 Mon Sep 17 00:00:00 2001 From: janos erdos Date: Sun, 9 Jun 2024 11:15:09 +0200 Subject: [PATCH] move hide markers to table.clj --- src/stencil/functions.clj | 13 +----------- src/stencil/postprocess/table.clj | 34 ++++++++++++++++++++++++++++--- src/stencil/types.clj | 17 ---------------- test/stencil/infix_test.clj | 2 +- 4 files changed, 33 insertions(+), 33 deletions(-) diff --git a/src/stencil/functions.clj b/src/stencil/functions.clj index 5cc00d90..5f3eaa71 100644 --- a/src/stencil/functions.clj +++ b/src/stencil/functions.clj @@ -2,7 +2,7 @@ "Function definitions" (:require [clojure.string] [stencil.ooxml :as ooxml] - [stencil.types :refer [->HideTableColumnMarker ->HideTableRowMarker ->FragmentInvoke]] + [stencil.types :refer [->FragmentInvoke]] [stencil.util :refer [fail find-first]])) (set! *warn-on-reflection* true) @@ -74,17 +74,6 @@ (defmethod call-fn "list" [_ & elements] (vec elements)) -(defmethod call-fn "hideColumn" [_ & args] - (case (first args) - ("cut") (->HideTableColumnMarker :cut) - ("resize-last" "resizeLast" "resize_last") (->HideTableColumnMarker :resize-last) - ("resize-first" "resizeFirst resize_first") (->HideTableColumnMarker :resize-first) - ("rational") (->HideTableColumnMarker :rational) - ;; default - (->HideTableColumnMarker))) - -(defmethod call-fn "hideRow" [_] (->HideTableRowMarker)) - (defn- lookup [column data] (second (or (find data column) (find data (keyword column))))) diff --git a/src/stencil/postprocess/table.clj b/src/stencil/postprocess/table.clj index 47039e1d..fea03eb6 100644 --- a/src/stencil/postprocess/table.clj +++ b/src/stencil/postprocess/table.clj @@ -1,13 +1,41 @@ (ns stencil.postprocess.table "XML fa utofeldolgozasat vegzo kod." (:require [clojure.zip :as zip] + [stencil.functions :refer [call-fn]] [stencil.ooxml :as ooxml] - [stencil.types :refer :all] - [stencil.util :refer :all])) + [stencil.types :refer [ControlMarker]] + [stencil.util :refer [find-first find-last fixpt iterations ->int find-first-in-tree xml-zip zipper?]])) (set! *warn-on-reflection* true) -;; az ennel keskenyebb oszlopokat kidobjuk! +(def column-resize-modes #{:resize-first :resize-last :rational :cut}) + +;; Tells if a table column should be hidden in a postprocess step. +(defrecord HideTableColumnMarker [columns-resize] ControlMarker) +(defn hide-table-column-marker? [x] (instance? HideTableColumnMarker x)) + +#_{:clj-kondo/ignore [:redefined-var]} +(defn ->HideTableColumnMarker + ([] (HideTableColumnMarker. :cut)) + ([x] (assert (column-resize-modes x)) + (HideTableColumnMarker. x))) + +;; Tells if a table row should be hidden in a postprocess step. +(defrecord HideTableRowMarker [] ControlMarker) +(defn hide-table-row-marker? [x] (instance? HideTableRowMarker x)) + +(defmethod call-fn "hideColumn" [_ & args] + (case (first args) + ("cut") (->HideTableColumnMarker :cut) + ("resize-last" "resizeLast" "resize_last") (->HideTableColumnMarker :resize-last) + ("resize-first" "resizeFirst resize_first") (->HideTableColumnMarker :resize-first) + ("rational") (->HideTableColumnMarker :rational) + ;; default + (->HideTableColumnMarker))) + +(defmethod call-fn "hideRow" [_] (->HideTableRowMarker)) + +;; columns narrower that this are goig to be removed (def min-col-width 20) (defn- loc-cell? [loc] (some-> loc zip/node :tag name #{"tc"})) diff --git a/src/stencil/types.clj b/src/stencil/types.clj index eb10bcf3..944321a2 100644 --- a/src/stencil/types.clj +++ b/src/stencil/types.clj @@ -10,21 +10,4 @@ ;; Invocation of a fragment by name (defrecord FragmentInvoke [result] ControlMarker) -;; Tells if a table column should be hidden in a postprocess step. -(defrecord HideTableColumnMarker [columns-resize] ControlMarker) - -(def column-resize-modes #{:resize-first :resize-last :rational :cut}) - -#_{:clj-kondo/ignore [:redefined-var]} -(defn ->HideTableColumnMarker - ([] (HideTableColumnMarker. :cut)) - ([x] (assert (column-resize-modes x)) - (HideTableColumnMarker. x))) - -;; Tells if a table row should be hidden in a postprocess step. -(defrecord HideTableRowMarker [] ControlMarker) - -(defn hide-table-column-marker? [x] (instance? HideTableColumnMarker x)) -(defn hide-table-row-marker? [x] (instance? HideTableRowMarker x)) - (defn control? [x] (satisfies? ControlMarker x)) diff --git a/test/stencil/infix_test.clj b/test/stencil/infix_test.clj index f259dd0c..ee41e6fe 100644 --- a/test/stencil/infix_test.clj +++ b/test/stencil/infix_test.clj @@ -1,7 +1,7 @@ (ns stencil.infix-test (:import [clojure.lang ExceptionInfo]) (:require [stencil.infix :as infix] - [stencil.types :refer [hide-table-column-marker?]] + [stencil.postprocess.table :refer [hide-table-column-marker?]] [clojure.test :refer [deftest testing is are]])) (defn- run