Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Newer
Older
100644 124 lines (89 sloc) 3.604 kB
2f0d9a8 @lynaghk Update README. Let users load their own rules.
authored
1 /$$
2 | $$
3 /$$$$$$$ | $$ /$$ /$$ /$$
4 /$$_____/ | $$ |__/ | $$ /$$/
5 | $$ | $$ /$$ \ $$$$/
6 | $$ | $$ | $$ >$$ $$
7 | $$$$$$$ | $$ | $$ /$$/\ $$
8 \_______/ |__/ | $$ |__/ \__/
9 /$$ | $$
10 | $$$$$$/ Your code is, like, data, bro.
11 \______/
3f0ad0a @lynaghk Moar cleanup!
authored
12
13
2f0d9a8 @lynaghk Update README. Let users load their own rules.
authored
14 Cljx is a Lein plugin that emits Clojure and ClojureScript code from a single metadata-annotated codebase.
3f0ad0a @lynaghk Moar cleanup!
authored
15
2f0d9a8 @lynaghk Update README. Let users load their own rules.
authored
16 To use it, add it to your `project.clj`:
3f0ad0a @lynaghk Moar cleanup!
authored
17
2f0d9a8 @lynaghk Update README. Let users load their own rules.
authored
18 ```clojure
6cf5550 @cemerick 0.2.0
cemerick authored
19 :plugins [[com.keminglabs/cljx "0.2.0"]]
2f0d9a8 @lynaghk Update README. Let users load their own rules.
authored
20 :cljx {:builds [{:source-paths ["src/cljx"]
21 :output-path ".generated/clj"
22 :rules cljx.rules/clj-rules}
23
24 {:source-paths ["src/cljx"]
25 :output-path ".generated/cljs"
26 :extension "cljs"
72bb09a @jwhitlark Oops. Forgot to update readme.
jwhitlark authored
27 :include-meta true
2f0d9a8 @lynaghk Update README. Let users load their own rules.
authored
28 :rules cljx.rules/cljs-rules}]}
29 ```
30
02d8fe6 @jwhitlark Added "auto" capability, using watchtower to watch for file/directory…
jwhitlark authored
31 Can be run "once" or "auto", in which case it will watch all source-paths for changes to .cljx files. Defaults to "once".
32
7a32c50 @lynaghk Add hook to run cljx before `lein jar`.
authored
33 Add
34
35 ```clojure
36 :hooks [cljx.hooks]
37 ```
38
39 to automatically run cljx before cutting a JAR.
40
713572a @lynaghk Moar README!
authored
41 The included clj and cljs rule sets will remove forms marked with platform-specific metadata and rename protocols as appropriate.
42 E.g., the `.cljx` source containing
43
44 ```clojure
45 ^:clj (ns c2.maths
46 (:use [c2.macros :only [combine-with]]))
47 ^:cljs (ns c2.maths
48 (:use-macros [c2.macros :only [combine-with]]))
49
50 (defn ^:clj sin [x] (Math/sin x))
51 (defn ^:cljs sin [x] (.sin js/Math x))
52
53 (reify
54 clojure.lang.IFn
55 (invoke [_ x] (inc x)))
56 ```
57
023f03f @lynaghk Moar README!
authored
58 will, when run through `cljx.rules/cljs-rules`, yield:
713572a @lynaghk Moar README!
authored
59
60 ```clojure
61 (ns c2.maths
62 (:use-macros [c2.macros :only [combine-with]]))
63
64 (defn sin [x] (.sin js/Math x))
65
66 (reify
67 IFn
68 (invoke [_ x] (inc x)))
69 ```
70
c4bfb43 @cemerick Use eval-in-leiningen to enable usage of rules from anywhere on the c…
cemerick authored
71 The value associated with `:rules` should be a symbol naming a var containing
72 the rules to use for that build. `cljx.rules/cljs-rules` and `cljx.rules/clj-rules`
73 are provided as a convenience, but you can extend those (or replace them entirely).
74 For example, a namespace on your classpath like this defines some rules:
2f0d9a8 @lynaghk Update README. Let users load their own rules.
authored
75
c4bfb43 @cemerick Use eval-in-leiningen to enable usage of rules from anywhere on the c…
cemerick authored
76 ```clojure
77 (ns my.rules
78 (:require [kibit.rules.util :refer (compile-rule defrules)]))
79
80 (defrules rules
81 [(+ ?x 1) (inc ?x)]
82 [(- ?x 1) (dec ?x)])
2f0d9a8 @lynaghk Update README. Let users load their own rules.
authored
83 ```
84
c4bfb43 @cemerick Use eval-in-leiningen to enable usage of rules from anywhere on the c…
cemerick authored
85 Now you can use those rules in a cljx build like so:
023f03f @lynaghk Moar README!
authored
86
c4bfb43 @cemerick Use eval-in-leiningen to enable usage of rules from anywhere on the c…
cemerick authored
87 ```clojure
88 :rules my.rules/rules
023f03f @lynaghk Moar README!
authored
89 ```
90
c4bfb43 @cemerick Use eval-in-leiningen to enable usage of rules from anywhere on the c…
cemerick authored
91 The var's namespace will be automatically loaded by cljx (i.e. no need to do so
92 manually via the `:injections` key in your `project.clj`).
93
2f0d9a8 @lynaghk Update README. Let users load their own rules.
authored
94 Forms that are converted into `:cljx.core/exclude` will be excluded from the output.
c4bfb43 @cemerick Use eval-in-leiningen to enable usage of rules from anywhere on the c…
cemerick authored
95 See [Kibit](http://github.com/jonase/kibit) for more info on writing rules, and
96 [C2](https://github.com/lynaghk/c2) for a project that uses `.cljx` heavily.
2f0d9a8 @lynaghk Update README. Let users load their own rules.
authored
97
98
99 Clojure is a hosted language
100 ----------------------------
101 Cljx does *not* try to hide implementation differences between host platforms.
713572a @lynaghk Moar README!
authored
102 Clojure has ints, floats, longs, &c., ClojureScript has number; Clojure regular expressions act differently than ClojureScript regular expressions, because *they are different*.
2f0d9a8 @lynaghk Update README. Let users load their own rules.
authored
103
104 Cljx only tries to unify Clojure/ClojureScript abstractions when it makes sense.
105 E.g., converting `clojure.lang.IFn` into `IFn` when generating ClojureScript.
1bbdac1 @lynaghk Lein plugin-ify.
authored
106
107
3f0ad0a @lynaghk Moar cleanup!
authored
108 Misc
109 ----
2f0d9a8 @lynaghk Update README. Let users load their own rules.
authored
110 Emacs users, want syntax highlighting?
111 Add to your emacs config: `(add-to-list 'auto-mode-alist '("\\.cljx\\'" . clojure-mode))`.
49a287e @lynaghk Thanks!
authored
112
506059f @lynaghk Add todo.
authored
113 Todo
114 ----
115
116 + CLJS: Remove docstrings from namespaces.
49a287e @lynaghk Thanks!
authored
117
118 Thanks
119 ======
120 @jonase & @ohpauleez for kibit
121 @swannodette for core.logic
506059f @lynaghk Add todo.
authored
122
123
Something went wrong with that request. Please try again.