Skip to content

Commit

Permalink
move hide markers to table.clj
Browse files Browse the repository at this point in the history
  • Loading branch information
erdos committed Jun 9, 2024
1 parent ce7cd5a commit 8306f4f
Show file tree
Hide file tree
Showing 4 changed files with 33 additions and 33 deletions.
13 changes: 1 addition & 12 deletions src/stencil/functions.clj
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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)))))
Expand Down
34 changes: 31 additions & 3 deletions src/stencil/postprocess/table.clj
Original file line number Diff line number Diff line change
@@ -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"}))
Expand Down
17 changes: 0 additions & 17 deletions src/stencil/types.clj
Original file line number Diff line number Diff line change
Expand Up @@ -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))
2 changes: 1 addition & 1 deletion test/stencil/infix_test.clj
Original file line number Diff line number Diff line change
@@ -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
Expand Down

0 comments on commit 8306f4f

Please sign in to comment.