shadow-cljs-gjs-target

This project implements a build target for shadow-cljs so that Clojurescript can be compiled to Javascript in a form suitable for Gnome Javascript Bindings - Gjs.

Notes

Special syntax for importing builtin modules

Gjs builtin modules can be accessed using a string based namespace syntax - "gjs.<builtin-module-name>". For example, if you want to import the gi.Gtk module, the mapped namespace name should be "gjs.gi.Gtk".

Import syntax mapping

| Javascript | Clojurescript | | ---------- | ------------- | | const Gtk = imports.gi.Gtk; | (require '["gjs.gi.Gtk" :as Gtk]) | | const ByteArray = imports.ByteArray; | (require '["gjs.byteArray" :as ByteArray]) | | const { Gtk, GLib } = imports.gi; | (require '["gjs.gi" :refer [Gtk GLib]]) |

Tutorial

Here's a short tutorial on how to get a simple Gtk app and running with Clojurescript. Note that I am detailing the lowest friction way of installing and using shadow-cljs. Feel free to use lein, boot or deps.edn, if you want so. Look at shadow-cljs documentation to know how to do that.

```clojure (ns gjs-demo (:require [clojure.string :as str] ["gjs.gi.Gtk" :as Gtk] ["gjs.system" :as system]))

(defn ^:export main [& args] (println "Hello from console!") (println "Command line arguments are: " (str/join ", " args)) (let [msg (str "Hello, Gtk + Clojurescript!\ngjs version = " (.-version system))] (Gtk/init nil) (let [win (Gtk/Window.) label (Gtk/Label. #js {:label msg})] (doto win (.add label) (.show_all)) (Gtk/main)))) ```

```clojure ;; shadow-cljs configuration {:source-paths ["src/dev" "src/main" "src/test"]

:dependencies [[titonbarua/shadow-cljs-gjs-target "0.1.0"]]

:builds {:app {:target shadow-cljs-gjs-target.core :output-to "./app.js" :main gjs-demo/main}}} ```

Related resources

Things to TODO:

License

Copyright © 2020 Titon Barua

This program and the accompanying materials are made available under the terms of the Eclipse Public License 2.0 which is available at http://www.eclipse.org/legal/epl-2.0.

This Source Code may also be made available under the following Secondary Licenses when the conditions for such availability set forth in the Eclipse Public License, v. 2.0 are satisfied: GNU General Public License as published by the Free Software Foundation, either version 2 of the License, or (at your option) any later version, with the GNU Classpath Exception which is available at https://www.gnu.org/software/classpath/license.html.