re-frame-template
Leiningen template for reagent web apps that implements the re-frame pattern.
Through the use of profiles, this template lets the developer pick and choose what is included in their application.
Usage
The base template includes:
- re-frame
- figwheel
- cljs-devtools
- To enable: 1) Open Chrome's DevTools,
Ctrl-Shift-i
; 2) open "Settings",F1
; 3) Check "Enable custom formatters" under the "Console" section; 4) close and re-open DevTools
- To enable: 1) Open Chrome's DevTools,
To create an application with the base template:
lein new re-frame <project-name>
The optional profiles include:
- cider (
+cider
) - cljs.test and doo (
+test
) - compojure (
+handler
) - garden (
+garden
) - less (
+less
) - re-com (
+re-com
) - re-frisk (
+re-frisk
) - secretary (
+routes
)
To add a profile to the base template, just append the profile name (let's use +re-com
as an example):
lein new re-frame <project-name> +re-com
Any combination of profiles can be added at once:
lein new re-frame <project-name> +garden +re-com +routes +test +less +re-frisk
Development Mode
Start Cider from Emacs (if using +cider):
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
)
Compile css (if using +garden or +less):
Compile css file once.
lein garden once
lein less once
Automatically recompile css file on change.
lein garden auto
lein less auto
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.
Logging:
In project-name.config, there is a variable called debug?
, which
defaults to true. However, for the min
build, this variable is
re-defined to false.
When debug?
is true, we include (enable-console-print!)
. If you wrap all of your println
s with a when
block as show below, then you will get logs printed to the browser's console for the dev
build and not the min
build.
(when config/debug?
(println "dev mode"))
Run tests (if using +test):
lein clean
lein doo phantom test once
The above command assumes that you have phantomjs installed. However, please note that doo can be configured to run cljs.test in many other JS environments (chrome, ie, safari, opera, slimer, node, rhino, or nashorn).
NOTE: as a result of the recent update of clojurescript, will receive this error when running doo (issue 142):
;; ======================================================================
;; Testing with Phantom:
Testing everything.core-test
FAIL in (fake-test) (:)
fake description
expected: (= 1 2)
actual: (not (= 1 2))
Ran 1 tests containing 1 assertions.
1 failures, 0 errors.
WARNING: doo's init function was not set
#object[TypeError TypeError: undefined is not an object (evaluating 'process_exit.call')]
TypeError: undefined is not an object (evaluating 'process_exit.call')
phantomjs://code/phantom1945436062118516770.js:81 in onError
Watching paths: /home/matthew/gadfly/projects/re-frame-template/temp/everything/src/cljs, /home/matthew/gadfly/projects/re-frame-template/temp/everything/test/cljs
Production Build
To compile clojurescript to javascript:
lein clean
lein cljsbuild once min
If you're using +handler
lein clean
lein uberjar
To deploy to heroku, first create your app:
heroku create
Then deploy the application:
git push heroku master
Other Templates
There is also a public comparison chart of the common templates.
Misc.
Looking for some re-frame scaffolding? Check out slush-reframe.
Contributing
Contributions are welcomed! To add a new profile, this is what I'd recommend:
- Add a file with the name of the profile here
- Look at the existing options in that folder for inspiration for what to include in that file
- Update project.clj with the profile
- Add any new files here and use the {{ var-name }} syntax as needed
- Update the README that will result when the template is used, as well as the top-level README for re-frame-template itself
- In a terminal, at the root of re-frame-template, run
lein install
- Locally test that your profile works,
lein new re-frame <app-name> +<profile-name>
- Add your profile to create-templates and run the script to make sure the other profiles didn't break.
License
The MIT License (MIT)
Copyright © 2015 Matthew Jaoudi
Copyright © 2015 Dylan Paris
Copyright © 2015 Michael Thompson
Copyright © 2015 Markku Rontu
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.