-
Notifications
You must be signed in to change notification settings - Fork 13
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
0 parents
commit e7964bb
Showing
21 changed files
with
565 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
/target | ||
/lib | ||
/classes | ||
/checkouts | ||
pom.xml | ||
*.jar | ||
*.class | ||
/.lein-* | ||
profiles.clj | ||
/.env | ||
*.log |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
web: java $JVM_OPTS -cp target/guestbook.jar clojure.main -m guestbook.core |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
# guestbook | ||
|
||
FIXME | ||
|
||
## Prerequisites | ||
|
||
You will need [Leiningen][1] 2.0 or above installed. | ||
|
||
[1]: https://github.com/technomancy/leiningen | ||
|
||
## Running | ||
|
||
To start a web server for the application, run: | ||
|
||
lein ring server | ||
|
||
## License | ||
|
||
Copyright © 2015 FIXME |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
DROP TABLE users; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
CREATE TABLE users | ||
(id VARCHAR(20) PRIMARY KEY, | ||
first_name VARCHAR(30), | ||
last_name VARCHAR(30), | ||
email VARCHAR(30), | ||
admin BOOLEAN, | ||
last_login TIME, | ||
is_active BOOLEAN, | ||
pass VARCHAR(100)); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
(defproject guestbook "0.1.0-SNAPSHOT" | ||
|
||
:description "FIXME: write description" | ||
:url "http://example.com/FIXME" | ||
|
||
:dependencies [[org.clojure/clojure "1.7.0-RC2"] | ||
[selmer "0.8.2"] | ||
[com.taoensso/timbre "3.4.0"] | ||
[com.taoensso/tower "3.0.2"] | ||
[markdown-clj "0.9.66"] | ||
[environ "1.0.0"] | ||
[compojure "1.3.4"] | ||
[ring/ring-defaults "0.1.5"] | ||
[ring/ring-session-timeout "0.1.0"] | ||
[metosin/ring-middleware-format "0.6.0"] | ||
[metosin/ring-http-response "0.6.2"] | ||
[bouncer "0.3.3"] | ||
[prone "0.8.2"] | ||
[org.clojure/tools.nrepl "0.2.10"] | ||
[ring-server "0.4.0"] | ||
[ragtime "0.3.9"] | ||
[org.clojure/java.jdbc "0.3.7"] | ||
[instaparse "1.4.0"] | ||
[yesql "0.5.0-rc2"] | ||
[com.h2database/h2 "1.4.187"]] | ||
|
||
:min-lein-version "2.0.0" | ||
:uberjar-name "guestbook.jar" | ||
:jvm-opts ["-server"] | ||
|
||
;;enable to start the nREPL server when the application launches | ||
;:env {:repl-port 7001} | ||
|
||
:main guestbook.core | ||
|
||
:plugins [[lein-ring "0.9.1"] | ||
[lein-environ "1.0.0"] | ||
[lein-ancient "0.6.5"] | ||
[ragtime/ragtime.lein "0.3.8"]] | ||
|
||
|
||
|
||
:ring {:handler guestbook.handler/app | ||
:init guestbook.handler/init | ||
:destroy guestbook.handler/destroy | ||
:uberwar-name "guestbook.war"} | ||
|
||
|
||
|
||
:profiles | ||
{:uberjar {:omit-source true | ||
:env {:production true} | ||
|
||
:aot :all} | ||
:dev {:dependencies [[ring-mock "0.1.5"] | ||
[ring/ring-devel "1.3.2"] | ||
[pjstadig/humane-test-output "0.7.0"] | ||
] | ||
|
||
|
||
|
||
:repl-options {:init-ns guestbook.core} | ||
:injections [(require 'pjstadig.humane-test-output) | ||
(pjstadig.humane-test-output/activate!)] | ||
:env {:dev true}}}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
<div class="bs-callout bs-callout-danger"> | ||
|
||
### Database Configuration is Required | ||
|
||
Before continuing please follow the steps below to configure your database connection and run the necessary migrations. | ||
|
||
* Run `lein run migrate` in the root of the project to create the tables. | ||
* Restart the application. | ||
|
||
</div> | ||
|
||
### Managing Your Middleware | ||
|
||
Request middleware functions are located under the `guestbook.middleware` namespace. | ||
A request logging helper called `log-request` is defined below: | ||
|
||
```clojure | ||
(defn log-request [handler] | ||
(fn [req] | ||
(timbre/debug req) | ||
(handler req))) | ||
``` | ||
|
||
This namespace also defines two vectors for organizing the middleware called `development-middleware` and `production-middleware`. | ||
Any middleware that you only wish to run in development mode, such as `log-request`, should be added to the first vector. | ||
|
||
### Here are some links to get started | ||
|
||
1. [HTML templating](http://www.luminusweb.net/docs/html_templating.md) | ||
2. [Accessing the database](http://www.luminusweb.net/docs/database.md) | ||
3. [Serving static resources](http://www.luminusweb.net/docs/static_resources.md) | ||
4. [Setting response types](http://www.luminusweb.net/docs/responses.md) | ||
5. [Defining routes](http://www.luminusweb.net/docs/routes.md) | ||
6. [Adding middleware](http://www.luminusweb.net/docs/middleware.md) | ||
7. [Sessions and cookies](http://www.luminusweb.net/docs/sessions_cookies.md) | ||
8. [Security](http://www.luminusweb.net/docs/security.md) | ||
9. [Deploying the application](http://www.luminusweb.net/docs/deployment.md) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
html, | ||
body { | ||
font-family: 'Helvetica Neue', Helvetica, Arial, sans-serif; | ||
height: 100%; | ||
padding-top: 40px; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
-- name: create-user! | ||
-- creates a new user record | ||
INSERT INTO users | ||
(id, first_name, last_name, email, pass) | ||
VALUES (:id, :first_name, :last_name, :email, :pass) | ||
|
||
-- name: update-user! | ||
-- update an existing user record | ||
UPDATE users | ||
SET first_name = :first_name, last_name = :last_name, email = :email | ||
WHERE id = :id | ||
|
||
-- name: get-user | ||
-- retrieve a user given the id. | ||
SELECT * FROM users | ||
WHERE id = :id |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
{% extends "base.html" %} | ||
{% block content %} | ||
<p>this is the story of guestbook... work in progress</p> | ||
{% endblock %} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
<!DOCTYPE html> | ||
<html> | ||
<head> | ||
<META http-equiv="Content-Type" content="text/html; charset=UTF-8"> | ||
<title>Welcome to guestbook</title> | ||
</head> | ||
<body> | ||
<!-- navbar --> | ||
<div class="navbar navbar-inverse navbar-fixed-top"> | ||
<div class="container"> | ||
<div class="navbar-header"> | ||
<a class="navbar-brand" href="{{servlet-context}}/">guestbook</a> | ||
</div> | ||
<div class="navbar-collapse collapse "> | ||
<ul class="nav navbar-nav"> | ||
<li {% ifequal page "home.html" %} class="active"{%endifequal%}> | ||
<a href="{{servlet-context}}/">Home</a> | ||
</li> | ||
<li {% ifequal page "about.html" %} class="active"{%endifequal%}> | ||
<a href="{{servlet-context}}/about">About</a> | ||
</li> | ||
</ul> | ||
</div> | ||
</div> | ||
</div> | ||
|
||
<div class="container"> | ||
{% block content %} | ||
{% endblock %} | ||
</div> | ||
<!-- scripts and styles --> | ||
<link rel="stylesheet" href="//maxcdn.bootstrapcdn.com/bootstrap/3.3.0/css/bootstrap.min.css"> | ||
<link rel="stylesheet" href="//maxcdn.bootstrapcdn.com/bootstrap/3.3.0/css/bootstrap-theme.min.css"> | ||
{% style "/css/screen.css" %} | ||
|
||
<script src="//code.jquery.com/jquery-2.1.1.min.js" type="text/javascript"></script> | ||
<script src="//maxcdn.bootstrapcdn.com/bootstrap/3.3.0/js/bootstrap.min.js"></script> | ||
|
||
<script type="text/javascript"> | ||
var context = "{{servlet-context}}"; | ||
</script> | ||
{% block page-scripts %} | ||
{% endblock %} | ||
</body> | ||
</html> | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
<!DOCTYPE html> | ||
<html> | ||
<head> | ||
<title>Something bad happened</title> | ||
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8"> | ||
<meta name="viewport" content="width=device-width, initial-scale=1.0"> | ||
<link rel="stylesheet" href="//maxcdn.bootstrapcdn.com/bootstrap/3.3.0/css/bootstrap.min.css"> | ||
<link rel="stylesheet" href="//maxcdn.bootstrapcdn.com/bootstrap/3.3.0/css/bootstrap-theme.min.css"> | ||
<style type="text/css"> | ||
html { | ||
height: 100%; | ||
min-height: 100%; | ||
min-width: 100%; | ||
overflow: hidden; | ||
width: 100%; | ||
} | ||
html body { | ||
height: 100%; | ||
margin: 0; | ||
padding: 0; | ||
width: 100%; | ||
} | ||
html .container-fluid { | ||
display: table; | ||
height: 100%; | ||
padding: 0; | ||
width: 100%; | ||
} | ||
html .row-fluid { | ||
display: table-cell; | ||
height: 100%; | ||
vertical-align: middle; | ||
} | ||
</style> | ||
</head> | ||
<body> | ||
<div class="container-fluid"> | ||
<div class="row-fluid"> | ||
<div class="col-lg-12"> | ||
<div class="centering text-center"> | ||
<div class="text-center"> | ||
<h1><span class="text-danger">Error: 500</span></h1> | ||
<hr> | ||
<h2 class="without-margin">Something very bad has happened!</h2> | ||
<h4 class="text-danger">We've dispatched a team of highly trained gnomes to take care of the problem.</h4> | ||
</div> | ||
</div> | ||
</div> | ||
</div> | ||
</div> | ||
</body> | ||
</html> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
{% extends "base.html" %} | ||
{% block content %} | ||
<div class="jumbotron"> | ||
<h1>Welcome to guestbook</h1> | ||
<p>Time to start building your site!</p> | ||
<p><a class="btn btn-primary btn-lg" href="http://luminusweb.net">Learn more »</a></p> | ||
</div> | ||
|
||
<div class="row"> | ||
<div class="span12"> | ||
{{docs|markdown}} | ||
</div> | ||
</div> | ||
{% endblock %} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
(ns guestbook.core | ||
(:require [guestbook.handler :refer [app init destroy]] | ||
[ring.adapter.jetty :refer [run-jetty]] | ||
|
||
[ring.middleware.reload :as reload] | ||
[ragtime.main] | ||
[taoensso.timbre :as timbre] | ||
[environ.core :refer [env]]) | ||
(:gen-class)) | ||
|
||
(defn parse-port [[port]] | ||
(Integer/parseInt (or port (env :port) "3000"))) | ||
|
||
|
||
|
||
|
||
|
||
(defonce server (atom nil)) | ||
|
||
(defn start-server [port] | ||
(init) | ||
(reset! server | ||
(run-jetty | ||
(if (env :dev) (reload/wrap-reload #'app) app) | ||
{:port port | ||
:join? false}))) | ||
|
||
(defn stop-server [] | ||
(when @server | ||
(destroy) | ||
(.stop @server) | ||
(reset! server nil))) | ||
|
||
(defn start-app [args] | ||
(let [port (parse-port args)] | ||
(.addShutdownHook (Runtime/getRuntime) (Thread. stop-server)) | ||
(start-server port))) | ||
|
||
|
||
(defn migrate [args] | ||
(ragtime.main/-main | ||
"-r" "ragtime.sql.database" | ||
"-d" (env :database-url) | ||
"-m" "ragtime.sql.files/migrations" | ||
(clojure.string/join args))) | ||
|
||
(defn -main [& args] | ||
(case (first args) | ||
"migrate" (migrate args) | ||
"rollback" (migrate args) | ||
(start-app args))) | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
(ns guestbook.db.core | ||
(:require | ||
[yesql.core :refer [defqueries]] | ||
[clojure.java.io :as io])) | ||
|
||
(def db-store (str (.getName (io/file ".")) "/site.db")) | ||
|
||
(def db-spec | ||
{:classname "org.h2.Driver" | ||
:subprotocol "h2" | ||
:subname db-store | ||
:make-pool? true | ||
:naming {:keys clojure.string/lower-case | ||
:fields clojure.string/upper-case}}) | ||
|
||
(defqueries "sql/queries.sql" {:connection db-spec}) |
Oops, something went wrong.