From 8f2d4c2c7d84a61919e75bfcef96d47cf77c8135 Mon Sep 17 00:00:00 2001 From: Julian Ospald Date: Sun, 24 Jun 2018 14:42:40 +0200 Subject: [PATCH] Initial commit --- hello-world/README.md | 39 ++++++++ hello-world/dev/user.clj | 42 ++++++++ hello-world/project.clj | 109 +++++++++++++++++++++ hello-world/resources/public/css/style.css | 2 + hello-world/resources/public/index.html | 16 +++ hello-world/src/hello_world/core.cljs | 81 +++++++++++++++ 6 files changed, 289 insertions(+) create mode 100644 hello-world/README.md create mode 100644 hello-world/dev/user.clj create mode 100644 hello-world/project.clj create mode 100644 hello-world/resources/public/css/style.css create mode 100644 hello-world/resources/public/index.html create mode 100644 hello-world/src/hello_world/core.cljs diff --git a/hello-world/README.md b/hello-world/README.md new file mode 100644 index 0000000..6163967 --- /dev/null +++ b/hello-world/README.md @@ -0,0 +1,39 @@ +# hello-world + +FIXME: Write a one-line description of your library/project. + +## Overview + +FIXME: Write a paragraph about the library/project and highlight its goals. + +## Setup + +To get an interactive development environment run: + + lein figwheel + +and open your browser at [localhost:3449](http://localhost:3449/). +This will auto compile and send all changes to the browser without the +need to reload. After the compilation process is complete, you will +get a Browser Connected REPL. An easy way to try it is: + + (js/alert "Am I connected?") + +and you should see an alert in the browser window. + +To clean all compiled files: + + lein clean + +To create a production build run: + + lein do clean, cljsbuild once min + +And open your browser in `resources/public/index.html`. You will not +get live reloading, nor a REPL. + +## License + +Copyright © 2014 FIXME + +Distributed under the Eclipse Public License either version 1.0 or (at your option) any later version. diff --git a/hello-world/dev/user.clj b/hello-world/dev/user.clj new file mode 100644 index 0000000..11a6018 --- /dev/null +++ b/hello-world/dev/user.clj @@ -0,0 +1,42 @@ +(ns user + (:require + [figwheel-sidecar.repl-api :as f])) + +;; user is a namespace that the Clojure runtime looks for and +;; loads if its available + +;; You can place helper functions in here. This is great for starting +;; and stopping your webserver and other development services + +;; The definitions in here will be available if you run "lein repl" or launch a +;; Clojure repl some other way + +;; You have to ensure that the libraries you :require are listed in your dependencies + +;; Once you start down this path +;; you will probably want to look at +;; tools.namespace https://github.com/clojure/tools.namespace +;; and Component https://github.com/stuartsierra/component + + +(defn fig-start + "This starts the figwheel server and watch based auto-compiler." + [] + ;; this call will only work are long as your :cljsbuild and + ;; :figwheel configurations are at the top level of your project.clj + ;; and are not spread across different lein profiles + + ;; otherwise you can pass a configuration into start-figwheel! manually + (f/start-figwheel!)) + +(defn fig-stop + "Stop the figwheel server and watch based auto-compiler." + [] + (f/stop-figwheel!)) + +;; if you are in an nREPL environment you will need to make sure you +;; have setup piggieback for this to work +(defn cljs-repl + "Launch a ClojureScript REPL that is connected to your build and host environment." + [] + (f/cljs-repl)) diff --git a/hello-world/project.clj b/hello-world/project.clj new file mode 100644 index 0000000..b46f1ba --- /dev/null +++ b/hello-world/project.clj @@ -0,0 +1,109 @@ +(defproject hello-world "0.1.0-SNAPSHOT" + :description "FIXME: write this!" + :url "http://example.com/FIXME" + :license {:name "Eclipse Public License" + :url "http://www.eclipse.org/legal/epl-v10.html"} + + + + :min-lein-version "2.7.1" + + :dependencies [[org.clojure/clojure "1.9.0"] + [org.clojure/clojurescript "1.10.238"] + [org.clojure/core.async "0.4.474"] + [cljsjs/react "15.6.1-1"] + [cljsjs/react-dom "15.6.1-1"] + [sablono "0.8.3"] + [org.omcljs/om "1.0.0-alpha46"]] + + :plugins [[lein-figwheel "0.5.16"] + [lein-cljsbuild "1.1.7" :exclusions [[org.clojure/clojure]]]] + + :source-paths ["src"] + + :cljsbuild {:builds + [{:id "dev" + :source-paths ["src"] + + ;; The presence of a :figwheel configuration here + ;; will cause figwheel to inject the figwheel client + ;; into your build + :figwheel {:on-jsload "hello-world.core/on-js-reload" + ;; :open-urls will pop open your application + ;; in the default browser once Figwheel has + ;; started and compiled your application. + ;; Comment this out once it no longer serves you. + :open-urls ["http://localhost:3449/index.html"]} + + :compiler {:main hello-world.core + :asset-path "js/compiled/out" + :output-to "resources/public/js/compiled/hello_world.js" + :output-dir "resources/public/js/compiled/out" + :source-map-timestamp true + ;; To console.log CLJS data-structures make sure you enable devtools in Chrome + ;; https://github.com/binaryage/cljs-devtools + :preloads [devtools.preload]}} + ;; This next build is a compressed minified build for + ;; production. You can build this with: + ;; lein cljsbuild once min + {:id "min" + :source-paths ["src"] + :compiler {:output-to "resources/public/js/compiled/hello_world.js" + :main hello-world.core + :optimizations :advanced + :pretty-print false}}]} + + :figwheel {;; :http-server-root "public" ;; default and assumes "resources" + ;; :server-port 3449 ;; default + ;; :server-ip "127.0.0.1" + + :css-dirs ["resources/public/css"] ;; watch and update CSS + + ;; Start an nREPL server into the running figwheel process + ;; :nrepl-port 7888 + + ;; Server Ring Handler (optional) + ;; if you want to embed a ring handler into the figwheel http-kit + ;; server, this is for simple ring servers, if this + + ;; doesn't work for you just run your own server :) (see lein-ring) + + ;; :ring-handler hello_world.server/handler + + ;; To be able to open files in your editor from the heads up display + ;; you will need to put a script on your path. + ;; that script will have to take a file path and a line number + ;; ie. in ~/bin/myfile-opener + ;; #! /bin/sh + ;; emacsclient -n +$2 $1 + ;; + ;; :open-file-command "myfile-opener" + + ;; if you are using emacsclient you can just use + ;; :open-file-command "emacsclient" + + ;; if you want to disable the REPL + ;; :repl false + + ;; to configure a different figwheel logfile path + ;; :server-logfile "tmp/logs/figwheel-logfile.log" + + ;; to pipe all the output to the repl + ;; :server-logfile false + } + + + ;; Setting up nREPL for Figwheel and ClojureScript dev + ;; Please see: + ;; https://github.com/bhauman/lein-figwheel/wiki/Using-the-Figwheel-REPL-within-NRepl + :profiles {:dev {:dependencies [[binaryage/devtools "0.9.9"] + [figwheel-sidecar "0.5.16"] + [cider/piggieback "0.3.1"]] + ;; need to add dev source path here to get user.clj loaded + :source-paths ["src" "dev"] + ;; for CIDER + ;; :plugins [[cider/cider-nrepl "0.12.0"]] + :repl-options {:nrepl-middleware [cider.piggieback/wrap-cljs-repl]} + ;; need to add the compliled assets to the :clean-targets + :clean-targets ^{:protect false} ["resources/public/js/compiled" + :target-path]}}) diff --git a/hello-world/resources/public/css/style.css b/hello-world/resources/public/css/style.css new file mode 100644 index 0000000..26163d2 --- /dev/null +++ b/hello-world/resources/public/css/style.css @@ -0,0 +1,2 @@ +/* some style */ + diff --git a/hello-world/resources/public/index.html b/hello-world/resources/public/index.html new file mode 100644 index 0000000..6273f68 --- /dev/null +++ b/hello-world/resources/public/index.html @@ -0,0 +1,16 @@ + + + + + + + + + +
+

