forked from interstar/contascalango
-
Notifications
You must be signed in to change notification settings - Fork 5
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
Showing
15 changed files
with
314 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,5 @@ | ||
/*.log | ||
/target | ||
/*-init.clj | ||
/resources/public/js/compiled | ||
out |
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 @@ | ||
web: java $JVM_OPTS -cp target/contascalangos.jar clojure.main -m contascalangos.server |
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,60 @@ | ||
# contascalangos | ||
|
||
A [re-frame](https://github.com/Day8/re-frame) application designed to ... well, that part is up to you. | ||
|
||
## Development Mode | ||
|
||
### Start Cider from Emacs: | ||
|
||
Put this in your Emacs config file: | ||
|
||
``` | ||
(setq cider-cljs-lein-repl | ||
"(do (require 'figwheel-sidecar.repl-api) | ||
(figwheel-sidecar.repl-api/start-figwheel!) | ||
(figwheel-sidecar.repl-api/cljs-repl))") | ||
``` | ||
|
||
Navigate to a clojurescript file and start a figwheel REPL with `cider-jack-in-clojurescript` or (`C-c M-J`) | ||
|
||
### Run application: | ||
|
||
``` | ||
lein clean | ||
lein figwheel dev | ||
``` | ||
|
||
Figwheel will automatically push cljs changes to the browser. | ||
|
||
Wait a bit, then browse to [http://localhost:3449](http://localhost:3449). | ||
|
||
## Production Build | ||
|
||
``` | ||
lein clean | ||
lein with-profile prod uberjar | ||
``` | ||
|
||
That should compile the clojurescript code first, and then create the standalone jar. | ||
|
||
When you run the jar you can set the port the ring server will use by setting the environment variable PORT. | ||
If it's not set, it will run on port 3000 by default. | ||
|
||
To deploy to heroku, first create your app: | ||
|
||
``` | ||
heroku create | ||
``` | ||
|
||
Then deploy the application: | ||
|
||
``` | ||
git push heroku master | ||
``` | ||
|
||
To compile clojurescript to javascript: | ||
|
||
``` | ||
lein clean | ||
lein cljsbuild once min | ||
``` |
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,71 @@ | ||
(defproject contascalangos "0.1.0-SNAPSHOT" | ||
:dependencies [[org.clojure/clojure "1.8.0"] | ||
[org.clojure/clojurescript "1.10.238"] | ||
[reagent "0.7.0"] | ||
[re-frame "0.10.5"] | ||
[secretary "1.2.3"] | ||
[compojure "1.5.0"] | ||
[yogthos/config "0.8"] | ||
[ring "1.4.0"]] | ||
|
||
:plugins [[lein-cljsbuild "1.1.7"]] | ||
|
||
:min-lein-version "2.5.3" | ||
|
||
:source-paths ["src/clj" "src/cljs"] | ||
|
||
:clean-targets ^{:protect false} ["resources/public/js/compiled" "target"] | ||
|
||
:figwheel {:css-dirs ["resources/public/css"] | ||
:ring-handler contascalangos.handler/dev-handler} | ||
|
||
:repl-options {:nrepl-middleware [cider.piggieback/wrap-cljs-repl]} | ||
|
||
:profiles | ||
{:dev | ||
{:dependencies [[binaryage/devtools "0.9.10"] | ||
[day8.re-frame/re-frame-10x "0.3.3"] | ||
[day8.re-frame/tracing "0.5.1"] | ||
[figwheel-sidecar "0.5.16"] | ||
[cider/piggieback "0.3.5"]] | ||
|
||
:plugins [[lein-figwheel "0.5.16"]]} | ||
:prod { :dependencies [[day8.re-frame/tracing-stubs "0.5.1"]]}} | ||
|
||
:cljsbuild | ||
{:builds | ||
[{:id "dev" | ||
:source-paths ["src/cljs"] | ||
:figwheel {:on-jsload "contascalangos.core/mount-root"} | ||
:compiler {:main contascalangos.core | ||
:output-to "resources/public/js/compiled/app.js" | ||
:output-dir "resources/public/js/compiled/out" | ||
:asset-path "js/compiled/out" | ||
:source-map-timestamp true | ||
:preloads [devtools.preload | ||
day8.re-frame-10x.preload] | ||
:closure-defines {"re_frame.trace.trace_enabled_QMARK_" true | ||
"day8.re_frame.tracing.trace_enabled_QMARK_" true} | ||
:external-config {:devtools/config {:features-to-install :all}} | ||
}} | ||
|
||
{:id "min" | ||
:source-paths ["src/cljs"] | ||
:jar true | ||
:compiler {:main contascalangos.core | ||
:output-to "resources/public/js/compiled/app.js" | ||
:optimizations :advanced | ||
:closure-defines {goog.DEBUG false} | ||
:pretty-print false}} | ||
|
||
|
||
]} | ||
|
||
:main contascalangos.server | ||
|
||
:aot [contascalangos.server] | ||
|
||
:uberjar-name "contascalangos.jar" | ||
|
||
:prep-tasks [["cljsbuild" "once" "min"] "compile"] | ||
) |
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,13 @@ | ||
<!doctype html> | ||
<html lang="en"> | ||
<head> | ||
<meta charset='utf-8'> | ||
|
||
|
||
</head> | ||
<body> | ||
<div id="app"></div> | ||
<script src="js/compiled/app.js"></script> | ||
<script>contascalangos.core.init();</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 @@ | ||
(ns contascalangos.core) |
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,13 @@ | ||
(ns contascalangos.handler | ||
(:require [compojure.core :refer [GET defroutes]] | ||
[compojure.route :refer [resources]] | ||
[ring.util.response :refer [resource-response]] | ||
[ring.middleware.reload :refer [wrap-reload]])) | ||
|
||
(defroutes routes | ||
(GET "/" [] (resource-response "index.html" {:root "public"})) | ||
(resources "/")) | ||
|
||
(def dev-handler (-> #'routes wrap-reload)) | ||
|
||
(def handler routes) |
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 @@ | ||
(ns contascalangos.server | ||
(:require [contascalangos.handler :refer [handler]] | ||
[config.core :refer [env]] | ||
[ring.adapter.jetty :refer [run-jetty]]) | ||
(:gen-class)) | ||
|
||
(defn -main [& args] | ||
(let [port (Integer/parseInt (or (env :port) "3000"))] | ||
(run-jetty handler {:port port :join? false}))) |
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,4 @@ | ||
(ns contascalangos.config) | ||
|
||
(def debug? | ||
^boolean goog.DEBUG) |
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,26 @@ | ||
(ns contascalangos.core | ||
(:require | ||
[reagent.core :as reagent] | ||
[re-frame.core :as re-frame] | ||
[contascalangos.events :as events] | ||
[contascalangos.routes :as routes] | ||
[contascalangos.views :as views] | ||
[contascalangos.config :as config] | ||
)) | ||
|
||
|
||
(defn dev-setup [] | ||
(when config/debug? | ||
(enable-console-print!) | ||
(println "dev mode"))) | ||
|
||
(defn mount-root [] | ||
(re-frame/clear-subscription-cache!) | ||
(reagent/render [views/main-panel] | ||
(.getElementById js/document "app"))) | ||
|
||
(defn ^:export init [] | ||
(routes/app-routes) | ||
(re-frame/dispatch-sync [::events/initialize-db]) | ||
(dev-setup) | ||
(mount-root)) |
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,4 @@ | ||
(ns contascalangos.db) | ||
|
||
(def default-db | ||
{:name "re-frame"}) |
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,16 @@ | ||
(ns contascalangos.events | ||
(:require | ||
[re-frame.core :as re-frame] | ||
[contascalangos.db :as db] | ||
[day8.re-frame.tracing :refer-macros [fn-traced defn-traced]] | ||
)) | ||
|
||
(re-frame/reg-event-db | ||
::initialize-db | ||
(fn-traced [_ _] | ||
db/default-db)) | ||
|
||
(re-frame/reg-event-db | ||
::set-active-panel | ||
(fn-traced [db [_ active-panel]] | ||
(assoc db :active-panel active-panel))) |
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,33 @@ | ||
(ns contascalangos.routes | ||
(:require-macros [secretary.core :refer [defroute]]) | ||
(:import goog.History) | ||
(:require | ||
[secretary.core :as secretary] | ||
[goog.events :as gevents] | ||
[goog.history.EventType :as EventType] | ||
[re-frame.core :as re-frame] | ||
[contascalangos.events :as events] | ||
)) | ||
|
||
(defn hook-browser-navigation! [] | ||
(doto (History.) | ||
(gevents/listen | ||
EventType/NAVIGATE | ||
(fn [event] | ||
(secretary/dispatch! (.-token event)))) | ||
(.setEnabled true))) | ||
|
||
(defn app-routes [] | ||
(secretary/set-config! :prefix "#") | ||
;; -------------------- | ||
;; define routes here | ||
(defroute "/" [] | ||
(re-frame/dispatch [::events/set-active-panel :home-panel]) | ||
) | ||
|
||
(defroute "/about" [] | ||
(re-frame/dispatch [::events/set-active-panel :about-panel])) | ||
|
||
|
||
;; -------------------- | ||
(hook-browser-navigation!)) |
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,13 @@ | ||
(ns contascalangos.subs | ||
(:require | ||
[re-frame.core :as re-frame])) | ||
|
||
(re-frame/reg-sub | ||
::name | ||
(fn [db] | ||
(:name db))) | ||
|
||
(re-frame/reg-sub | ||
::active-panel | ||
(fn [db _] | ||
(:active-panel db))) |
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,45 @@ | ||
(ns contascalangos.views | ||
(:require | ||
[re-frame.core :as re-frame] | ||
[contascalangos.subs :as subs] | ||
)) | ||
|
||
|
||
;; home | ||
|
||
(defn home-panel [] | ||
(let [name (re-frame/subscribe [::subs/name])] | ||
[:div | ||
[:h1 (str "Hello from " @name ". This is the Home Page.")] | ||
|
||
[:div | ||
[:a {:href "#/about"} | ||
"go to About Page"]] | ||
])) | ||
|
||
|
||
;; about | ||
|
||
(defn about-panel [] | ||
[:div | ||
[:h1 "This is the About Page."] | ||
|
||
[:div | ||
[:a {:href "#/"} | ||
"go to Home Page"]]]) | ||
|
||
|
||
;; main | ||
|
||
(defn- panels [panel-name] | ||
(case panel-name | ||
:home-panel [home-panel] | ||
:about-panel [about-panel] | ||
[:div])) | ||
|
||
(defn show-panel [panel-name] | ||
[panels panel-name]) | ||
|
||
(defn main-panel [] | ||
(let [active-panel (re-frame/subscribe [::subs/active-panel])] | ||
[show-panel @active-panel])) |