commit 6e4977867bc38c07ce90f20ebfad1edc53da4801 Author: gered Date: Tue Jul 4 11:16:25 2017 -0400 initial commit diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..278bb6d --- /dev/null +++ b/.gitignore @@ -0,0 +1,17 @@ +.DS_Store +/target +/classes +/checkouts +pom.xml +pom.xml.asc +*.jar +*.class +/.lein-* +/.nrepl-port +.settings/ +.project +.classpath +.idea/ +*.iml +*.ipr +*.iws diff --git a/LICENSE b/LICENSE new file mode 100644 index 0000000..68b07b6 --- /dev/null +++ b/LICENSE @@ -0,0 +1,21 @@ +The MIT License (MIT) + +Copyright (c) 2017 Gered King + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +SOFTWARE. \ No newline at end of file diff --git a/README.md b/README.md new file mode 100644 index 0000000..f809ec0 --- /dev/null +++ b/README.md @@ -0,0 +1,50 @@ +# Simple Clojure/ClojureScript Web App Leiningen Template + +A Leiningen template for creating new Clojure/ClojureScript web app projects using a simplified / stripped-down base. + +Too often I find myself wanting to start a new web application project with just a really simple, light-weight base. In +these cases, I almost always don't want a bunch of extra junk cluttering up the project tree. A lot of the time this is +just to help me write a very quick/simple test application for something I'm working on (e.g. a little web app to serve +as a simple test or demo project for a library I'm working on). + +A lot of the other Leiningen templates out there for creating web applications include a lot of this type of extra junk +out of the box, so I created this template as an alternative. This template primarily exists for my own use, so some +stuff is more oriented towards my own particular preferences regarding the set-up and organization of a Clojure project. + +Includes out-of-the-box support for: + +* Ring/Compojure +* Immutant +* Reagent +* Figwheel +* Bootstrap + +## Usage + +``` +$ lein new simple-web-app [your-project-name-here] +``` + +Then you can spin up figwheel and run the server-side component by running the following each in their own separate CLI +instances: + +``` +$ lein figwheel +$ lein run +``` + +Out of the box the web app will be running at http://localhost:8080/ + +A ClojureScript REPL is also configured by Figwheel on port 7000. Run `(cljs-repl)` once connected. + +An uber JAR for deployment can be created with: + +``` +$ lein uberjar +``` + +## License + +Copyright © 2017 Gered King + +Distributed under the the MIT License. See LICENSE for more details. diff --git a/project.clj b/project.clj new file mode 100644 index 0000000..df9906d --- /dev/null +++ b/project.clj @@ -0,0 +1,6 @@ +(defproject simple-web-app/lein-template "0.1" + :description "Simple / Stripped-down template for Clojure/ClojureScript web apps" + :url "https://github.com/gered/simple-web-app-template" + :license {:name "MIT License" + :url "http://opensource.org/licenses/MIT"} + :eval-in-leiningen true) diff --git a/resources/leiningen/new/simple_web_app/.gitignore b/resources/leiningen/new/simple_web_app/.gitignore new file mode 100644 index 0000000..c7c1135 --- /dev/null +++ b/resources/leiningen/new/simple_web_app/.gitignore @@ -0,0 +1,18 @@ +.DS_Store +/target +/classes +/checkouts +pom.xml +pom.xml.asc +*.jar +*.class +/.lein-* +/.nrepl-port +.settings/ +.project +.classpath +.idea/ +*.iml +*.ipr +*.iws +/resources/public/cljs diff --git a/resources/leiningen/new/simple_web_app/env/dev/src/user.clj b/resources/leiningen/new/simple_web_app/env/dev/src/user.clj new file mode 100644 index 0000000..acd2bbe --- /dev/null +++ b/resources/leiningen/new/simple_web_app/env/dev/src/user.clj @@ -0,0 +1,3 @@ +(ns user + (:require + [figwheel-sidecar.repl-api :refer [cljs-repl]])) diff --git a/resources/leiningen/new/simple_web_app/project.clj b/resources/leiningen/new/simple_web_app/project.clj new file mode 100644 index 0000000..f1dee50 --- /dev/null +++ b/resources/leiningen/new/simple_web_app/project.clj @@ -0,0 +1,63 @@ +(defproject {{name}} "0.1.0-SNAPSHOT" + + :dependencies [[cljsjs/bootstrap "3.3.6-1"] + [compojure "1.6.0"] + [environ "1.1.0"] + [hiccup "1.0.5"] + [org.clojure/clojure "1.8.0"] + [org.clojure/clojurescript "1.9.671"] + [org.immutant/web "2.1.9"] + [org.webjars/bootstrap "3.3.6"] + [reagent "0.7.0"] + [ring "1.6.1"] + [ring-webjars "0.2.0"] + [ring/ring-defaults "0.3.0" :exclusions [javax.servlet/servlet-api]]] + + :plugins [[lein-cljsbuild "1.1.6"] + [lein-environ "1.1.0"] + [lein-figwheel "0.5.11"]] + + :main {{root-ns}}.server + + :clean-targets ^{:protect false} [:target-path + [:cljsbuild :builds :app :compiler :output-dir] + [:cljsbuild :builds :app :compiler :output-to]] + + :figwheel {:css-dirs ["resources/public/css"]} + + :cljsbuild {:builds + {:app + {:source-paths ["src"] + :figwheel {:on-jsload {{root-ns}}.client/reload} + :compiler {:main {{root-ns}}.client + :output-to "resources/public/cljs/app.js" + :output-dir "resources/public/cljs/target" + :asset-path "cljs/target" + :source-map true + :optimizations :none + :pretty-print true}}}} + + :profiles {:dev {:env {:dev? true} + :source-paths ["env/dev/src"] + :dependencies [[figwheel-sidecar "0.5.11"] + [org.clojure/tools.nrepl "0.2.13"] + [com.cemerick/piggieback "0.2.2-SNAPSHOT"]] + :figwheel {:nrepl-port 7000 + :nrepl-middleware [cemerick.piggieback/wrap-cljs-repl]} + :cljsbuild {:builds {:app + {:source-paths ["src" "env/dev/src"]}}}} + + :uberjar {:source-paths ["env/prod/src"] + :aot :all + :hooks [leiningen.cljsbuild] + :omit-source true + :cljsbuild {:jar true + :builds {:app + {:compiler ^:replace {:source-paths ["src" "env/prod/src"] + :output-to "resources/public/cljs/app.js" + :optimizations :advanced + :pretty-print false}}}}}} + + :aliases {"uberjar" ["do" ["clean"] ["uberjar"]]} + + ) diff --git a/resources/leiningen/new/simple_web_app/resources/public/css/app.css b/resources/leiningen/new/simple_web_app/resources/public/css/app.css new file mode 100644 index 0000000..e69de29 diff --git a/resources/leiningen/new/simple_web_app/src/root_ns/client.cljs b/resources/leiningen/new/simple_web_app/src/root_ns/client.cljs new file mode 100644 index 0000000..88a906e --- /dev/null +++ b/resources/leiningen/new/simple_web_app/src/root_ns/client.cljs @@ -0,0 +1,16 @@ +(ns {{root-ns}}.client + (:require + [reagent.core :as r])) + +(defn main-app-component + [] + [:h1 "Hello, world!"]) + +(defn reload + [] + (r/render-component [main-app-component] (.getElementById js/document "app"))) + +(defn ^:export run + [] + (enable-console-print!) + (reload)) diff --git a/resources/leiningen/new/simple_web_app/src/root_ns/server.clj b/resources/leiningen/new/simple_web_app/src/root_ns/server.clj new file mode 100644 index 0000000..2ac9e9a --- /dev/null +++ b/resources/leiningen/new/simple_web_app/src/root_ns/server.clj @@ -0,0 +1,47 @@ +(ns {{root-ns}}.server + (:gen-class) + (:require + [compojure.core :refer [routes GET]] + [compojure.route :as route] + [environ.core :refer [env]] + [hiccup.element :refer [javascript-tag]] + [hiccup.page :refer [html5 include-css include-js]] + [immutant.web :as immutant] + [ring.middleware.defaults :refer [wrap-defaults site-defaults]] + [ring.middleware.reload :refer [wrap-reload]] + [ring.middleware.webjars :refer [wrap-webjars]] + [ring.util.response :refer [response]])) + +(defn render-home-page + [] + (html5 + [:head + [:meta {:charset "utf-8"}] + [:meta {:http-equiv "X-UA-Compatible" :content "IE-edge"}] + [:meta {:name "viewport" :content "width=device-width, initial-scale=1"}] + [:title "{{name}} :: Home Page"] + (include-css "/assets/bootstrap/css/bootstrap.min.css") + (include-css "css/app.css") + (include-js "cljs/app.js")] + [:body + [:div#app [:h1 "Waiting for ClojureScript to load ..."]] + (javascript-tag "{{root-ns}}.client.run();")])) + +(def app-routes + (routes + (GET "/" [] (render-home-page)) + (route/not-found "not found"))) + +(def handler + (as-> app-routes h + (if (:dev? env) (wrap-reload h) h) + (wrap-defaults h (assoc-in site-defaults [:security :anti-forgery] false)) + (wrap-webjars h))) + +(defn run-server + [] + (immutant/run handler {:port 8080})) + +(defn -main + [& args] + (run-server)) diff --git a/src/leiningen/new/simple_web_app.clj b/src/leiningen/new/simple_web_app.clj new file mode 100644 index 0000000..ba62038 --- /dev/null +++ b/src/leiningen/new/simple_web_app.clj @@ -0,0 +1,23 @@ +(ns leiningen.new.simple-web-app + (:require + [leiningen.new.templates :as t] + [leiningen.core.main :as main])) + +(def render (t/renderer "simple-web-app")) + +(defn simple-web-app + [name] + (let [data {:name name + :sanitized (t/sanitize name) + :root-ns (t/sanitize-ns name) + :root-ns-path (t/name-to-path name)}] + (main/info (str "Creating a new simple-web-app Clojure/ClojureScript web app project \"" name "\" ...")) + (t/->files + data + ["env/dev/src/user.clj" (render "env/dev/src/user.clj" data)] + "env/prod/src" + ["resources/public/css/app.css" (render "resources/public/css/app.css" data)] + ["src/{{root-ns-path}}/client.cljs" (render "src/root_ns/client.cljs" data)] + ["src/{{root-ns-path}}/server.clj" (render "src/root_ns/server.clj" data)] + [".gitignore" (render ".gitignore" data)] + ["project.clj" (render "project.clj" data)])))