Skip to content

Instantly share code, notes, and snippets.

@jolby
Created August 2, 2011 00:12
Show Gist options
  • Save jolby/1119294 to your computer and use it in GitHub Desktop.
Save jolby/1119294 to your computer and use it in GitHub Desktop.
Clojurescript on Appcelerator Titanium
(ns tiexample.core)
(defn ^{:export dbg} dbg [s]
(js* "Titanium.API.debug(~{s})"))
;;stolen from another gist I saw
(defn make-js-map
"makes a javascript map from a clojure one"
[cljmap]
(let [out (js-obj)]
(doall (map #(aset out
(name (first %))
(if (map? (second %))
(make-js-map (second %))
(second %)))
cljmap))
;;(dbg (str "js map: " (js* "JSON.stringify(~{})" out)))
out))
(defn ^{:export create-win} create-win [props]
(let [jsprops (make-js-map props)]
(js* "Titanium.UI.createWindow(~{jsprops})")))
(defn ^{:export create-tab} create-tab [props]
(let [jsprops (make-js-map props)]
(js* "Titanium.UI.createTab(~{jsprops})")))
(defn ^{:export create-tab-group} create-tab-group [props]
(let [jsprops (make-js-map props)]
(js* "Titanium.UI.createTabGroup(~{jsprops})")))
(defn ^{:export create-label} create-label [props]
(let [jsprops (make-js-map props)]
(js* "Titanium.UI.createLabel(~{jsprops})")))
(defn ^{:export create-tab-win} create-tab-win [win-title label-text]
(let [win (create-win {:title win-title :backgroundColor "#fff"})
label (create-label {:color "#999"
:text label-text
:font {:fontSize 20 :fontFamily "Helvetica Neue"}
:textAlign "center"
:width "auto"})]
(.add win label)
win))
(defn ^{:export create-example-tab} create-example-tab
[tab-title tab-img win-title label-text]
(let [win (create-tab-win win-title label-text)
tab (create-tab {:icon tab-img :title tab-title :window win})]
tab))
(defn ^{:export create-app-ui} create-app-ui []
(let [tab-group (create-tab-group {})
win1 (create-tab-win "Win 1 Title" "Witness the power of my fully armed and operational Titanium Clojure App")
tab1 (create-tab {:icon "KS_nav_views.png" :title "Tab 1" :window win1})
win2 (create-tab-win "Win 2 Title" "Win 2 Label")
tab2 (create-tab {:icon "KS_nav_ui.png" :title "Tab 2" :window win2})]
(.addTab tab-group tab1)
(.addTab tab-group tab2)
(comment
(dbg (str (js* "JSON.stringify(~{})" tab-group)))
(dbg (str (js* "JSON.stringify(~{})" tab1)))
(dbg (str (js* "JSON.stringify(~{})" tab2)))
(dbg (str (js* "JSON.stringify(~{})" win1)))
(dbg (str (js* "JSON.stringify(~{})" win2))))
(dbg "Starting Titanium Clojure App...")
(. tab-group (open))))
(create-app-ui)
@r4vi
Copy link

r4vi commented Nov 9, 2013

Interesting, did you make a 'real' app with this or is this where the experiment ended?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment