Skip to content

Commit

Permalink
Substantial project restructuring
Browse files Browse the repository at this point in the history
- provides a 'lean' bundle for lightweight deployments: yada/lean

- allows for other bundles, containing collections including more
  exotic extensions
  • Loading branch information
malcolmsparks committed Jan 2, 2017
1 parent 5c3121a commit c936ef3
Show file tree
Hide file tree
Showing 101 changed files with 1,449 additions and 2,130 deletions.
23 changes: 12 additions & 11 deletions .gitignore
@@ -1,12 +1,12 @@
/target/
/.nrepl-port
/.lein-failures
/pom.xml
/pom.xml.asc
/.lein-repl-history
/.idea/
/*.iml
/todo.org
target/
.nrepl-port
.lein-failures
pom.xml
pom.xml.asc
.lein-repl-history
.idea/
*.iml
todo.org
/notes.org
/dev/resources/hello-async.png
/todo.org_archive
Expand All @@ -21,10 +21,11 @@
/talks/clojurex-2015-thomas.tex
/talks/clojurex-2015-malcolm.pdf
/talks/clojurex-2015-malcolm.tex
target/
/talks/clojutre-2016.html
/talks/clojutre-2016.pdf
/talks/clojutre-2016.tex
/talks/fby-2016.pdf
/talks/fby-2016.tex
/examples/phonebook/.lein-failures
/doc/book.xml
/doc/tmp
/doc/book.pdf
26 changes: 12 additions & 14 deletions README.md
Expand Up @@ -20,10 +20,12 @@ The user-manual is also available as an e-book or PDF, at

## Installation

Add the following dependency to your
`project.clj` file
Add the following dependency to your `project.clj` or `build.boot` file

```clojure
[yada "1.2.0-SNAPSHOT" :classifier "full"]
```

[![Clojars Project](http://clojars.org/yada/latest-version.svg)](http://clojars.org/yada)
[![Build Status](https://travis-ci.org/juxt/yada.png)](https://travis-ci.org/juxt/yada)

## Create a yada handler
Expand All @@ -48,15 +50,6 @@ yada requires the following :-

- a Java JDK/JRE installation, version 8 or above
- Clojure 1.8.0
- Aleph 0.4.1 (provided via a dependency)
- bidi 2.0.9 or above

A project using yada will need to bring in [aleph](https://github.com/ztellman/aleph), and optionally bidi.

``` clojure
[aleph "0.4.1"]
[bidi "2.0.9"]
```

Support for other web-severs, such as undertow, are on the road-map.

Expand All @@ -72,8 +65,6 @@ By default, yada is batteries-included, bringing in a large number of dependenci

However, a leaner version of yada is available which cuts out Swagger, swagger-ui, JSON (cheshire), Transit, buddy, core.async, SSE and other fat.

Instead of requiring `yada.yada`, require `yada.yada.lean` but otherwise use yada in the same way.

The following differences apply:

- yada doesn't automatically encode/decode JSON bodies, or render JSON as HTML
Expand All @@ -83,6 +74,13 @@ The following differences apply:
- no JWT
- no Transit

To use the lean (or any other) variant of yada, specify the
appropriate classifier in your `project.clj` or `build.boot` file.

```clojure
[yada "1.1.47" :classifier "lean"]
```

## Running documentation and examples offline

Although yada is a library, if you clone this repo you can run the documentation and examples from the REPL.
Expand Down
7 changes: 7 additions & 0 deletions bundles/full/README.md
@@ -0,0 +1,7 @@
# yada - full bundle

## Testing

Testing this bundle is done from the top-level yada directory:

lein test
20 changes: 20 additions & 0 deletions bundles/full/project.clj
@@ -0,0 +1,20 @@
;; Copyright © 2014-2016, JUXT LTD.

(def VERSION "1.2.0-SNAPSHOT")

(defproject yada VERSION

:pedantic? :abort

:dependencies [[yada/aleph ~VERSION]
[yada/async ~VERSION]
[yada/bidi ~VERSION]
[yada/core ~VERSION]
[yada/json ~VERSION]
[yada/json-html ~VERSION]
[yada/jwt ~VERSION]
[yada/multipart ~VERSION]
[yada/oauth2 ~VERSION]
[yada/swagger ~VERSION]
[yada/transit ~VERSION]
[yada/webjars ~VERSION]])
Expand Up @@ -6,6 +6,7 @@
[bidi.bidi :as bidi]
yada.aleph
yada.async
yada.bidi
yada.context
[yada.handler :refer [interceptor-chain error-interceptor-chain]]
[yada.interceptors :as i]
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
Expand Up @@ -8,13 +8,19 @@ yada.process-request-body-test
[yada.interceptors :as i]
[yada.resource :refer [resource]]
[yada.request-body :refer [process-request-body]]
[yada.test-util :refer [is-coercing-correctly?]]
[byte-streams :as bs]
[schema.coerce :as sc]
[cognitect.transit :as transit])
(:import (clojure.lang ExceptionInfo Keyword)
(java.io ByteArrayOutputStream)))

(defmacro is-coercing-correctly?
[expected value content-type]
`(let [expected# ~expected
res# (process-request-body {} ~value ~content-type)]
(is (= {:body expected#}
res#))))

(declare thrown?)

(def ^:private test-map {:a "Hello" :b :foo :c [4 5 6]})
Expand Down
File renamed without changes.
Expand Up @@ -2,8 +2,15 @@
(:require [clojure.test :refer :all]
[schema.core :as s]
[byte-streams :as bs]
[yada.body :as sut]
[yada.test-util :refer [is-coercing-correctly?]]))
[yada.request-body :refer [process-request-body]]
[yada.body :as sut]))

(defmacro is-coercing-correctly?
[expected value content-type]
`(let [expected# ~expected
res# (process-request-body {} ~value ~content-type)]
(is (= {:body expected#}
res#))))

(def ^:private test-map {:a "Hello" :b :foo :c [4 5 6]})

Expand Down
File renamed without changes.
15 changes: 15 additions & 0 deletions bundles/lean/README.md
@@ -0,0 +1,15 @@
# yada - lean bundle

A replacement yada.yada namespace which contains a stripped down
interceptor chain and minimal dependencies.

Other dependencies can be added

## Testing

Testing this bundle is done from this directory:

lein test

This tests the core tests in the top-level `test` directory, adding a
few more tests contained in this bundle's `test` directory.
1 change: 1 addition & 0 deletions bundles/lean/dev/config.edn
@@ -0,0 +1 @@
{}
54 changes: 54 additions & 0 deletions bundles/lean/project.clj
@@ -0,0 +1,54 @@
;; Copyright © 2014-2016, JUXT LTD.

(def VERSION "1.2.0-SNAPSHOT")

(defproject yada/lean VERSION
:pedantic? :abort
:dependencies [[yada/aleph ~VERSION]
[yada/bidi ~VERSION]
[yada/core ~VERSION]]

:profiles
{:dev
{:jvm-opts ["-Xms1g" "-Xmx1g"
"-server"
"-Dio.netty.leakDetectionLevel=paranoid"
"-Dyada.dir=../../"]

:dependencies
[[org.clojure/clojure "1.8.0"]

;; Testing
[ring/ring-mock "0.3.0" :exclusions [ring/ring-codec]]

;; REPL and dev workflow
[org.clojure/tools.namespace "0.2.11"]
[org.clojure/tools.nrepl "0.2.12"]
[com.stuartsierra/component "0.3.2"]
[aero "1.0.1"]

;; Logging
[org.clojure/tools.logging "0.3.1"]
[ch.qos.logback/logback-classic "1.1.8"
:exclusions [org.slf4j/slf4j-api]]
[org.slf4j/jul-to-slf4j "1.7.22"]
[org.slf4j/jcl-over-slf4j "1.7.22"]
[org.slf4j/log4j-over-slf4j "1.7.22"]

;; Publishing user manual
[camel-snake-kebab "0.4.0"]
[org.asciidoctor/asciidoctorj "1.6.0-alpha.3"]
[markdown-clj "0.9.91"]

]

:source-paths ["../../dev/src" ;; yada.yada
"../../src" ;; core source
;; Extension sources
"../../ext/aleph/src"
"../../ext/bidi/src"]

;; For logback.xml
:resource-paths ["../../dev/resources"]

:test-paths ["../../test"]}})
11 changes: 5 additions & 6 deletions ext/lean/src/yada/lean.clj → bundles/lean/src/yada/yada.clj
@@ -1,27 +1,26 @@
;; Copyright © 2014-2016, JUXT LTD.

(ns yada.yada.lean
(ns yada.yada
(:refer-clojure :exclude [partial])
(:require
[bidi.bidi :as bidi]
yada.aleph
yada.bidi
yada.context
[yada.handler :refer [interceptor-chain error-interceptor-chain]]
[yada.interceptors :as i]
;; yada.multipart - still depends on swagger :(
[yada.parameters :refer [parse-parameters]]
yada.redirect
yada.resources.atom-resource
yada.resources.collection-resource
yada.resources.exception-resource
yada.resources.file-resource
yada.resources.string-resource
yada.resources.url-resource
;; yada.resources.sse - requires sse
[yada.security :as sec]
yada.test
yada.util
yada.wrappers
[potemkin :refer (import-vars)]))
[potemkin :refer [import-vars]]))

(import-vars
[yada.aleph listener server]
Expand All @@ -41,7 +40,7 @@
i/uri-too-long?
i/TRACE
i/method-allowed?
;; swgparams/parse-parameters
parse-parameters
i/capture-proxy-headers
sec/authenticate
i/get-properties
Expand Down
Expand Up @@ -3,11 +3,12 @@
(ns yada.bidi-test
(:require
[byte-streams :as b]
[clojure.string :as str]
[bidi.vhosts :refer [vhosts-model make-handler]]
[clojure.string :as str]
[clojure.test :refer :all]
[ring.mock.request :refer [request]]
[yada.yada :refer [uri-info resource]]))
[yada.yada :refer [uri-info resource]]
yada.bidi))

(deftest uri-info-test
(let [h
Expand Down
Expand Up @@ -2,9 +2,11 @@

(ns yada.response-for-test
(:require
[byte-streams :as b]
[clojure.test :refer :all]
[yada.test :refer [response-for]]
[yada.handler :refer [handler]]))
[yada.test :refer [response-for request-for]]
[yada.handler :refer [handler as-handler]]
yada.bidi))

(deftest response-for-test
(let [res (response-for ["/" (handler "foo")] :get "/")]
Expand Down
4 changes: 3 additions & 1 deletion dev/config.edn
@@ -1,4 +1,6 @@
{:docsite {:port 8090
{:listener {:host "http://localhost:8090" :port 8090}

:docsite {:port 8090
:vhosts #profile {:dev ["http://localhost:8090"]
:local ["http://yada.juxt.pro.local"]
:prod ["https://yada.juxt.pro" "http://yada.juxt.pro"]}}
Expand Down
36 changes: 0 additions & 36 deletions dev/src/yada/dev/async.clj

This file was deleted.

21 changes: 6 additions & 15 deletions dev/src/yada/dev/config.clj
Expand Up @@ -3,25 +3,16 @@
(ns yada.dev.config
(:require
[schema.core :as s]
[aero.core :refer (read-config)]
[phonebook.schema :refer [PhonebookEntry Phonebook UserPort]]))

(s/defschema ConfigSchema
{:docsite {:port UserPort
:vhosts [s/Str]}

:phonebook {:vhosts [s/Str]
:port UserPort
:entries Phonebook}})
[aero.core :as aero]))

(defn config
"Return a map of the static configuration used in the component
constructors."
[profile]
(read-config
"dev/config.edn"
{:profile profile
:schema ConfigSchema}))

(aero/read-config "dev/config.edn" {:profile profile}))

(defn get-listener-port [config]
(get-in config [:listener :port]))

(defn get-host [config]
(get-in config [:listener :host]))

0 comments on commit c936ef3

Please sign in to comment.