diff --git a/.gitignore b/.gitignore index 0ef5d3f..47fed6c 100644 --- a/.gitignore +++ b/.gitignore @@ -9,3 +9,4 @@ pom.xml.asc .lein-repl-history .lein-plugins/ .lein-failures +.nrepl-port diff --git a/README.md b/README.md index aa45737..510ea96 100644 --- a/README.md +++ b/README.md @@ -11,7 +11,7 @@ a batteries included setup for development and deployment. ### Getting Help -For any questions or discussion please come join us at the [Reagent Google Group](https://groups.google.com/forum/#!forum/reagent-project). +For any questions or discussion please come join us in the #reagent channel on the [Clojurians Slack](http://clojurians.net/). ## Usage @@ -21,12 +21,12 @@ Create a new application project: lein new reagent ``` -To enable [cljs.test](https://github.com/clojure/clojurescript/blob/master/src/main/cljs/cljs/test.cljs) and [doo](https://github.com/bensu/doo) with [PhantomJS](http://phantomjs.org/), use `+test` flag: +To enable [cljs.test](https://github.com/clojure/clojurescript/blob/master/src/main/cljs/cljs/test.cljs) and [doo](https://github.com/bensu/doo) use `+test` flag: ``` lein new reagent +test ``` -To run the tests, please use `lein doo phantom test once`. For installation instructions of PhantomJS, please see [this](http://phantomjs.org/download.html). +To run the tests using headless chrome first install karma and its plugins `npm install -g karma-cli && npm install karma karma-cljs-test karma-chrome-launcher --save-dev`, then use `lein doo chrome-headless test once`. For other environments please check [doo's documentation](https://github.com/bensu/doo#setting-up-environments). To enable [speclj](https://github.com/slagyr/speclj) with [PhantomJS](http://phantomjs.org/), use `+spec` flag: @@ -47,22 +47,42 @@ To add [CIDER](https://github.com/clojure-emacs/cider) plugin, use the `+cider` lein new reagent +cider ``` +To add [less](https://github.com/Deraen/less4clj)/[sass](https://github.com/Deraen/sass4clj) support +use `+less` or `+sass` flags: -### Development mode +``` +lein new reagent +less +``` + +To add [figwheel](https://github.com/bhauman/lein-figwheel/) (legacy), use the `+figwheel` flag: +``` +lein new reagent +figwheel +``` -To start the Figwheel compiler, navigate to the project folder and run the following command in the terminal: +### Development mode with [shadow-cljs](https://github.com/thheller/shadow-cljs) + +To start the [shadow-cljs](https://github.com/thheller/shadow-cljs) compiler run +``` +npm install +shadow-cljs watch app +``` + +Shadow-cljs automatically pushes cljs changes to the browser. The application will now be available at [http://localhost:3000](http://localhost:3000). + +### Development mode with Figwheel + +To start the Figwheel compiler (if enabled with `+figwheel` flag), navigate to the project folder and run the following command in the terminal: ``` lein figwheel ``` -To start the DevCards build run +To start the [DevCards](https://github.com/bhauman/devcards) (if enabled with `+devcards` flag) build run ``` lein figwheel devcards ``` - -Figwheel will automatically push cljs changes to the browser. The server will be available at [http://localhost:3449](http://localhost:3449) +Figwheel will also automatically push cljs changes to the browser. The server will be available at [http://localhost:3449](http://localhost:3449) once Figwheel starts up. To view your devcards, type `(switch-to-build devcards)` at the Figwheel REPL and navigate to [http://localhost:3449/cards](http://localhost:3449/cards). Figwheel also starts `nREPL` using the value of the `:nrepl-port` in the `:figwheel` @@ -80,16 +100,17 @@ The application will now be available at [http://localhost:3000](http://localhos In case of using `+less` option you may also want to run ``` -lein less auto +lein less4j auto ``` to autocompile less files. In case of using `+sass` option you may also want to run ``` -lein sass watch +lein sass4clj auto ``` to autocompile sass/scss files. + #### Optional development tools Start the browser REPL: @@ -113,14 +134,20 @@ and stopped by running: lein do clean, uberjar ``` +#### Building for release with [shadow-cljs](https://github.com/thheller/shadow-cljs) +``` +shadow-cljs release app +``` + ### Deploying to Heroku -Make sure you have [Git](http://git-scm.com/downloads) and [Heroku toolbelt](https://toolbelt.heroku.com/) installed, then simply follow the steps below. +The project generates a `system.properties` used for Heroku deployments. Make sure you have [Git](http://git-scm.com/downloads) and [Heroku toolbelt](https://toolbelt.heroku.com/) installed, then simply follow the steps below. -Optionally, test that your application runs locally with foreman by running. +Optionally, test that your application runs locally by running. ``` -foreman start +lein do clean, uberjar +heroku local ``` Now, you can initialize your git repo and commit your application. @@ -160,10 +187,10 @@ The template packages everything you need to create a production ready ClojureSc * [Reagent](https://github.com/reagent-project/reagent) - ClojureScript interface to Facebook's React * [reagent-forms](https://github.com/reagent-project/reagent-forms) - data binding library for Reagent * [reagent-utils](https://github.com/reagent-project/reagent-utils) - utilities such as session and cookie management -* [Secretary](https://github.com/gf3/secretary) - client-side routing -* [Accountant](https://github.com/venantius/accountant) - additional setup facilities for client-side routing in SPA way +* [Reitit](https://metosin.github.io/reitit/) - Routing, server and client side +* [Accountant](https://github.com/venantius/accountant) - HTML5 history management, enabling href navigation in SPAs +* [Clerk](https://github.com/PEZ/clerk) - In page navigation for SPAs. Scroll restoration, anchor targeting, and such. * [Hiccup](https://github.com/weavejester/hiccup) - server-side HTML templating -* [Compojure](https://github.com/weavejester/compojure) - a popular routing library * [Ring](https://github.com/ring-clojure/ring) - Clojure HTTP interface * [Prone](https://github.com/magnars/prone) - better exception reporting middleware for Ring * [Heroku](https://www.heroku.com/) - the template is setup to work on Heroku out of the box, simply run `git push heroku master` @@ -174,8 +201,11 @@ The template supports the following options: * `+test` - ClojureScript testing support * `+spec` - use [speclj](https://github.com/slagyr/speclj) for TDD/BDD -* `+less` - use [less](https://github.com/montoux/lein-less) for compiling Less CSS files -* `+sass` - use [sass](https://github.com/vladh/lein-sassy) for compiling Sass/Scss CSS files +* `+less` - use [less](https://github.com/Deraen/less4clj) for compiling Less CSS files +* `+sass` - use [sass](https://github.com/Deraen/sass4clj) for compiling Sass/Scss CSS files +* `+devcards` - add [Devcards](https://github.com/bhauman/devcards) support +* `+cider` - add [CIDER](https://github.com/clojure-emacs/cider) support +* `-clerk` - do not add [Clerk](https://github.com/PEZ/clerk) support ## Contributing & Customizing diff --git a/project.clj b/project.clj index c484a1a..d4ab613 100644 --- a/project.clj +++ b/project.clj @@ -1,4 +1,4 @@ -(defproject reagent/lein-template "0.9.45" +(defproject reagent/lein-template "0.10.57" :description "A Leiningen template for a ClojureScript setup with Figwheel, Austin, and Reagent." :url "https://github.com/reagent-project/reagent-template" :license {:name "MIT License" diff --git a/src/leiningen/new/reagent/LICENSE b/resources/leiningen/new/reagent/LICENSE similarity index 100% rename from src/leiningen/new/reagent/LICENSE rename to resources/leiningen/new/reagent/LICENSE diff --git a/src/leiningen/new/reagent/Procfile b/resources/leiningen/new/reagent/Procfile similarity index 100% rename from src/leiningen/new/reagent/Procfile rename to resources/leiningen/new/reagent/Procfile diff --git a/resources/leiningen/new/reagent/README.md b/resources/leiningen/new/reagent/README.md new file mode 100644 index 0000000..344261b --- /dev/null +++ b/resources/leiningen/new/reagent/README.md @@ -0,0 +1,140 @@ +# {{name}} + +This is the {{name}} project. + +## Development mode + +To start the Figwheel compiler, navigate to the project folder and run the following command in the terminal: + +``` +lein figwheel +``` +{{#devcards-hook?}} + +To start the [DevCards](https://github.com/bhauman/devcards) build, run + +``` +lein figwheel devcards +``` +{{/devcards-hook?}} + +Figwheel will automatically push cljs changes to the browser. The server will be available at [http://localhost:3449](http://localhost:3449) once Figwheel starts up. {{#devcards-hook?}} To view your devcards, type `(switch-to-build devcards)` at the Figwheel REPL and navigate to [http://localhost:3449/cards](http://localhost:3449/cards). {{/devcards-hook?}} + +Figwheel also starts `nREPL` using the value of the `:nrepl-port` in the `:figwheel` +config found in `project.clj`. By default the port is set to `7002`. + +The figwheel server can have unexpected behaviors in some situations such as when using +websockets. In this case it's recommended to run a standalone instance of a web server as follows: + +``` +lein do clean, run +``` + +The application will now be available at [http://localhost:3000](http://localhost:3000). + +{{#less-or-sass-hook?}} +### Style compilation +{{/less-or-sass-hook?}} +{{#less-hook?}} +To compile [less](https://github.com/Deraen/less4clj) sources and then watch for changes and recompile until interrupted, run +``` +lein less4j auto +``` +{{/less-hook?}} +{{#sass-hook?}} +To compile [sass](https://github.com/Deraen/sass4clj) sources and then watch for changes and recompile until interrupted, run +``` +lein sass4clj auto +``` +{{/sass-hook?}} + +### Optional development tools + +Start the browser REPL: + +``` +$ lein repl +``` +The Jetty server can be started by running: + +```clojure +(start-server) +``` +and stopped by running: +```clojure +(stop-server) +``` + +{{#test-or-spec-hook?}} +## Running the tests +{{/test-or-spec-hook?}} +{{#test-hook?}} +To run [cljs.test](https://github.com/clojure/clojurescript/blob/master/src/main/cljs/cljs/test.cljs) tests using headless chrome install karma and its plugins: + +``` +npm install -g karma-cli +npm install karma karma-cljs-test karma-chrome-launcher --save-dev +lein doo chrome-headless test once +``` + +For other environments please check [doo's documentation](https://github.com/bensu/doo#setting-up-environments). + +{{/test-hook?}} +{{#spec-hook?}} + +To run [speclj](https://github.com/slagyr/speclj) tests, please use + +``` +lein cljsbuild test +``` +{{/spec-hook?}} +{{#test-or-spec-hook?}} + +For installation instructions of PhantomJS, please see [this](http://phantomjs.org/download.html). +{{/test-or-spec-hook?}} + +## Building for release + +``` +lein do clean, uberjar +``` + +## Deploying to Heroku + +Make sure you have [Git](http://git-scm.com/downloads) and [Heroku toolbelt](https://toolbelt.heroku.com/) installed, then simply follow the steps below. + +Optionally, test that your application runs locally with foreman by running. + +``` +foreman start +``` + +Now, you can initialize your git repo and commit your application. + +``` +git init +git add . +git commit -m "init" +``` +create your app on Heroku + +``` +heroku create +``` + +optionally, create a database for the application + +``` +heroku addons:add heroku-postgresql +``` + +The connection settings can be found at your [Heroku dashboard](https://dashboard.heroku.com/apps/) under the add-ons for the app. + +deploy the application + +``` +git push heroku master +``` + +Your application should now be deployed to Heroku! +For further instructions see the [official documentation](https://devcenter.heroku.com/articles/clojure). diff --git a/resources/leiningen/new/reagent/env/dev/clj/reagent/middleware.clj b/resources/leiningen/new/reagent/env/dev/clj/reagent/middleware.clj new file mode 100644 index 0000000..9caa5d9 --- /dev/null +++ b/resources/leiningen/new/reagent/env/dev/clj/reagent/middleware.clj @@ -0,0 +1,12 @@ +(ns {{project-ns}}.middleware + (:require + [ring.middleware.content-type :refer [wrap-content-type]] + [ring.middleware.params :refer [wrap-params]] + [prone.middleware :refer [wrap-exceptions]] + [ring.middleware.reload :refer [wrap-reload]] + [ring.middleware.defaults :refer [site-defaults wrap-defaults]])) + +(def middleware + [#(wrap-defaults % site-defaults) + wrap-exceptions + wrap-reload]) diff --git a/src/leiningen/new/reagent/env/dev/clj/reagent/repl.clj b/resources/leiningen/new/reagent/env/dev/clj/reagent/repl.clj similarity index 92% rename from src/leiningen/new/reagent/env/dev/clj/reagent/repl.clj rename to resources/leiningen/new/reagent/env/dev/clj/reagent/repl.clj index 8de08e9..10409ed 100644 --- a/src/leiningen/new/reagent/env/dev/clj/reagent/repl.clj +++ b/resources/leiningen/new/reagent/env/dev/clj/reagent/repl.clj @@ -1,5 +1,6 @@ -(ns {{name}}.repl - (:use {{name}}.handler +(ns {{project-ns}}.repl + (:use {{project-ns}}.handler + figwheel-sidecar.repl-api ring.server.standalone [ring.middleware file-info file])) diff --git a/resources/leiningen/new/reagent/env/dev/clj/user.clj b/resources/leiningen/new/reagent/env/dev/clj/user.clj new file mode 100644 index 0000000..4ba997c --- /dev/null +++ b/resources/leiningen/new/reagent/env/dev/clj/user.clj @@ -0,0 +1,11 @@ +(ns user + (:require [figwheel-sidecar.repl-api :as ra])) + +(defn start-fw [] + (ra/start-figwheel!)) + +(defn stop-fw [] + (ra/stop-figwheel!)) + +(defn cljs [] + (ra/cljs-repl)) diff --git a/src/leiningen/new/reagent/env/dev/cljs/reagent/cards.cljs b/resources/leiningen/new/reagent/env/dev/cljs/reagent/cards.cljs similarity index 69% rename from src/leiningen/new/reagent/env/dev/cljs/reagent/cards.cljs rename to resources/leiningen/new/reagent/env/dev/cljs/reagent/cards.cljs index 530dbe7..57a1271 100644 --- a/src/leiningen/new/reagent/env/dev/cljs/reagent/cards.cljs +++ b/resources/leiningen/new/reagent/env/dev/cljs/reagent/cards.cljs @@ -1,7 +1,8 @@ (ns {{project-ns}}.cards (:require [reagent.core :as reagent :refer [atom]] - [reagent.session :as session] - [{{project-ns}}.core :as core]) + [reagent.dom :as rdom] + [{{project-ns}}.core :as core] + [devcards.core :as dc]) (:require-macros [devcards.core :as dc @@ -13,7 +14,7 @@ (defcard-rg home-page-card [core/home-page]) -(reagent/render [:div] (.getElementById js/document "app")) +(rdom/render [:div] (.getElementById js/document "app")) ;; remember to run 'lein figwheel devcards' and then browse to ;; http://localhost:3449/cards diff --git a/resources/leiningen/new/reagent/env/dev/cljs/reagent/dev.cljs b/resources/leiningen/new/reagent/env/dev/cljs/reagent/dev.cljs new file mode 100644 index 0000000..6b2a6d5 --- /dev/null +++ b/resources/leiningen/new/reagent/env/dev/cljs/reagent/dev.cljs @@ -0,0 +1,15 @@ +(ns ^:figwheel-no-load {{project-ns}}.dev + (:require + [{{project-ns}}.core :as core] + [devtools.core :as devtools])) + +(extend-protocol IPrintWithWriter + js/Symbol + (-pr-writer [sym writer _] + (-write writer (str "\"" (.toString sym) "\"")))) + +(devtools/install!) + +(enable-console-print!) + +(core/init!) diff --git a/resources/leiningen/new/reagent/env/prod/clj/reagent/middleware.clj b/resources/leiningen/new/reagent/env/prod/clj/reagent/middleware.clj new file mode 100644 index 0000000..a8a6f2e --- /dev/null +++ b/resources/leiningen/new/reagent/env/prod/clj/reagent/middleware.clj @@ -0,0 +1,6 @@ +(ns {{project-ns}}.middleware + (:require + [ring.middleware.defaults :refer [site-defaults wrap-defaults]])) + +(def middleware + [#(wrap-defaults % site-defaults)]) diff --git a/src/leiningen/new/reagent/env/prod/cljs/reagent/prod.cljs b/resources/leiningen/new/reagent/env/prod/cljs/reagent/prod.cljs similarity index 100% rename from src/leiningen/new/reagent/env/prod/cljs/reagent/prod.cljs rename to resources/leiningen/new/reagent/env/prod/cljs/reagent/prod.cljs diff --git a/src/leiningen/new/reagent/gitignore b/resources/leiningen/new/reagent/gitignore similarity index 65% rename from src/leiningen/new/reagent/gitignore rename to resources/leiningen/new/reagent/gitignore index f7fcc1b..4e11e91 100644 --- a/src/leiningen/new/reagent/gitignore +++ b/resources/leiningen/new/reagent/gitignore @@ -8,8 +8,11 @@ pom.xml.asc *.class /.lein-* /.nrepl-port -/resources/public/js /out /.repl *.log /.env +/.sass-cache +/node_modules +/.shadow-cljs/ +/resources/public/js/ diff --git a/resources/leiningen/new/reagent/package.json b/resources/leiningen/new/reagent/package.json new file mode 100644 index 0000000..8ed6abb --- /dev/null +++ b/resources/leiningen/new/reagent/package.json @@ -0,0 +1,9 @@ +{ + "devDependencies": { + "shadow-cljs": "^2.16.5" + }, + "dependencies":{ + "react": "^17.0.2", + "react-dom": "^17.0.2" + } +} diff --git a/resources/leiningen/new/reagent/project.clj b/resources/leiningen/new/reagent/project.clj new file mode 100644 index 0000000..e677310 --- /dev/null +++ b/resources/leiningen/new/reagent/project.clj @@ -0,0 +1,201 @@ +(defproject {{full-name}} "0.1.0-SNAPSHOT" + :description "FIXME: write description" + :url "http://example.com/FIXME" + :license {:name "Eclipse Public License" + :url "http://www.eclipse.org/legal/epl-v10.html"} + + :dependencies [[org.clojure/clojure "1.11.1"] + [ring-server "0.5.0"] + [reagent "1.1.1"] + [reagent-utils "0.3.4"] + [cljsjs/react "17.0.2-0"] + [cljsjs/react-dom "17.0.2-0"] + [ring "1.9.5"] + [ring/ring-defaults "0.3.3"] + [hiccup "1.0.5"] + [yogthos/config "1.2.0"] + [org.clojure/clojurescript "1.11.54" + :scope "provided"] + [metosin/reitit "0.5.18"] + {{#clerk-hook?}} + [pez/clerk "1.0.0"] + {{/clerk-hook?}} + [venantius/accountant "0.2.5" + :exclusions [org.clojure/tools.reader]]] + + :jvm-opts ["-Xmx1G"] + + :plugins [[lein-environ "1.1.0"] + [lein-cljsbuild "1.1.7"] + [lein-asset-minifier "0.4.6" + :exclusions [org.clojure/clojure]]] + + :ring {:handler {{project-ns}}.handler/app + :uberwar-name "{{name}}.war"} + + :min-lein-version "2.5.0" + :uberjar-name "{{name}}.jar" + :main {{project-ns}}.server + :clean-targets ^{:protect false} + [:target-path + [:cljsbuild :builds :app :compiler :output-dir] + [:cljsbuild :builds :app :compiler :output-to]] + + :source-paths ["src/clj" "src/cljc" "src/cljs"] + {{#spec-hook?}} + :test-paths ["spec/clj"] + {{/spec-hook?}} + :resource-paths ["resources" "target/cljsbuild"] + + :minify-assets + [[:css {:source "resources/public/css/site.css" + :target "resources/public/css/site.min.css"}]] + + :cljsbuild + {:builds {:min + {:source-paths ["src/cljs" "src/cljc" "env/prod/cljs"] + :compiler + {:output-to "target/cljsbuild/public/js/app.js" + :output-dir "target/cljsbuild/public/js" + :source-map "target/cljsbuild/public/js/app.js.map" + :optimizations :advanced + :infer-externs true + :pretty-print false}} + :app + {:source-paths ["src/cljs" "src/cljc" "env/dev/cljs"] + :figwheel {:on-jsload "{{project-ns}}.core/mount-root"} + :compiler + {:main "{{name}}.dev" + :asset-path "/js/out" + :output-to "target/cljsbuild/public/js/app.js" + :output-dir "target/cljsbuild/public/js/out" + :source-map true + :optimizations :none + :pretty-print true}} + {{#test-hook?}} + :test + {:source-paths ["src/cljs" "src/cljc" "test/cljs"] + :compiler {:main {{project-ns}}.doo-runner + :asset-path "/js/out" + :output-to "target/test.js" + :output-dir "target/cljstest/public/js/out" + :optimizations :whitespace + :pretty-print true}}{{/test-hook?}} + {{#spec-hook?}} + :test + {:source-paths ["src/cljs" "src/cljc" "spec/cljs"] + :compiler {:output-to "target/test.js" + :optimizations :whitespace + :pretty-print true}}{{/spec-hook?}} + {{#devcards-hook?}} + :devcards + {:source-paths ["src/cljs" "src/cljc" "env/dev/cljs"] + :figwheel {:devcards true} + :compiler {:main "{{name}}.cards" + :asset-path "js/devcards_out" + :output-to "target/cljsbuild/public/js/app_devcards.js" + :output-dir "target/cljsbuild/public/js/devcards_out" + :source-map-timestamp true + :optimizations :none + :pretty-print true}}{{/devcards-hook?}} + } + {{#spec-hook?}} + :test-commands {"unit" ["phantomjs" "runners/speclj" "target/test.js"]} + {{/spec-hook?}} + } +{{#test-hook?}} + :doo {:build "test" + :alias {:default [:chrome]}} +{{/test-hook?}} +{{#spec-hook?}} + :doo {:build "test"} + {{/spec-hook?}} + + :figwheel + {:http-server-root "public" + :server-port 3449 + :nrepl-port 7002 + :nrepl-middleware [cider.piggieback/wrap-cljs-repl + {{#cider-hook?}} + cider.nrepl/cider-middleware + refactor-nrepl.middleware/wrap-refactor + {{/cider-hook?}} + ] + :css-dirs ["resources/public/css"] + :ring-handler {{project-ns}}.handler/app} + + {{#less-hook?}} + :less {:source-paths ["src/less"] + :target-path "resources/public/css"} + {{/less-hook?}} + + {{#sass-hook?}} + :sass {:source-paths ["src/sass"] + :target-path "resources/public/css"} + {{/sass-hook?}} + + :profiles {:dev {:repl-options {:init-ns {{project-ns}}.repl} + :dependencies [[cider/piggieback "0.5.3"] + [binaryage/devtools "1.0.6"] + [ring/ring-mock "0.4.0"] + [ring/ring-devel "1.9.5"] + [prone "2021-04-23"] + [figwheel-sidecar "0.5.20"] + [nrepl "0.9.0"] + {{#shadow-cljs-hook?}} + [thheller/shadow-cljs "2.16.7"] + {{/shadow-cljs-hook?}} + {{#spec-hook?}} + [speclj "3.3.2"] + {{/spec-hook?}} + {{#devcards-hook?}} + [devcards "0.2.6" :exclusions [cljsjs/react]] + {{/devcards-hook?}} + [pjstadig/humane-test-output "0.11.0"] + {{dev-dependencies}} + {{#less-hook?}} + ;; To silence warnings from less4clj dependecies about missing logger implementation + [org.slf4j/slf4j-nop "1.7.25"] + {{/less-hook?}} + {{#sass-hook?}} + ;; To silence warnings from sass4clj dependecies about missing logger implementation + [org.slf4j/slf4j-nop "1.7.25"] + {{/sass-hook?}} ] + + :source-paths ["env/dev/clj"] + :plugins [[lein-figwheel "0.5.20"] + {{#test-hook?}} + [lein-doo "0.1.10"] + {{/test-hook?}} + {{#spec-hook?}} + [speclj "3.3.2"] + {{/spec-hook?}} + {{#cider-hook?}} + [cider/cider-nrepl "0.21.1"] + [org.clojure/tools.namespace "0.3.0-alpha4" + :exclusions [org.clojure/tools.reader]] + [refactor-nrepl "2.4.0" + :exclusions [org.clojure/clojure]] + {{/cider-hook?}} + {{#less-hook?}} + [deraen/lein-less4j "0.6.2"] + {{/less-hook?}} + {{#sass-hook?}} + [deraen/lein-sass4clj "0.3.1"] + {{/sass-hook?}}] + + :injections [(require 'pjstadig.humane-test-output) + (pjstadig.humane-test-output/activate!)] + + :env {:dev true}} + + {{#shadow-cljs-hook?}} + :shadow-cljs {:dependencies [[com.google.javascript/closure-compiler-unshaded "v20211201"]]} + {{/shadow-cljs-hook?}} + + :uberjar {:hooks [minify-assets.plugin/hooks] + :source-paths ["env/prod/clj"] + :prep-tasks ["compile" ["cljsbuild" "once" "min"]] + :env {:production true} + :aot :all + :omit-source true}}) diff --git a/src/leiningen/new/reagent/resources/public/css/site.css b/resources/leiningen/new/reagent/resources/public/css/site.css similarity index 91% rename from src/leiningen/new/reagent/resources/public/css/site.css rename to resources/leiningen/new/reagent/resources/public/css/site.css index b3e8203..f5bdfaf 100644 --- a/src/leiningen/new/reagent/resources/public/css/site.css +++ b/resources/leiningen/new/reagent/resources/public/css/site.css @@ -1,6 +1,6 @@ -body { +.body-container { font-family: 'Helvetica Neue', Verdana, Helvetica, Arial, sans-serif; - max-width: 600px; + max-width: 640px; margin: 0 auto; padding-top: 72px; -webkit-font-smoothing: antialiased; diff --git a/src/leiningen/new/reagent/runners/doo_runner.cljs b/resources/leiningen/new/reagent/runners/doo_runner.cljs similarity index 100% rename from src/leiningen/new/reagent/runners/doo_runner.cljs rename to resources/leiningen/new/reagent/runners/doo_runner.cljs diff --git a/src/leiningen/new/reagent/runners/speclj b/resources/leiningen/new/reagent/runners/speclj similarity index 100% rename from src/leiningen/new/reagent/runners/speclj rename to resources/leiningen/new/reagent/runners/speclj diff --git a/resources/leiningen/new/reagent/shadow-cljs.edn b/resources/leiningen/new/reagent/shadow-cljs.edn new file mode 100644 index 0000000..09bcba8 --- /dev/null +++ b/resources/leiningen/new/reagent/shadow-cljs.edn @@ -0,0 +1,7 @@ +{:lein {:profile "+shadow-cljs"} + :builds {:app {:target :browser + :output-dir "resources/public/js" + :asset-path "/js" + :modules {:app {:init-fn {{project-ns}}.core/init!}}}} + :dev-http {3000 {:root "resources/public" + :handler {{project-ns}}.handler/app}}} diff --git a/src/leiningen/new/reagent/spec/cljs/reagent/core_spec.cljs b/resources/leiningen/new/reagent/spec/cljs/reagent/core_spec.cljs similarity index 87% rename from src/leiningen/new/reagent/spec/cljs/reagent/core_spec.cljs rename to resources/leiningen/new/reagent/spec/cljs/reagent/core_spec.cljs index 5c96e43..d18e7c2 100644 --- a/src/leiningen/new/reagent/spec/cljs/reagent/core_spec.cljs +++ b/resources/leiningen/new/reagent/spec/cljs/reagent/core_spec.cljs @@ -2,6 +2,7 @@ (:require-macros [speclj.core :refer [describe it should= should should-not]]) (:require [speclj.core] [reagent.core :as reagent :refer [atom]] + [reagent.dom :as rdom] [{{project-ns}}.core :as rc])) @@ -20,9 +21,9 @@ (defn with-mounted-component [comp f] (when isClient (let [div (add-test-div "_testreagent")] - (let [comp (reagent/render-component comp div #(f comp div))] - (reagent/unmount-component-at-node div) - (reagent/flush) + (let [comp (rdom/render comp div #(f comp div))] + (rdom/unmount-component-at-node div) + (rflush) (.removeChild (.-body js/document) div))))) diff --git a/resources/leiningen/new/reagent/src/clj/reagent/handler.clj b/resources/leiningen/new/reagent/src/clj/reagent/handler.clj new file mode 100644 index 0000000..08d836e --- /dev/null +++ b/resources/leiningen/new/reagent/src/clj/reagent/handler.clj @@ -0,0 +1,65 @@ +(ns {{project-ns}}.handler + (:require + [reitit.ring :as reitit-ring] + [{{project-ns}}.middleware :refer [middleware]] + [hiccup.page :refer [include-js include-css html5]] + [config.core :refer [env]])) + +(def mount-target + [:div#app + [:h2 "Welcome to {{name}}"] + [:p "please wait while Figwheel{{#shadow-cljs-hook?}}/shadow-cljs{{/shadow-cljs-hook?}} is waking up ..."] + [:p "(Check the js console for hints if nothing exciting happens.)"]]) + +(defn head [] + [:head + [:meta {:charset "utf-8"}] + [:meta {:name "viewport" + :content "width=device-width, initial-scale=1"}] + (include-css (if (env :dev) "/css/site.css" "/css/site.min.css"))]) + +(defn loading-page [] + (html5 + (head) + [:body {:class "body-container"} + mount-target + (include-js "/js/app.js")])) + +{{#devcards-hook?}} + +(defn cards-page [] + (html5 + (head) + [:body + mount-target + (include-js "/js/app_devcards.js")])) +{{/devcards-hook?}} + +(defn index-handler + [_request] + {:status 200 + :headers {"Content-Type" "text/html"} + :body (loading-page)}) + {{#devcards-hook?}} + +(defn cards-handler + [_] + {:status 200 + :headers {"Content-Type" "text/html"} + :body (cards-page)}) +{{/devcards-hook?}} + +(def app + (reitit-ring/ring-handler + (reitit-ring/router + [["/" {:get {:handler index-handler}}] + ["/items" + ["" {:get {:handler index-handler}}] + ["/:item-id" {:get {:handler index-handler + :parameters {:path {:item-id int?}}}}]] + ["/about" {:get {:handler index-handler}}]{{#devcards-hook?}} + ["/cards" {:get {:handler cards-handler}}]{{/devcards-hook?}}]) + (reitit-ring/routes + (reitit-ring/create-resource-handler {:path "/" :root "/public"}) + (reitit-ring/create-default-handler)) + {:middleware middleware})) diff --git a/resources/leiningen/new/reagent/src/clj/reagent/server.clj b/resources/leiningen/new/reagent/src/clj/reagent/server.clj new file mode 100644 index 0000000..83560db --- /dev/null +++ b/resources/leiningen/new/reagent/src/clj/reagent/server.clj @@ -0,0 +1,10 @@ +(ns {{project-ns}}.server + (:require + [{{project-ns}}.handler :refer [app]] + [config.core :refer [env]] + [ring.adapter.jetty :refer [run-jetty]]) + (:gen-class)) + +(defn -main [& args] + (let [port (or (env :port) 3000)] + (run-jetty #'app {:port port :join? false}))) diff --git a/src/leiningen/new/reagent/src/cljc/reagent/util.cljc b/resources/leiningen/new/reagent/src/cljc/reagent/util.cljc similarity index 100% rename from src/leiningen/new/reagent/src/cljc/reagent/util.cljc rename to resources/leiningen/new/reagent/src/cljc/reagent/util.cljc diff --git a/resources/leiningen/new/reagent/src/cljs/reagent/core.cljs b/resources/leiningen/new/reagent/src/cljs/reagent/core.cljs new file mode 100644 index 0000000..b0a499b --- /dev/null +++ b/resources/leiningen/new/reagent/src/cljs/reagent/core.cljs @@ -0,0 +1,122 @@ +(ns {{project-ns}}.core + (:require + [reagent.core :as reagent :refer [atom]] + [reagent.dom :as rdom] + [reagent.session :as session] + [reitit.frontend :as reitit] + {{#clerk-hook?}}[clerk.core :as clerk]{{/clerk-hook?}} + [accountant.core :as accountant])) + +;; ------------------------- +;; Routes + +(def router + (reitit/router + [["/" :index] + ["/items" + ["" :items] + ["/:item-id" :item]] + ["/about" :about]])) + +(defn path-for [route & [params]] + (if params + (:path (reitit/match-by-name router route params)) + (:path (reitit/match-by-name router route)))) + +;; ------------------------- +;; Page components + +(defn home-page [] + (fn [] + [:span.main + [:h1 "Welcome to {{name}}"] + [:ul + [:li [:a {:href (path-for :items)} "Items of {{name}}"]] + [:li [:a {:href "/broken/link"} "Broken link"]]]])) + + + +(defn items-page [] + (fn [] + [:span.main + [:h1 "The items of {{name}}"] + [:ul (map (fn [item-id] + [:li {:name (str "item-" item-id) :key (str "item-" item-id)} + [:a {:href (path-for :item {:item-id item-id})} "Item: " item-id]]) + (range 1 60))]])) + + +(defn item-page [] + (fn [] + (let [routing-data (session/get :route) + item (get-in routing-data [:route-params :item-id])] + [:span.main + [:h1 (str "Item " item " of {{name}}")] + [:p [:a {:href (path-for :items)} "Back to the list of items"]]]))) + + +(defn about-page [] + (fn [] [:span.main + [:h1 "About {{name}}"]])) + + +;; ------------------------- +;; Translate routes -> page components + +(defn page-for [route] + (case route + :index #'home-page + :about #'about-page + :items #'items-page + :item #'item-page)) + + +;; ------------------------- +;; Page mounting component + +(defn current-page [] + (fn [] + (let [page (:current-page (session/get :route))] + [:div + [:header + [:p [:a {:href (path-for :index)} "Home"] " | " + [:a {:href (path-for :about)} "About {{name}}"]]] + [page] + [:footer + [:p "{{name}} was generated by the " + [:a {:href "https://github.com/reagent-project/reagent-template"} "Reagent Template"] "."]]]))) + +;; ------------------------- +;; Initialize app + +(defn mount-root [] + (rdom/render [current-page] (.getElementById js/document "app"))) + +(defn init! [] + {{#clerk-hook?}} + (clerk/initialize!) + {{/clerk-hook?}} + (accountant/configure-navigation! + {:nav-handler + (fn [path] + (let [match (reitit/match-by-path router path) + current-page (:name (:data match)) + route-params (:path-params match)] + {{#clerk-hook?}} + (reagent/after-render clerk/after-render!) + {{/clerk-hook?}} + (session/put! :route {:current-page (page-for current-page) + :route-params route-params}) + {{#clerk-hook?}} + (clerk/navigate-page! path) + {{/clerk-hook?}})) + :path-exists? + (fn [path] + (boolean (reitit/match-by-path router path)))}) + (accountant/dispatch-current!) + (mount-root)) + +{{#shadow-cljs-hook?}} +(defn ^:dev/after-load reload! [] + (mount-root)) +{{/shadow-cljs-hook?}} \ No newline at end of file diff --git a/resources/leiningen/new/reagent/src/less/profile.less b/resources/leiningen/new/reagent/src/less/profile.less new file mode 100644 index 0000000..8b13789 --- /dev/null +++ b/resources/leiningen/new/reagent/src/less/profile.less @@ -0,0 +1 @@ + diff --git a/src/leiningen/new/reagent/src/less/site.less b/resources/leiningen/new/reagent/src/less/site.main.less similarity index 72% rename from src/leiningen/new/reagent/src/less/site.less rename to resources/leiningen/new/reagent/src/less/site.main.less index b3e8203..fa28d81 100644 --- a/src/leiningen/new/reagent/src/less/site.less +++ b/resources/leiningen/new/reagent/src/less/site.main.less @@ -1,3 +1,8 @@ +// Less4clj considers files ending in .main.less entrypoints, i.e. they are compiled to .css files +// Other files can be included using @import: + +// @import "profile"; + body { font-family: 'Helvetica Neue', Verdana, Helvetica, Arial, sans-serif; max-width: 600px; diff --git a/src/leiningen/new/reagent/src/sass/profile.scss b/resources/leiningen/new/reagent/src/sass/_profile.scss similarity index 100% rename from src/leiningen/new/reagent/src/sass/profile.scss rename to resources/leiningen/new/reagent/src/sass/_profile.scss diff --git a/resources/leiningen/new/reagent/src/sass/site.scss b/resources/leiningen/new/reagent/src/sass/site.scss new file mode 100644 index 0000000..df1fe84 --- /dev/null +++ b/resources/leiningen/new/reagent/src/sass/site.scss @@ -0,0 +1,46 @@ +// Files not starting with _ are consided entrypoints, i.e. they are compiled to .css files +// Partials (files starting with _) can be inclued using @import: +// (import path can include _ but it is not needed) + +// @import 'profile'; + +// You can use any sass features, like variables, for instance: +$font-stack: 'Helvetica Neue', Verdana, Helvetica, Arial, sans-serif; +$base-font-size: 1.125em; + +.body-container { + font-family: $font-stack; + max-width: 600px; + margin: 0 auto; + padding-top: 72px; + -webkit-font-smoothing: antialiased; + font-size: $base-font-size; + color: #333; + line-height: 1.5em; +} + +h1, h2, h3 { + color: #000; +} + +h1 { + font-size: $base-font-size + 1.375; +} + +h2 { + font-size: $base-font-size + 0.875; +} + +h3 { + font-size: $base-font-size + 0.125; +} + +a { + text-decoration: none; + color: #09f; + + // nesting is also supported + &:hover { + text-decoration: underline; + } +} diff --git a/src/leiningen/new/reagent/system.properties b/resources/leiningen/new/reagent/system.properties similarity index 100% rename from src/leiningen/new/reagent/system.properties rename to resources/leiningen/new/reagent/system.properties diff --git a/src/leiningen/new/reagent/test/cljs/reagent/core_test.cljs b/resources/leiningen/new/reagent/test/cljs/reagent/core_test.cljs similarity index 71% rename from src/leiningen/new/reagent/test/cljs/reagent/core_test.cljs rename to resources/leiningen/new/reagent/test/cljs/reagent/core_test.cljs index ad7792d..99a7c35 100644 --- a/src/leiningen/new/reagent/test/cljs/reagent/core_test.cljs +++ b/resources/leiningen/new/reagent/test/cljs/reagent/core_test.cljs @@ -1,7 +1,9 @@ (ns {{project-ns}}.core-test - (:require [cljs.test :refer-macros [is are deftest testing use-fixtures]] - [reagent.core :as reagent :refer [atom]] - [{{project-ns}}.core :as rc])) + (:require + [cljs.test :refer-macros [is are deftest testing use-fixtures]] + [reagent.core :as reagent :refer [atom]] + [reagent.dom :as rdom] + [{{project-ns}}.core :as rc])) (def isClient (not (nil? (try (.-document js/window) @@ -19,9 +21,9 @@ (defn with-mounted-component [comp f] (when isClient (let [div (add-test-div "_testreagent")] - (let [comp (reagent/render-component comp div #(f comp div))] - (reagent/unmount-component-at-node div) - (reagent/flush) + (let [comp (rdom/render comp div #(f comp div))] + (rdom/unmount-component-at-node div) + (rflush) (.removeChild (.-body js/document) div))))) diff --git a/src/leiningen/new/reagent/vendor/console-polyfill.js b/resources/leiningen/new/reagent/vendor/console-polyfill.js similarity index 100% rename from src/leiningen/new/reagent/vendor/console-polyfill.js rename to resources/leiningen/new/reagent/vendor/console-polyfill.js diff --git a/src/leiningen/new/reagent/vendor/es5-sham.js b/resources/leiningen/new/reagent/vendor/es5-sham.js similarity index 100% rename from src/leiningen/new/reagent/vendor/es5-sham.js rename to resources/leiningen/new/reagent/vendor/es5-sham.js diff --git a/src/leiningen/new/reagent/vendor/es5-shim.js b/resources/leiningen/new/reagent/vendor/es5-shim.js similarity index 100% rename from src/leiningen/new/reagent/vendor/es5-shim.js rename to resources/leiningen/new/reagent/vendor/es5-shim.js diff --git a/src/leiningen/new/reagent.clj b/src/leiningen/new/reagent.clj index 164f3f6..868663e 100644 --- a/src/leiningen/new/reagent.clj +++ b/src/leiningen/new/reagent.clj @@ -3,7 +3,7 @@ :refer [renderer name-to-path ->files sanitize sanitize-ns project-name]] [leiningen.core.main :as main] - [clojure.string :refer [join]])) + [clojure.string :as string])) (def render (renderer "reagent")) @@ -11,18 +11,12 @@ (fn [] (->> list (map #(str "\n" (apply str (repeat n " ")) (wrap %))) - (join "")))) - -(defn dep-list [n list] - (wrap-indent #(str "[" % "]") n list)) + (string/join "")))) (defn indent [n list] (wrap-indent identity n list)) -(def valid-opts ["+test" "+spec" "+less" "+sass" "+devcards" "+cider"]) - -(defn valid-opts? [opts] - (every? #(some #{%} valid-opts) opts)) +(def valid-opts ["+test" "+spec" "+less" "+sass" "+devcards" "+cider" "+figwheel" "-clerk"]) (defn less? [opts] (some #{"+less"} opts)) @@ -30,9 +24,6 @@ (defn sass? [opts] (some #{"+sass"} opts)) -(def less-plugin "lein-less \"1.7.5\"") -(def sass-plugin "lein-sassy \"1.0.7\"") - (defn test? [opts] (some #{"+test"} opts)) @@ -45,10 +36,25 @@ (defn cider? [opts] (some #{"+cider"} opts)) -(defn project-plugins [opts] - (cond-> [] - (less? opts) (conj less-plugin) - (sass? opts) (conj sass-plugin))) +(defn figwheel? [opts] + (some #{"+figwheel"} opts)) + +(defn clerk? [opts] + (not (some #{"-clerk"} opts))) + +(defn validate-opts [opts] + (let [invalid-opts (remove (set valid-opts) opts)] + (cond + (seq invalid-opts) + (str "invalid options supplied: " (string/join " " invalid-opts) + "\nvalid options are: " (string/join " " valid-opts)) + + (and (test? opts) (spec? opts)) "Both +test and +spec options can't be used together, select one."))) + +(defn jvm>8? [] + (try + (> (Double/parseDouble (subs (System/getProperty "java.version") 0 3)) 1.8) + (catch Exception _))) (defn template-data [name opts] {:full-name name @@ -56,25 +62,27 @@ :project-goog-module (sanitize (sanitize-ns name)) :project-ns (sanitize-ns name) :sanitized (name-to-path name) - :project-dev-plugins (dep-list 29 (project-plugins opts)) - ;; test :test-hook? (fn [block] (if (test? opts) (str block "") "")) - - ;; spec :spec-hook? (fn [block] (if (spec? opts) (str block "") "")) - ;; less + :test-or-spec-hook? + (fn [block] (if (or (test? opts) (spec? opts)) (str block "") "")) + :less-hook? (fn [block] (if (less? opts) (str block "") "")) - ;; sass :sass-hook? (fn [block] (if (sass? opts) (str block "") "")) - ;; devcards + :less-or-sass-hook? + (fn [block] (if (or (less? opts) (sass? opts)) (str block "") "")) + :devcards-hook? (fn [block] (if (devcards? opts) (str block "") "")) - ;; cider - :cider-hook? (fn [block] (if (cider? opts) (str block "") ""))}) + :cider-hook? (fn [block] (if (cider? opts) (str block "") "")) + + :shadow-cljs-hook? (fn [block] (if (figwheel? opts) "" (str block ""))) + + :clerk-hook? (fn [block] (if (clerk? opts) (str block "") ""))}) (defn format-files-args [name opts] (let [data (template-data name opts) @@ -86,15 +94,16 @@ ["env/prod/clj/{{sanitized}}/middleware.clj" (render "env/prod/clj/reagent/middleware.clj" data)] ["env/dev/clj/{{sanitized}}/middleware.clj" (render "env/dev/clj/reagent/middleware.clj" data)] ["env/dev/clj/{{sanitized}}/repl.clj" (render "env/dev/clj/reagent/repl.clj" data)] + ["env/dev/clj/user.clj" (render "env/dev/clj/user.clj" data)] ["src/cljs/{{sanitized}}/core.cljs" (render "src/cljs/reagent/core.cljs" data)] ["src/cljc/{{sanitized}}/util.cljc" (render "src/cljc/reagent/util.cljc" data)] ["env/dev/cljs/{{sanitized}}/dev.cljs" (render "env/dev/cljs/reagent/dev.cljs" data)] ["env/prod/cljs/{{sanitized}}/prod.cljs" (render "env/prod/cljs/reagent/prod.cljs" data)] - ["LICENSE" (render "LICENSE" data)] + #_["LICENSE" (render "LICENSE" data)] ["README.md" (render "README.md" data)] [".gitignore" (render "gitignore" data)] ;; Heroku support - ["system.properties" (render "system.properties" data)] + ["system.properties" (render "system.properties" data)] ["Procfile" (render "Procfile" data)]] args (if (test? opts) (conj args ["test/cljs/{{sanitized}}/core_test.cljs" (render "test/cljs/reagent/core_test.cljs" data)] @@ -108,21 +117,27 @@ ["runners/speclj" (render "runners/speclj" data)]) args) args (if (less? opts) - (conj args ["src/less/site.less" (render "src/less/site.less" data)]) + (conj args + ["src/less/site.main.less" (render "src/less/site.main.less" data)] + ["src/less/profile.less" (render "src/less/profile.less" data)]) args) args (if (sass? opts) (conj args - ["src/sass/index.sass" (render "src/sass/index.sass" data)] - ["src/sass/profile.scss" (render "src/sass/profile.scss" data)]) + ["src/sass/site.scss" (render "src/sass/site.scss" data)] + ["src/sass/_profile.scss" (render "src/sass/_profile.scss" data)]) args) args (if (devcards? opts) (conj args ["env/dev/cljs/{{sanitized}}/cards.cljs" (render "env/dev/cljs/reagent/cards.cljs" data)]) - args)] + args) + args (if (figwheel? opts) + args + (conj args + ["shadow-cljs.edn" (render "shadow-cljs.edn" data)] + ["package.json" (render "package.json" data)]))] args)) (defn reagent [name & opts] (main/info "Generating fresh 'lein new' Reagent project.") - (if-not (valid-opts? opts) - (println "invalid options supplied:" (clojure.string/join " " opts) - "\nvalid options are:" (join " " valid-opts)) + (if-let [error (validate-opts opts)] + (println error) (apply ->files (format-files-args name opts)))) diff --git a/src/leiningen/new/reagent/README.md b/src/leiningen/new/reagent/README.md deleted file mode 100644 index e69de29..0000000 diff --git a/src/leiningen/new/reagent/env/dev/clj/reagent/middleware.clj b/src/leiningen/new/reagent/env/dev/clj/reagent/middleware.clj deleted file mode 100644 index 10082ca..0000000 --- a/src/leiningen/new/reagent/env/dev/clj/reagent/middleware.clj +++ /dev/null @@ -1,10 +0,0 @@ -(ns {{name}}.middleware - (:require [ring.middleware.defaults :refer [site-defaults wrap-defaults]] - [prone.middleware :refer [wrap-exceptions]] - [ring.middleware.reload :refer [wrap-reload]])) - -(defn wrap-middleware [handler] - (-> handler - (wrap-defaults site-defaults) - wrap-exceptions - wrap-reload)) diff --git a/src/leiningen/new/reagent/env/dev/cljs/reagent/dev.cljs b/src/leiningen/new/reagent/env/dev/cljs/reagent/dev.cljs deleted file mode 100644 index bf497ce..0000000 --- a/src/leiningen/new/reagent/env/dev/cljs/reagent/dev.cljs +++ /dev/null @@ -1,11 +0,0 @@ -(ns ^:figwheel-no-load {{project-ns}}.dev - (:require [{{project-ns}}.core :as core] - [figwheel.client :as figwheel :include-macros true])) - -(enable-console-print!) - -(figwheel/watch-and-reload - :websocket-url "ws://localhost:3449/figwheel-ws" - :jsload-callback core/mount-root) - -(core/init!) diff --git a/src/leiningen/new/reagent/env/prod/clj/reagent/middleware.clj b/src/leiningen/new/reagent/env/prod/clj/reagent/middleware.clj deleted file mode 100644 index dacd1df..0000000 --- a/src/leiningen/new/reagent/env/prod/clj/reagent/middleware.clj +++ /dev/null @@ -1,5 +0,0 @@ -(ns {{name}}.middleware - (:require [ring.middleware.defaults :refer [site-defaults wrap-defaults]])) - -(defn wrap-middleware [handler] - (wrap-defaults handler site-defaults)) diff --git a/src/leiningen/new/reagent/project.clj b/src/leiningen/new/reagent/project.clj deleted file mode 100644 index 611efa8..0000000 --- a/src/leiningen/new/reagent/project.clj +++ /dev/null @@ -1,182 +0,0 @@ -(defproject {{full-name}} "0.1.0-SNAPSHOT" - :description "FIXME: write description" - :url "http://example.com/FIXME" - :license {:name "Eclipse Public License" - :url "http://www.eclipse.org/legal/epl-v10.html"} - - :dependencies [[org.clojure/clojure "1.8.0"] - [ring-server "0.4.0"] - [reagent "0.5.1" - :exclusions [org.clojure/tools.reader]] - [reagent-forms "0.5.15"] - [reagent-utils "0.1.7"] - [ring "1.4.0"] - [ring/ring-defaults "0.1.5"] - [compojure "1.4.0"] - [hiccup "1.0.5"] - [environ "1.0.2"] - [org.clojure/clojurescript "1.7.228" :scope "provided"] - [secretary "1.2.3"] - [venantius/accountant "0.1.6" - :exclusions [org.clojure/tools.reader]]] - - :plugins [[lein-environ "1.0.2"] - [lein-cljsbuild "1.1.1"] - [lein-asset-minifier "0.2.4" - :exclusions [org.clojure/clojure]]] - - :ring {:handler {{project-ns}}.handler/app - :uberwar-name "{{name}}.war"} - - :min-lein-version "2.5.0" - - :uberjar-name "{{name}}.jar" - - :main {{project-ns}}.server - - :clean-targets ^{:protect false} [:target-path - [:cljsbuild :builds :app :compiler :output-dir] - [:cljsbuild :builds :app :compiler :output-to]] - - :source-paths ["src/clj" "src/cljc"] - {{#spec-hook?}} - :test-paths ["spec/clj"] - {{/spec-hook?}} - :resource-paths ["resources" "target/cljsbuild"] - - :minify-assets - {:assets - {"resources/public/css/site.min.css" "resources/public/css/site.css"}} - - :cljsbuild {:builds {:app {:source-paths ["src/cljs" "src/cljc"] - :compiler {:output-to "target/cljsbuild/public/js/app.js" - :output-dir "target/cljsbuild/public/js/out" - :asset-path "js/out" - :optimizations :none - :pretty-print true}}}} - {{#less-hook?}} - :less {:source-paths ["src/less"] - :target-path "resources/public/css"} - {{/less-hook?}} - - {{#sass-hook?}} - :sass {:src "src/sass" - :dst "resources/public/css"} - {{/sass-hook?}} - - :profiles {:dev {:repl-options {:init-ns {{project-ns}}.repl} - - :dependencies [[ring/ring-mock "0.3.0"] - [ring/ring-devel "1.4.0"] - [prone "1.0.1"] - [lein-figwheel "0.5.0-6" - :exclusions [org.clojure/core.memoize - ring/ring-core - org.clojure/clojure - org.ow2.asm/asm-all - org.clojure/data.priority-map - org.clojure/tools.reader - org.clojure/clojurescript - org.clojure/core.async - org.clojure/tools.analyzer.jvm]] - [org.clojure/clojurescript "1.7.170" - :exclusions [org.clojure/clojure org.clojure/tools.reader]] - [org.clojure/tools.nrepl "0.2.12"] - [com.cemerick/piggieback "0.2.1"] - {{#test-hook?}} - [lein-doo "0.1.6"] - {{/test-hook?}} - {{#spec-hook?}} - [speclj "3.3.1"] - {{/spec-hook?}} - {{#devcards-hook?}} - [devcards "0.2.0-8" - :exclusions [org.clojure/tools.reader]] - {{/devcards-hook?}} - [pjstadig/humane-test-output "0.7.1"] - {{dev-dependencies}}] - - :source-paths ["env/dev/clj"] - :plugins [[lein-figwheel "0.5.0-6" - :exclusions [org.clojure/core.memoize - ring/ring-core - org.clojure/clojure - org.ow2.asm/asm-all - org.clojure/data.priority-map - org.clojure/tools.reader - org.clojure/clojurescript - org.clojure/core.async - org.clojure/tools.analyzer.jvm]] - [org.clojure/clojurescript "1.7.228"] - {{#test-hook?}} - [lein-doo "0.1.6"] - {{/test-hook?}} - {{#spec-hook?}} - [speclj "3.3.1"] - {{/spec-hook?}} - {{#cider-hook?}} - [cider/cider-nrepl "0.10.0-SNAPSHOT"] - [org.clojure/tools.namespace "0.3.0-alpha2" - :exclusions [org.clojure/tools.reader]] - [refactor-nrepl "2.0.0-SNAPSHOT" - :exclusions [org.clojure/clojure]] - {{/cider-hook?}} - {{{project-dev-plugins}}}] - - :injections [(require 'pjstadig.humane-test-output) - (pjstadig.humane-test-output/activate!)] - - :figwheel {:http-server-root "public" - :server-port 3449 - :nrepl-port 7002 - :nrepl-middleware ["cemerick.piggieback/wrap-cljs-repl" - {{#cider-hook?}} - "cider.nrepl/cider-middleware" - "refactor-nrepl.middleware/wrap-refactor" - {{/cider-hook?}} - ] - :css-dirs ["resources/public/css"] - :ring-handler {{project-ns}}.handler/app} - - :env {:dev true} - - :cljsbuild {:builds {:app {:source-paths ["env/dev/cljs"] - :compiler {:main "{{name}}.dev" - :source-map true}} - {{#test-hook?}} - :test {:source-paths ["src/cljs" "src/cljc" "test/cljs"] - :compiler {:output-to "target/test.js" - :main {{project-ns}}.doo-runner - :optimizations :whitespace - :pretty-print true}}{{/test-hook?}} - {{#spec-hook?}} - :test {:source-paths ["src/cljs" "src/cljc" "spec/cljs"] - :compiler {:output-to "target/test.js" - :optimizations :whitespace - :pretty-print true}}{{/spec-hook?}} - {{#devcards-hook?}} - :devcards {:source-paths ["src/cljs" "src/cljc" "env/dev/cljs"] - :figwheel {:devcards true} - :compiler {:main "{{name}}.cards" - :asset-path "js/devcards_out" - :output-to "target/cljsbuild/public/js/app_devcards.js" - :output-dir "target/cljsbuild/public/js/devcards_out" - :source-map-timestamp true}}{{/devcards-hook?}} - } - {{#spec-hook?}} - :test-commands {"unit" ["phantomjs" "runners/speclj" "target/test.js"]} - {{/spec-hook?}} - }} - - :uberjar {:hooks [minify-assets.plugin/hooks] - :source-paths ["env/prod/clj"] - :prep-tasks ["compile" ["cljsbuild" "once"]] - :env {:production true} - :aot :all - :omit-source true - :cljsbuild {:jar true - :builds {:app - {:source-paths ["env/prod/cljs"] - :compiler - {:optimizations :advanced - :pretty-print false}}}}}}) diff --git a/src/leiningen/new/reagent/src/clj/reagent/handler.clj b/src/leiningen/new/reagent/src/clj/reagent/handler.clj deleted file mode 100644 index 8e5f89a..0000000 --- a/src/leiningen/new/reagent/src/clj/reagent/handler.clj +++ /dev/null @@ -1,42 +0,0 @@ -(ns {{project-ns}}.handler - (:require [compojure.core :refer [GET defroutes]] - [compojure.route :refer [not-found resources]] - [hiccup.page :refer [include-js include-css html5]] - [{{name}}.middleware :refer [wrap-middleware]] - [environ.core :refer [env]])) - -(def mount-target - [:div#app - [:h3 "ClojureScript has not been compiled!"] - [:p "please run " - [:b "lein figwheel"] - " in order to start the compiler"]]) - -(def loading-page - (html5 - [:head - [:meta {:charset "utf-8"}] - [:meta {:name "viewport" - :content "width=device-width, initial-scale=1"}] - (include-css (if (env :dev) "css/site.css" "css/site.min.css"))] - [:body - mount-target - (include-js "js/app.js")])) -{{#devcards-hook?}} - -(def cards-page - (html5 - [:head - [:meta {:charset "utf-8"}]] - [:body - mount-target - (include-js "js/app_devcards.js")])){{/devcards-hook?}} - -(defroutes routes - (GET "/" [] loading-page) - (GET "/about" [] loading-page) - {{#devcards-hook?}}(GET "/cards" [] cards-page){{/devcards-hook?}} - (resources "/") - (not-found "Not Found")) - -(def app (wrap-middleware #'routes)) diff --git a/src/leiningen/new/reagent/src/clj/reagent/server.clj b/src/leiningen/new/reagent/src/clj/reagent/server.clj deleted file mode 100644 index c460d15..0000000 --- a/src/leiningen/new/reagent/src/clj/reagent/server.clj +++ /dev/null @@ -1,9 +0,0 @@ -(ns {{project-ns}}.server - (:require [{{project-ns}}.handler :refer [app]] - [environ.core :refer [env]] - [ring.adapter.jetty :refer [run-jetty]]) - (:gen-class)) - - (defn -main [& args] - (let [port (Integer/parseInt (or (env :port) "3000"))] - (run-jetty app {:port port :join? false}))) diff --git a/src/leiningen/new/reagent/src/cljs/reagent/core.cljs b/src/leiningen/new/reagent/src/cljs/reagent/core.cljs deleted file mode 100644 index fffcf4d..0000000 --- a/src/leiningen/new/reagent/src/cljs/reagent/core.cljs +++ /dev/null @@ -1,39 +0,0 @@ -(ns {{project-ns}}.core - (:require [reagent.core :as reagent :refer [atom]] - [reagent.session :as session] - [secretary.core :as secretary :include-macros true] - [accountant.core :as accountant])) - -;; ------------------------- -;; Views - -(defn home-page [] - [:div [:h2 "Welcome to {{name}}"] - [:div [:a {:href "/about"} "go to about page"]]]) - -(defn about-page [] - [:div [:h2 "About {{name}}"] - [:div [:a {:href "/"} "go to the home page"]]]) - -(defn current-page [] - [:div [(session/get :current-page)]]) - -;; ------------------------- -;; Routes - -(secretary/defroute "/" [] - (session/put! :current-page #'home-page)) - -(secretary/defroute "/about" [] - (session/put! :current-page #'about-page)) - -;; ------------------------- -;; Initialize app - -(defn mount-root [] - (reagent/render [current-page] (.getElementById js/document "app"))) - -(defn init! [] - (accountant/configure-navigation!) - (accountant/dispatch-current!) - (mount-root)) diff --git a/src/leiningen/new/reagent/src/sass/index.sass b/src/leiningen/new/reagent/src/sass/index.sass deleted file mode 100644 index 7d6f439..0000000 --- a/src/leiningen/new/reagent/src/sass/index.sass +++ /dev/null @@ -1,3 +0,0 @@ -body - background: tomato - color: pink