Figwheel template

+

Checkout your developer console.

+
+ + + diff --git a/hello-world/src/hello_world/core.cljs b/hello-world/src/hello_world/core.cljs new file mode 100644 index 0000000..11034df --- /dev/null +++ b/hello-world/src/hello_world/core.cljs @@ -0,0 +1,81 @@ +(ns hello-world.core + (:require [om.core :as om :include-macros true] + [om.dom :as dom :include-macros true])) + +(enable-console-print!) + +(println "This text is printed from src/hello-world/core.cljs. Go ahead and edit it and see reloading in action.") + +;; define your app data so that it doesn't get over-written on reload + +(defonce app-state (atom {:text "Hello world!"})) + + +(om/root + (fn [data owner] + (reify om/IRender + (render [_] + (dom/div nil + (dom/h1 nil (:text data)) + (dom/h3 nil "Edit this and wtc it change!"))))) + app-state + {:target (. js/document (getElementById "app"))}) + +(defn on-js-reload [] + ;; optionally touch your app-state to force rerendering depending on + ;; your application + ;; (swap! app-state update-in [:__figwheel_counter] inc) +) + +(.getElementById js/document "app") + + +(defn average [a b] + (/ (+ a b) 2.0)) ;; blah + +(average 3 8) + + +(loop [[n & numbers] '(1 2 3 4 5) + result '()] + (let [result (cons (* n n) result)] + (if numbers + (recur numbers result) + result))) + +(loop [x 10] + (let [result x] + (when (> x 1) + (println x) + (recur (- x 2))) + )) + +(defn head [[n & _]] + (println (+ n 1)) + n) + +(head '(3 2 1)) + +(even? 4) + +(declare ^{:dynamic true} *foo*) + +(def l '(1 2 3)) + +(defn with-foo [f] + (binding [*foo* "I exist!"] + (f))) + +; ; (with-foo #(println *foo*)) =>"I exist!" + + +(str "Hello" " " "World") + +;; functions + +((fn add-five [x] (+ x 5)) 6) +((fn [x] (+ x 5)) 3) +(#(+ % 5) 3) +((partial + 5) 3) + +; (add-five 3)