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.2.1"]
;; NOTE: REQUIRES Clojure 1.7.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:
boot aot expectations
cfml.coerce
namespace (breaking change if you used them in 0.1.2).Copyright © 2015-2017 World Singles llc
Distributed under the Eclipse Public License either version 1.0 or (at your option) any later version.
Can you improve this documentation?Edit on GitHub
cljdoc is a website building & hosting documentation for Clojure/Script libraries
× close