Permalink
Browse files

Initial commit.

  • Loading branch information...
0 parents commit 6ed070da07c92bbfb819cbf3e0f8db3e76169fb0 @technomancy committed May 13, 2012
@@ -0,0 +1,10 @@
+/target
+/lib
+/classes
+/checkouts
+pom.xml
+*.jar
+*.class
+.lein-deps-sum
+.lein-failures
+.lein-plugins
@@ -0,0 +1,34 @@
+# lein-gnome
+
+Bringing the magic of ClojureScript to the desktop via Gnome Shell extensions.
+
+## Usage
+
+Put `[lein-gnome "0.1.0-SNAPSHOT"]` into the `:plugins` vector of your project.clj.
+
+ $ lein new lein-gnome myextension example.com
+ $ cd myextension/
+ $ tree
+ .
+ ├── project.clj
+ └── src
+ ├── hello.cljs
+ └── stylesheet.css
+ 1 directory, 3 files
+ $ lein gnome compile
+ [...]
+ Compiling ClojureScript.
+ Compiling "/tmp/myextension/target/extension/extension.js" from "src"...
+ Successfully compiled "[...]/extension.js" in 6.107488105 seconds.
+ Wrote extension: target/extension
+ $ lein gnome install
+ Copied extension to ~/.local/share/gnome-shell/extensions/myextension@example.com directory.
+ Press Alt+F2 r ENTER to reload.
+
+Coming soon: a repl.
+
+## License
+
+Copyright © 2012 Phil Hagelberg
+
+Distributed under the Eclipse Public License, the same as Clojure.
@@ -0,0 +1,10 @@
+/target
+/lib
+/classes
+/checkouts
+pom.xml
+*.jar
+*.class
+.lein-deps-sum
+.lein-failures
+.lein-plugins
@@ -0,0 +1,16 @@
+# lein-template
+
+A Leiningen template generating Gnome Shell extension projects.
+
+## Usage
+
+ $ lein new lein-gnome myproject example.com
+
+Use the `lein-gnome` plugin on the project to compile and install it
+once generated.
+
+## License
+
+Copyright © 2012 Phil Hagelberg
+
+Distributed under the Eclipse Public License, the same as Clojure.
@@ -0,0 +1,6 @@
+(defproject lein-gnome/lein-template "0.1.0-SNAPSHOT"
+ :description "A template for new Gnome Shell extensions."
+ :url "https://github.com/technomancy/lein-gnome"
+ :license {:name "Eclipse Public License"
+ :url "http://www.eclipse.org/legal/epl-v10.html"}
+ :eval-in-leiningen true)
@@ -0,0 +1,17 @@
+(ns leiningen.new.lein-gnome
+ (:use [leiningen.new.templates :only [renderer name-to-path ->files]]))
+
+(def render (renderer "lein_gnome"))
+
+(defn lein-gnome
+ "A template for new Gnome Shell extensions."
+ [name group]
+ (let [data {:name name
+ :group group
+ :sanitized (name-to-path name)}]
+ (println "Generating a lein-gnome project named" (str name "."))
+ (->files data
+ ["src/hello.cljs" (render "hello.cljs" data)]
+ ["src/stylesheet.css" (render "stylesheet.css" data)]
+ ["project.clj" (render "project.clj" data)]
+ [".gitignore" (render "gitignore" data)])))
@@ -0,0 +1,6 @@
+/target
+/checkouts
+.lein-deps-sum
+.lein-plugins
+.lein-failures
+.lein-cljsbuild*
@@ -0,0 +1,50 @@
+(ns hello)
+
+(def main js/imports.ui.main)
+
+(def text (js/imports.gi.St.Label. (.-strobj {"style_class" "helloworld-label"
+ "text" "Hello, ClojureScript"})))
+
+(def button (js/imports.gi.St.Bin. (.-strobj {"style_class" "panel-button"
+ "reactive" true
+ "can_focus" true
+ "x_fill" true
+ "y_fill" false
+ "track_hover" true})))
+
+(defn hide-hello []
+ (-> main .-uiGroup (.remove_actor text)))
+
+(defn show-hello []
+ (-> main .-uiGroup (.add_actor text))
+ (set! (.-opacity text) 255)
+ (let [monitor (-> main .-layoutManager .-primaryMonitor)]
+ (.set_position text
+ (Math/floor (- (/ (.-width monitor) 2)
+ (/ (.-width text) 2)))
+ (Math/floor (- (/ (.-height monitor) 2)
+ (/ (.-height text) 2))))
+ (.addTween js/imports.ui.tweener
+ text (.-strobj {"opacity" 0
+ "time" 2
+ "transition" "easeOutQuad"
+ "onComplete" hide-hello}))))
+
+(defn init []
+ (let [icon (js/imports.gi.St.Icon.
+ (.-strobj {"icon_name" "system-run"
+ "icon_type" js/imports.gi.St.IconType.SYMBOLIC
+ "style_class" "system-status-icon"}))]
+ (.set_child button icon)
+ (.connect button "button-press-event" show-hello)))
+
+(defn enable []
+ (-> main .-panel .-_rightBox (.insert_actor button 0)))
+
+(defn disable []
+ (-> main .-panel .-_rightBox (.remove_actor button)))
+
+(this-as self
+ (set! (.-init self) (fn [] (init) nil))
+ (set! (.-enable self) enable)
+ (set! (.-disable self) disable))
@@ -0,0 +1,8 @@
+(defproject {{group}}/{{name}} "0.1.0-SNAPSHOT"
+ :description "FIXME"
+ :url "http://example.com/FIXME"
+ :license {:name "Eclipse Public License"
+ :url "http://www.eclipse.org/legal/epl-v10.html"}
+ :shell-version ["3.2.2.1"]
+ :dependencies [[org.clojure/clojure "1.4.0"]]
+ :plugins [[lein-gnome "0.1.0-SNAPSHOT"]])
@@ -0,0 +1,9 @@
+
+.helloworld-label {
+ font-size: 36px;
+ font-weight: bold;
+ color: #ffffff;
+ background-color: rgba(10,10,10,0.7);
+ border-radius: 5px;
+ padding: .5em;
+}
@@ -0,0 +1,8 @@
+(defproject lein-gnome "0.1.0-SNAPSHOT"
+ :description "Bringing the magic of ClojureScript to the desktop."
+ :url "https://github.com/technomancy/lein-gnome"
+ :license {:name "Eclipse Public License"
+ :url "http://www.eclipse.org/legal/epl-v10.html"}
+ :dependencies [[lein-cljsbuild "0.1.9"]
+ [cheshire "4.0.0"]]
+ :eval-in-leiningen true)
@@ -0,0 +1,52 @@
+(ns leiningen.gnome
+ (:refer-clojure :exclude [compile])
+ (:require [clojure.java.io :as io]
+ [clojure.java.shell :as sh]
+ [leiningen.cljsbuild :as cljs]
+ [leiningen.help :as help]
+ [leiningen.core.main :as main]
+ [cheshire.core :as json]))
+
+(defn uuid [project]
+ (format "%s@%s" (:name project) (:group project)))
+
+(defn out-dir [project]
+ (str (io/file (:target-path project) "extension")))
+
+(defn metadata-for [project]
+ (json/encode (assoc (select-keys project [:name :description :shell-version])
+ :uuid (uuid project))))
+
+(defn install [project & args]
+ (let [install-dir (format "%s/.local/share/gnome-shell/extensions/%s"
+ (System/getProperty "user.home") (uuid project))]
+ (.mkdirs (io/file install-dir))
+ (doseq [file (.listFiles (io/file (out-dir project)))]
+ (io/copy file (io/file install-dir (.getName file))))
+ (println "Copied extension to" install-dir "directory.")
+ (println "Press Alt+F2 r ENTER to reload.")))
+
+(defn compile [project & args]
+ (let [out (out-dir project)
+ [js metadata stylesheet] (map (comp str (partial io/file out))
+ ["extension.js"
+ "metadata.json"
+ "stylesheet.css"])
+ ;; TODO: use verbose nested :builds-style for :cljsbuild config
+ project (-> project
+ (update-in [:cljsbuild :source-path] #(or % "src"))
+ (update-in [:cljsbuild :compiler :output-to] #(or % js)))]
+ (cljs/cljsbuild project "once")
+ (spit metadata (metadata-for project))
+ ;; TODO: honor :source-paths?
+ (io/copy (io/file (:root project) "src" "stylesheet.css") (io/file stylesheet))
+ (main/info "Wrote extension:" out)))
+
+(defn gnome
+ "Operate on Gnome Shell extensions.
+
+Subtasks: compile and and install."
+ [project & [task args]]
+ (cond (= task "compile") (apply compile project args)
+ (= task "install") (apply install project args)
+ :else (help/help "gnome")))

0 comments on commit 6ed070d

Please sign in to comment.