A Clojure library designed to provide interoperability with CFML. This library is intended to be used by projects that are loaded into a CFML engine, such as Lucee via FW/1 or cfmljure.
CFML can treat Clojure vectors as arrays (ArrayList variants) but CFML structs are case-insensitive hash maps with strings as keys. This library can convert both CFML structs and Clojure maps into a map-like data structure that is case-insensitive and can accept both keywords and strings as keys. This makes interoperability much easier.
In addition, this library provides a number of useful data coercions: when faced with string inputs via URL and form scope, you often want to robustly convert them to Long
, Double
, or Boolean
. The cfml.coerce
namespace provides ->long
, ->double
, and ->boolean
for this.
The main function here is to-clj-struct
which converts CFML and Clojure (and compatible Java) data structures to a format that can be iterated over, indexed, and dereferenced by both CFML and Clojure.
;; add this Leiningen dependency:
[cfml-interop "0.3.0"]
;; NOTE: REQUIRES Clojure 1.8.0 OR LATER!
;; to use in Clojure:
(ns my.ns
(:require [cfml.interop :as cfml]))
(cfml/to-clj-struct {:a 1 :bC 2 :DeF 3})
;;=> {"A" 1, "BC" 2, "DEF" 3}
// to use in CFML:
// ensure "cfml.interop" is exposed via cfmljure
// convert Clojure data structure to usable CFML data structure:
var data = cfml.interop.to_clj_struct( clj_data );
// now data is usable in CFML!
// convert CFML data structure to usable Clojure data structure:
var data = cfml.interop.to_clj_struct( cfml_data );
// now data is usable in Clojure!
However, this map can still be indexed by keywords or strings.
In addition, as of 0.2.0, this provides ->long
, ->double
, and ->boolean
data coercions in the cfml.coerce
namespace.
Clone this repo and then run:
clj -A:test:runner
- 0.3.next in progress -- update dependencies.
- 0.3.0 -- 2020 Oct 30 -- Handle structs with non-string/non-keyword keys by coercing the key to a string; bumps all dependencies up to latest; confirms that Clojure 1.8 is the minimum.
- 0.2.9 -- 2019 Jul 01 -- Update testing infrastructure; back off to Clojure 1.8 to avoid compiling
clojure.core.specs.alpha
into the JAR. - 0.2.8 -- 2019 Apr 09 -- Support namespaced keys.
- 0.2.7 -- 2019 Feb 25 -- Switch to deps.edn.
- 0.2.6 -- 2019 Feb 25 -- (bad version).
- 0.2.5 -- 2018 Oct 17 -- Update to Clojure 1.10 / Java 8.
- 0.2.4 -- 2017 Jul 18 -- Switch to Boot.
- 0.2.3 -- 2017 Jul 18 -- Minor dependency update; drop nREPL plugin.
- 0.2.2 -- 2016 Jun 28 -- Minor dependency update.
- 0.2.1 -- 2016 Jun 09 -- Update dependencies; test against 1.9.0 (master).
- 0.2.0 -- 2015 Sep 07 -- Move data coercions to
cfml.coerce
namespace (breaking change if you used them in 0.1.2). - 0.1.2 -- 2015 Sep 06 -- Add data coercions.
- 0.1.1 -- 2015 Aug 05 -- Support - / _ translation #1.
- 0.1.0 -- 2015 Aug 04 -- Initial public release.
Copyright © 2015-2024 World Singles Networks llc
Distributed under the Eclipse Public License either version 1.0 or (at your option) any later version.