diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..e04714b --- /dev/null +++ b/.gitignore @@ -0,0 +1,9 @@ +/target +/classes +/checkouts +pom.xml +pom.xml.asc +*.jar +*.class +/.lein-* +/.nrepl-port diff --git a/README.md b/README.md new file mode 100644 index 0000000..f4b3c4b --- /dev/null +++ b/README.md @@ -0,0 +1,20 @@ +# atw-om + +A web application template with Clojure/Compojure on the backend, ClojureScript/Om on the frontend and core.async in-between: simply put, Clojure **a**ll **t**he **w**ay. + +## Usage + +``` +lein new atw-om foo +cd foo +lein up +``` + +Wait till ClojureScript is compiled, then go to `localhost:3000`. + +## License + +Copyright © 2014 Zaiste + +Distributed under the Eclipse Public License either version 1.0 or (at +your option) any later version. diff --git a/project.clj b/project.clj new file mode 100644 index 0000000..9574a3f --- /dev/null +++ b/project.clj @@ -0,0 +1,8 @@ +(defproject atw-om/lein-template "0.1.4" + :description "Clojure, all the way with Om" + :url "https://github.com/zaiste/atw-om" + :license {:name "Eclipse Public License" + :url "http://www.eclipse.org/legal/epl-v10.html"} + :scm {:name "git" + :url ""} + :eval-in-leiningen true) diff --git a/src/leiningen/new/atw_om.clj b/src/leiningen/new/atw_om.clj new file mode 100644 index 0000000..f63b4ac --- /dev/null +++ b/src/leiningen/new/atw_om.clj @@ -0,0 +1,14 @@ +(ns leiningen.new.atw-om + (:require [leiningen.new.templates :refer [renderer name-to-path ->files]])) + +(def render (renderer "atw-om")) + +(defn atw-om [name] + (let [data {:name name + :sanitized (name-to-path name)}] + (->files data + ["project.clj" (render "project.clj" data)] + ["src/clj/{{sanitized}}/core.clj" (render "core.clj" data)] + ["src/cljs/{{sanitized}}/core.cljs" (render "core.cljs" data)] + ["resources/public/index.html" (render "index.html" data)] + [".gitignore" (render "gitignore" data)]))) diff --git a/src/leiningen/new/atw_om/core.clj b/src/leiningen/new/atw_om/core.clj new file mode 100644 index 0000000..13a0d2c --- /dev/null +++ b/src/leiningen/new/atw_om/core.clj @@ -0,0 +1,17 @@ +(ns {{name}}.core + (:use ring.util.response) + (:require [compojure.handler :as handler] + [compojure.route :as route] + [compojure.core :refer [GET POST defroutes]] + [ring.middleware.json :as middleware])) + +(defroutes app-routes + (GET "/" [] (resource-response "index.html" {:root "public"})) + (GET "/widgets" [] (response [{:name "Widget 1"} {:name "Widget 2"}])) + (route/resources "/") + (route/not-found "Page not found")) + +(def app + (-> (handler/api app-routes) + (middleware/wrap-json-body) + (middleware/wrap-json-response))) diff --git a/src/leiningen/new/atw_om/core.cljs b/src/leiningen/new/atw_om/core.cljs new file mode 100644 index 0000000..5e4539c --- /dev/null +++ b/src/leiningen/new/atw_om/core.cljs @@ -0,0 +1,57 @@ +(ns {{name}}.core + (:require-macros [cljs.core.async.macros :refer [go alt!]]) + (:require [goog.events :as events] + [cljs.core.async :refer [put! ! chan timeout]] + [om.core :as om :include-macros true] + [om.dom :as dom :include-macros true] + [cljs-http.client :as http])) + +(enable-console-print!) + +(defn fetch-widgets + [url] + (let [c (chan)] + (go (let [{widgets :body} (! c (vec widgets)))) + c)) + +(def app-state + (atom {})) + +(defn widget [{:keys [name]} owner opts] + (om/component + (dom/li nil name))) + +(defn widget-list [{:keys [widgets]}] + (om/component + (apply dom/ul nil + (om/build-all widget widgets)))) + +(defn widget-box [app owner opts] + (reify + om/IInitState + (init-state [_] + (om/transact! app [:widgets] (fn [] []))) + om/IWillMount + (will-mount [_] + (go (while true + (let [widgets ( + + + + + + + + +
+
+
+
+
+ + + + + + + diff --git a/src/leiningen/new/atw_om/project.clj b/src/leiningen/new/atw_om/project.clj new file mode 100644 index 0000000..1a550d1 --- /dev/null +++ b/src/leiningen/new/atw_om/project.clj @@ -0,0 +1,41 @@ +(defproject {{name}} "0.1.0-SNAPSHOT" + :description "FIXME: write this!" + :url "http://example.com/FIXME" + :dependencies [[org.clojure/clojure "1.5.1"] + [org.clojure/tools.reader "0.8.2"] + [ring/ring-core "1.2.0"] + [ring/ring-json "0.2.0"] + [compojure "1.1.6"] + [org.clojure/clojurescript "0.0-2138"] + [org.clojure/core.async "0.1.267.0-0d7780-alpha"] + [cljs-http "0.1.2"] + [om "0.3.6"] + [com.facebook/react "0.8.0.1"]] + + :plugins [[lein-cljsbuild "1.0.1"] + [lein-ring "0.8.7"] + [lein-pdo "0.1.1"]] + + :aliases {"up" ["pdo" "cljsbuild" "auto" "dev," "ring" "server-headless"]} + + :min-lein-version "2.0.0" + :uberjar-name "{{name}}-standalone.jar" + + :ring {:handler {{name}}.core/app + :init {{name}}.core/init} + + :source-paths ["src/clj"] + + :cljsbuild {:builds [{:id "dev" + :source-paths ["src/cljs"] + :compiler {:output-to "resources/public/js/app.js" + :output-dir "resources/public/js/out" + :optimizations :none + :source-map true}} + {:id "release" + :source-paths ["src/cljs"] + :compiler {:output-to "resources/public/js/app.js" + :optimizations :advanced + :pretty-print false + :preamble ["react/react.min.js"] + :externs ["react/externs/react.js"]}}]})