yenu/resources/docs/docs.md
Aaron Fischer c2d1dd3227 Time to start over
+cljs +sqlite +sassc +reagent
2017-02-16 22:31:16 +01:00

138 lines
4.3 KiB
Markdown

<h2 class="alert alert-success">Congratulations, your <a class="alert-link" href="http://luminusweb.net">Luminus</a> site is ready!</h2>
This page will help guide you through the first steps of building your site.
#### Why are you seeing this page?
The `home-routes` handler in the `yenu.routes.home` namespace
defines the route that invokes the `home-page` function whenever an HTTP
request is made to the `/` URI using the `GET` method.
```
(defroutes home-routes
(GET "/" []
(home-page))
(GET "/docs" []
(-> (response/ok (-> "docs/docs.md" io/resource slurp))
(response/header "Content-Type" "text/plain; charset=utf-8"))))
```
The `home-page` function will in turn call the `yenu.layout/render` function
to render the HTML content:
```
(defn home-page []
(layout/render "home.html"))
```
The page contains a link to the compiled ClojureScript found in the `target/cljsbuild/public` folder:
```
{% script "/js/app.js" %}
```
The rest of this page is rendered by ClojureScript found in the `src/cljs/yenu/core.cljs` file.
#### Organizing the routes
The routes are aggregated and wrapped with middleware in the `yenu.handler` namespace:
```
(def app-routes
(routes
(-> #'home-routes
(wrap-routes middleware/wrap-csrf)
(wrap-routes middleware/wrap-formats))
(route/not-found
(:body
(error-page {:status 404
:title "page not found"})))))
```
The `app-routes` definition groups all the routes in the application into a single handler.
A default route group is added to handle the `404` case.
<a class="btn btn-primary" href="http://www.luminusweb.net/docs/routes.md">learn more about routing »</a>
The `home-routes` are wrapped with two middleware functions. The first enables CSRF protection.
The second takes care of serializing and deserializing various encoding formats, such as JSON.
#### Managing your middleware
Request middleware functions are located under the `yenu.middleware` namespace.
This namespace is reserved for any custom middleware for the application. Some default middleware is
already defined here. The middleware is assembled in the `wrap-base` function.
Middleware used for development is placed in the `yenu.dev-middleware` namespace found in
the `env/dev/clj/` source path.
<a class="btn btn-primary" href="http://www.luminusweb.net/docs/middleware.md">learn more about middleware »</a>
<div class="bs-callout bs-callout-danger">
#### Database configuration is required
If you haven't already, then please follow the steps below to configure your database connection and run the necessary migrations.
* Create the database for your application.
* Update the connection URL in the `profiles.clj` file with your database name and login.
* Run `lein run migrate` in the root of the project to create the tables.
* Let `mount` know to start the database connection by `require`-ing `yenu.db.core` in some other namespace.
* Restart the application.
<a class="btn btn-primary" href="http://www.luminusweb.net/docs/database.md">learn more about database access »</a>
</div>
<div class="bs-callout bs-callout-danger">
#### SassC libsass command-line compiler is required
You must have the SassC command-line compiler installed to use this feature.
Please follow the instructions at: <a href="http://github.com/sass/sassc">http://github.com/sass/sassc</a>
to install the compiler for your platform.
#### Usage
Compile your files once:
```
$ lein sassc once
```
To delete all the files generated by lein-sassc:
```
$ lein sassc clean
```
To recompile when any changes are made:
```
$ lein auto sassc once
```
#### Hooks
The following hooks are supported by lein-sassc:
```
$ lein compile
$ lein clean
```
Because lein-sassc requires a binary to compile Sass, it often won't work on platforms like Heroku which compile the application on their servers. To get around this limitation, commit the generated CSS files and remove
```
:hooks [leiningen.sassc]
```
from project.clj.
</div>
#### Need some help?
Visit the [official documentation](http://www.luminusweb.net/docs) for examples
on how to accomplish common tasks with Luminus. The `#luminus` channel on the [Clojurians Slack](http://clojurians.net/) and [Google Group](https://groups.google.com/forum/#!forum/luminusweb) are both great places to seek help and discuss projects with other users.