Rip out all the JS crap and make the bootstrap js work

This commit is contained in:
Aaron Fischer 2017-03-28 12:42:06 +02:00
parent 4b1978766e
commit a8111836a9
22 changed files with 17 additions and 529 deletions

View file

@ -1,28 +0,0 @@
#
# Name of the base image. Capstan will download this automatically from
# Cloudius S3 repository.
#
#base: cloudius/osv
base: cloudius/osv-openjdk8
#
# The command line passed to OSv to start up the application.
#
cmdline: /java.so -jar /yenu/app.jar
#
# The command to use to build the application.
# You can use any build tool/command (make/rake/lein/boot) - this runs locally on your machine
#
# For Leiningen, you can use:
#build: lein uberjar
# For Boot, you can use:
#build: boot build
#
# List of files that are included in the generated image.
#
files:
/yenu/app.jar: ./target/uberjar/yenu.jar

View file

@ -1,5 +1,5 @@
FROM java:8-alpine
MAINTAINER Your Name <you@example.com>
MAINTAINER Aaron Fischer <mail@aaron-fischer.net>
ADD target/uberjar/yenu.jar /yenu/app.jar

View file

@ -1,21 +0,0 @@
# yenu
generated using Luminus version "2.9.11.32"
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 run
## License
Copyright © 2017 FIXME

View file

@ -1,6 +1,5 @@
(ns user
(:require [mount.core :as mount]
[yenu.figwheel :refer [start-fw stop-fw cljs]]
yenu.core))
(defn start []

View file

@ -7,8 +7,8 @@
{:init
(fn []
(parser/cache-off!)
(log/info "\n-=[yenu started successfully using the development profile]=-"))
(log/info "\n== yenu started successfully using the development profile."))
:stop
(fn []
(log/info "\n-=[yenu has shut down successfully]=-"))
(log/info "\n== yenu has shut down successfully"))
:middleware wrap-dev})

View file

@ -1,12 +0,0 @@
(ns yenu.figwheel
(:require [figwheel-sidecar.repl-api :as ra]))
(defn start-fw []
(ra/start-figwheel!))
(defn stop-fw []
(ra/stop-figwheel!))
(defn cljs []
(ra/cljs-repl))

View file

@ -1,14 +0,0 @@
(ns ^:figwheel-no-load yenu.app
(:require [yenu.core :as core]
[devtools.core :as devtools]
[figwheel.client :as figwheel :include-macros true]))
(enable-console-print!)
(figwheel/watch-and-reload
:websocket-url "ws://localhost:3449/figwheel-ws"
:on-jsload core/mount-components)
(devtools/install!)
(core/init!)

View file

@ -4,8 +4,8 @@
(def defaults
{:init
(fn []
(log/info "\n-=[yenu started successfully]=-"))
(log/info "\n== yenu started successfully"))
:stop
(fn []
(log/info "\n-=[yenu has shut down successfully]=-"))
(log/info "\n== yenu has shut down successfully"))
:middleware identity})

View file

@ -1,7 +0,0 @@
(ns yenu.app
(:require [yenu.core :as core]))
;;ignore println statements in prod
(set! *print-fn* (fn [& _]))
(core/init!)

View file

@ -1,4 +0,0 @@
{:dev true
:port 3000
;; when :nrepl-port is set the application starts the nREPL server on load
:nrepl-port 7000}

View file

