-
-
Notifications
You must be signed in to change notification settings - Fork 160
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Move formatting code to formatting namespace
- Loading branch information
1 parent
ad4007a
commit e6500a6
Showing
2 changed files
with
27 additions
and
25 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,27 @@ | ||
(ns formatting | ||
(:require [cljfmt.core :refer [reformat-string]])) | ||
(:require [cljfmt.core :refer [reformat-string]] | ||
[clojure.string :as str]) | ||
(:import [com.github.jknack.handlebars Formatter])) | ||
|
||
(defn format-code [code] | ||
(reformat-string code)) | ||
|
||
(defn format-string [s _next] | ||
(str "\"" (str/escape s char-escape-string) "\"")) | ||
|
||
(defn format-collection [coll next open close] | ||
(let [formatted-elements (str/join " " (map #(. next format %) coll))] | ||
(str open formatted-elements close))) | ||
|
||
(defn format-list [coll next] | ||
(format-collection coll next "'(" ")")) | ||
|
||
(defn format-set [coll next] | ||
(format-collection coll next "#{" "}")) | ||
|
||
(defn formatter [test conv] | ||
(proxy [Formatter] [] | ||
(format [value next] | ||
(if (test value) | ||
(conv value next) | ||
(. next format value))))) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters