-
Notifications
You must be signed in to change notification settings - Fork 99
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Added ability to specify context-params in the project file. #192
Open
simon-brooke
wants to merge
1
commit into
weavejester:master
Choose a base branch
from
simon-brooke:master
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 | ||||
---|---|---|---|---|---|---|
|
@@ -100,24 +100,45 @@ | |||||
|
||||||
(def default-servlet-version "2.5") | ||||||
|
||||||
(defn make-context-params | ||||||
"Take this `params-map` and construct from it a sequence of | ||||||
s-expression representations of context-param elements." | ||||||
[params-map] | ||||||
(if | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||
(map? params-map) | ||||||
(map | ||||||
#(vector | ||||||
:context-param | ||||||
[:param-name (name %)] | ||||||
[:param-value (params-map %)]) | ||||||
(keys params-map)))) | ||||||
|
||||||
(defn make-web-sexpr | ||||||
"Take this `project` and construct from it an s-expression | ||||||
representation of the complete web.xml file" | ||||||
[project] | ||||||
(let [ring-options (:ring project)] | ||||||
[:web-app | ||||||
(get web-app-attrs | ||||||
(get-in project [:ring :servlet-version] default-servlet-version) | ||||||
{}) | ||||||
(make-context-params (:context-params ring-options)) | ||||||
[:listener | ||||||
[:listener-class (listener-class project)]] | ||||||
[:servlet | ||||||
[:servlet-name (servlet-name project)] | ||||||
[:servlet-class (servlet-class project)]] | ||||||
[:servlet-mapping | ||||||
[:servlet-name (servlet-name project)] | ||||||
[:url-pattern (url-pattern project)]]])) | ||||||
|
||||||
(defn make-web-xml [project] | ||||||
(let [ring-options (:ring project)] | ||||||
(if (contains? ring-options :web-xml) | ||||||
(slurp (:web-xml ring-options)) | ||||||
(indent-str | ||||||
(sexp-as-element | ||||||
[:web-app | ||||||
(get web-app-attrs | ||||||
(get-in project [:ring :servlet-version] default-servlet-version) | ||||||
{}) | ||||||
[:listener | ||||||
[:listener-class (listener-class project)]] | ||||||
[:servlet | ||||||
[:servlet-name (servlet-name project)] | ||||||
[:servlet-class (servlet-class project)]] | ||||||
[:servlet-mapping | ||||||
[:servlet-name (servlet-name project)] | ||||||
[:url-pattern (url-pattern project)]]]))))) | ||||||
(make-web-sexpr project)))))) | ||||||
|
||||||
(defn generate-handler [project handler-sym] | ||||||
(if (get-in project [:ring :servlet-path-info?] 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
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,21 @@ | ||
(ns leiningen.test.war | ||
(:require [clojure.test :refer :all] | ||
[leiningen.ring.war :refer :all])) | ||
|
||
(deftest test-generate-war | ||
(testing "Generation of context params elements" | ||
(is (empty? (make-context-params {})) | ||
"If no context params are specified, none should be generated") | ||
(is (empty? (make-context-params "froboz")) | ||
"If the argument to make-context-params is not a map, no context params should be generated") | ||
(is (= 1 (count (make-context-params {:foo "bar"}))) | ||
"If one context param is specified, one should be generated") | ||
(is (= '([:context-param [:param-name "foo"][:param-value "bar"]]) | ||
(make-context-params {:foo "bar"}))) | ||
(is (= '([:context-param [:param-name "foo"][:param-value 123]]) | ||
(make-context-params {:foo 123}))) | ||
(is (= 2 (count (make-context-params {:foo "bar" :froboz "baz"}))) | ||
"If two context params are specified, two should be generated")) | ||
(testing "Generation of war file" | ||
(is (= "" (make-web-xml {:ring {:web-xml "/dev/null"}})) | ||
"If a file path is specified as :web-xml, the content of that file should be returned"))) |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This should be a when, since it doesn't appear to have an else clause