@ -1,43 +0,0 @@
<?xml version="1.0" encoding="UTF-8"?>
<configuration>
<statusListener class="ch.qos.logback.core.status.NopStatusListener" />
<appender name="STDOUT" class="ch.qos.logback.core.ConsoleAppender">
<!-- encoders are assigned the type
ch.qos.logback.classic.encoder.PatternLayoutEncoder by default -->
<encoder>
<charset>UTF-8</charset>
<pattern>%date{ISO8601} [%thread] %-5level %logger{36} - %msg %n</pattern>
</encoder>
</appender>
<appender name="FILE" class="ch.qos.logback.core.rolling.RollingFileAppender">
<file>log/yenu.log</file>
<rollingPolicy class="ch.qos.logback.core.rolling.TimeBasedRollingPolicy">
<fileNamePattern>log/yenu.%d{yyyy-MM-dd}.%i.log</fileNamePattern>
<timeBasedFileNamingAndTriggeringPolicy class="ch.qos.logback.core.rolling.SizeAndTimeBasedFNATP">
<maxFileSize>100MB</maxFileSize>
</timeBasedFileNamingAndTriggeringPolicy>
<!-- keep 30 days of history -->
<maxHistory>30</maxHistory>
</rollingPolicy>
<encoder>
<charset>UTF-8</charset>
<pattern>%date{ISO8601} [%thread] %-5level %logger{36} - %msg %n</pattern>
</encoder>
</appender>
<logger name="org.apache.http" level="warn">
<AppenderRef ref="STDOUT"/>
<AppenderRef ref="FILE"/>
</logger>
<logger name="org.xnio.nio" level="warn">
<AppenderRef ref="STDOUT"/>
<AppenderRef ref="FILE"/>
</logger>
<logger name="com.zaxxer.hikari" level="warn">
<AppenderRef ref="STDOUT"/>
<AppenderRef ref="FILE"/>
</logger>
<root level="DEBUG">
<appender-ref ref="STDOUT" />
<appender-ref ref="FILE" />
</root>
</configuration>

View file

@ -2,8 +2,7 @@
:description "yenu -- The image sharing tool for friends"
:url "https://aaron-fischer.net/"
:dependencies [[bouncer "1.0.0"]
[cljs-ajax "0.5.8"]
:dependencies [[bouncer "1.0.1"]
[compojure "1.5.2"]
[conman "0.6.3"]
[cprop "0.1.10"]
@ -13,21 +12,18 @@
[metosin/ring-http-response "0.8.1"]
[mount "0.1.11"]
[org.clojure/clojure "1.8.0"]
[org.clojure/clojurescript "1.9.473" :scope "provided"]
[org.clojure/tools.cli "0.3.5"]
[org.clojure/tools.logging "0.3.1"]
[org.webjars.bower/tether "1.4.0"]
[org.webjars/jquery "3.2.0"]
[org.webjars/bootstrap "4.0.0-alpha.6-1"]
[org.webjars/font-awesome "4.7.0"]
[org.webjars/webjars-locator-jboss-vfs "0.1.0"]
[org.xerial/sqlite-jdbc "3.16.1"]
[reagent "0.6.0"]
[reagent-utils "0.2.0"]
[ring-middleware-format "0.7.2"]
[ring-webjars "0.1.1"]
[ring-middleware-format "0.7.2"]
[ring/ring-core "1.5.1"]
[ring/ring-defaults "0.2.3"]
[secretary "1.2.3"]
[selmer "1.10.6"]
[image-resizer "0.1.9"]
[me.raynes/fs "1.4.6"]
@ -48,7 +44,6 @@
:plugins [[lein-cprop "1.0.1"]
[migratus-lein "0.4.3"]
[lein-cljsbuild "1.1.4"]
[lein-immutant "2.1.0"]
[lein-sassc "0.10.4"]
[lein-auto "0.1.2"]]
@ -63,82 +58,23 @@
:hooks [leiningen.sassc]
:clean-targets ^{:protect false}
[:target-path [:cljsbuild :builds :app :compiler :output-dir] [:cljsbuild :builds :app :compiler :output-to]]
:figwheel
{:http-server-root "public"
:nrepl-port 7002
:css-dirs ["resources/public/css"]
:nrepl-middleware [cemerick.piggieback/wrap-cljs-repl]}
[:target-path [:builds :app :compiler :output-dir] [:builds :app :compiler :output-to]]
:profiles
{:uberjar {:omit-source true
:prep-tasks ["compile" ["cljsbuild" "once" "min"]]
:cljsbuild
{:builds
{:min
{:source-paths ["src/cljc" "src/cljs" "env/prod/cljs"]
:compiler
{:output-to "target/cljsbuild/public/js/app.js"
:optimizations :advanced
:pretty-print false
:closure-warnings
{:externs-validation :off :non-standard-jsdoc :off}
:externs ["react/externs/react.js"]}}}}
:aot :all
:uberjar-name "yenu.jar"
:source-paths ["env/prod/clj"]
:resource-paths ["env/prod/resources"]}
:dev [:project/dev :profiles/dev]
:test [:project/dev :project/test :profiles/test]
:project/dev {:dependencies [[prone "1.1.4"]
[ring/ring-mock "0.3.0"]
[ring/ring-devel "1.5.1"]
[pjstadig/humane-test-output "0.8.1"]
[binaryage/devtools "0.9.0"]
[com.cemerick/piggieback "0.2.2-SNAPSHOT"]
[doo "0.1.7"]
[figwheel-sidecar "0.5.9"]]
:plugins [[com.jakemccrary/lein-test-refresh "0.18.1"]
[lein-doo "0.1.7"]
[lein-figwheel "0.5.9"]
[org.clojure/clojurescript "1.9.473"]]
:cljsbuild
{:builds
{:app
{:source-paths ["src/cljs" "src/cljc" "env/dev/cljs"]
:compiler
{:main "yenu.app"
: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}}}}
:doo {:build "test"}
:source-paths ["env/dev/clj" "test/clj"]
[binaryage/devtools "0.9.0"]]
:source-paths ["env/dev/clj"]
:resource-paths ["env/dev/resources"]
:repl-options {:init-ns user}
:injections [(require 'pjstadig.humane-test-output)
(pjstadig.humane-test-output/activate!)]}
:project/test {:resource-paths ["env/test/resources"]
:cljsbuild
{:builds
{:test
{:source-paths ["src/cljc" "src/cljs" "test/cljs"]
:compiler
{:output-to "target/test.js"
:main "yenu.doo-runner"
:optimizations :whitespace
:pretty-print true}}}}
}
:profiles/dev {}
:profiles/test {}})
:repl-options {:init-ns user}}
:profiles/dev {}})

