Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
0 parents
commit d7e29e0
Showing
9 changed files
with
196 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
/target | ||
/classes | ||
/checkouts | ||
pom.xml | ||
pom.xml.asc | ||
*.jar | ||
*.class | ||
/.lein-* | ||
/.nrepl-port |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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)]))) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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))) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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} (<! (http/get url))] | ||
(>! 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 (<! (fetch-widgets (:url opts)))] | ||
(.log js/console (pr-str widgets)) | ||
(om/update! app #(assoc % :widgets widgets))) | ||
(<! (timeout (:poll-interval opts)))))) | ||
om/IRender | ||
(render [_] | ||
(dom/div nil | ||
(dom/h1 nil "Widgets") | ||
(om/build widget-list app))))) | ||
|
||
(defn om-app [app owner] | ||
(reify | ||
om/IRender | ||
(render [_] | ||
(dom/div nil | ||
(om/build widget-box app | ||
{:opts {:url "/widgets" | ||
:poll-interval 2000}}))))) | ||
|
||
(om/root app-state om-app (.getElementById js/document "content")) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
pom.xml | ||
*jar | ||
/lib/ | ||
/classes/ | ||
/out/ | ||
/target/ | ||
.lein-deps-sum | ||
.lein-repl-history | ||
.lein-plugins/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
<!DOCTYPE html> | ||
<html lang="en"> | ||
<head> | ||
<meta charset="utf-8"/> | ||
<meta http-equiv="X-UA-Compatible" content="IE=edge"/> | ||
<link rel="stylesheet" href="http://cdn.jsdelivr.net/foundation/5.0.3/css/foundation.min.css" /> | ||
<link rel="stylesheet" href="css/app.css" /> | ||
</head> | ||
<body> | ||
<div class="row"> | ||
<div class="large-12 columns"> | ||
<div id="content"></div> | ||
</div> | ||
</div> | ||
|
||
<script src="http://fb.me/react-0.8.0.js"></script> | ||
<script src="js/out/goog/base.js" type="text/javascript"></script> | ||
<script src="js/app.js" type="text/javascript"></script> | ||
<script type="text/javascript">goog.require("{{sanitized}}.core");</script> | ||
</body> | ||
</html> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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"]}}]}) |