View file

@ -1,137 +0,0 @@
<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.

File diff suppressed because one or more lines are too long

View file

@ -17,7 +17,7 @@
<div class="form-group">
<label for="title">Bildüberschrift</label>
<input type="text" name="title" class="form-control"
placeholder="Leerlassen für Dateiname">
placeholder="Leer lassen für Dateiname">
</div>
<div class="form-group">

View file

@ -56,21 +56,17 @@
Fischer</a>, <a href="https://instagram.com/juna_eule">Beatrice Fischer</a></p>
</div>
<!-- cljs stuff, remove ore reuse it (see cljs/jenu/core.cljs) -->
<div id="navbar"></div>
<div id="app"></div>
{% style "/assets/bootstrap/css/bootstrap.min.css" %}
{% style "/assets/font-awesome/css/font-awesome.min.css" %}
{% style "/css/screen.css" %}
<script type="text/javascript">
var context = "{{servlet-context}}";
var csrfToken = "{{csrf-token}}";
</script>
{% script "/js/app.js" %}
{% script "/js/bootstrap.min.js" %}
{% script "/assets/jquery/jquery.min.js" %}
{% script "/assets/bootstrap/js/bootstrap.min.js" %}
</body>
</html>

View file

@ -1,20 +0,0 @@
(ns yenu.ajax
(:require [ajax.core :as ajax]))
(defn local-uri? [{:keys [uri]}]
(not (re-find #"^\w+?://" uri)))
(defn default-headers [request]
(if (local-uri? request)
(-> request
(update :uri #(str js/context %))
(update :headers #(merge {"x-csrf-token" js/csrfToken} %)))
request))
(defn load-interceptors! []
(swap! ajax/default-interceptors
conj
(ajax/to-interceptor {:name "default headers"
:request default-headers})))

View file

@ -1,86 +0,0 @@
(ns yenu.core
(:require [reagent.core :as r]
[reagent.session :as session]
[secretary.core :as secretary :include-macros true]
[goog.events :as events]
[goog.history.EventType :as HistoryEventType]
[yenu.ajax :refer [load-interceptors!]]
[ajax.core :refer [GET POST]])
(:import goog.History))
(defn nav-link [uri title page collapsed?]
[:li.nav-item
{:class (when (= page (session/get :page)) "active")}
[:a.nav-link
{:href uri
:on-click #(reset! collapsed? true)} title]])
(defn navbar []
(let [collapsed? (r/atom true)]
(fn []
[:nav.navbar.navbar-dark.bg-primary
[:button.navbar-toggler.hidden-sm-up
{:on-click #(swap! collapsed? not)} "☰"]
[:div.collapse.navbar-toggleable-xs
(when-not @collapsed? {:class "in"})
[:a.navbar-brand {:href "#/"} "yenu"]
[:ul.nav.navbar-nav
[nav-link "#/" "Home" :home collapsed?]
[nav-link "#/about" "About" :about collapsed?]]]])))
(defn about-page []
[:div.container
[:div.row
[:div.col-md-12
[:img {:src (str js/context "/img/warning_clojure.png")}]]]])
(defn home-page []
[:div.container
(when-let [docs (session/get :docs)]
[:div.row>div.col-sm-12
[:div {:dangerouslySetInnerHTML
{:__html "test"}}]])])
(def pages
{:home #'home-page
:about #'about-page})
(defn page []
[(pages (session/get :page))])
;; -------------------------
;; Routes
(secretary/set-config! :prefix "#")
(secretary/defroute "/" []
(session/put! :page :home))
(secretary/defroute "/about" []
(session/put! :page :about))
;; -------------------------
;; History
;; must be called after routes have been defined
(defn hook-browser-navigation! []
(doto (History.)
(events/listen
HistoryEventType/NAVIGATE
(fn [event]
(secretary/dispatch! (.-token event))))
(.setEnabled true)))
;; -------------------------
;; Initialize app
(defn fetch-docs! []
(GET "/docs" {:handler #(session/put! :docs %)}))
(defn mount-components []
(r/render [#'navbar] (.getElementById js/document "navbar"))
(r/render [#'page] (.getElementById js/document "app")))
(defn init! []
;; (load-interceptors!)
;; (fetch-docs!)
;; (hook-browser-navigation!)
;; (mount-components)
)

View file

@ -1,36 +0,0 @@
(ns yenu.test.db.core
(:require [yenu.db.core :refer [*db*] :as db]
[luminus-migrations.core :as migrations]
[clojure.test :refer :all]
[clojure.java.jdbc :as jdbc]
[yenu.config :refer [env]]
[mount.core :as mount]))
(use-fixtures
:once
(fn [f]
(mount/start
#'yenu.config/env
#'yenu.db.core/*db*)
(migrations/migrate ["migrate"] (select-keys env [:database-url]))
(f)))
(deftest test-users
(jdbc/with-db-transaction [t-conn *db*]
(jdbc/db-set-rollback-only! t-conn)
(is (= 1 (db/create-user!
t-conn
{:id "1"
:first_name "Sam"
:last_name "Smith"
:email "sam.smith@example.com"
:pass "pass"})))
(is (= {:id "1"
:first_name "Sam"
:last_name "Smith"
:email "sam.smith@example.com"
:pass "pass"
:admin nil
:last_login nil
:is_active nil}
(db/get-user t-conn {:id "1"})))))

View file

@ -1,13 +0,0 @@
(ns yenu.test.handler
(:require [clojure.test :refer :all]
[ring.mock.request :refer :all]
[yenu.handler :refer :all]))
(deftest test-app
(testing "main route"
(let [response ((app) (request :get "/"))]
(is (= 200 (:status response)))))
(testing "not-found route"
(let [response ((app) (request :get "/invalid"))]
(is (= 404 (:status response))))))

View file

@ -1,9 +0,0 @@
(ns yenu.core-test
(:require [cljs.test :refer-macros [is are deftest testing use-fixtures]]
[pjstadig.humane-test-output]
[reagent.core :as reagent :refer [atom]]
[yenu.core :as rc]))
(deftest test-home
(is (= true true)))

View file

@ -1,6 +0,0 @@
(ns yenu.doo-runner
(:require [doo.runner :refer-macros [doo-tests]]
[yenu.core-test]))
(doo-tests 'yenu.core-test)