Skip to content

Commit

Permalink
form-to -> form
Browse files Browse the repository at this point in the history
  • Loading branch information
mmcgrana committed Jan 21, 2009
1 parent 2bd5382 commit 7411d80
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 17 deletions.
27 changes: 13 additions & 14 deletions clj-html-helpers-ext/src/clj_html/helpers_ext.clj
Expand Up @@ -55,20 +55,19 @@
[text]
(html [:input {:type "submit" :name "commit" :value text}]))

(defn form-to
(defn form
"Returns html for a form."
([target body]
(form-to target nil body))
([[method url] opts body]
(if (browser-method? method)
(html
[:form {:method (method-str method) :action url}
body])
(html
[:form {:method "post" :action url
:enctype (if (get opts :multipart) "multipart/form-data")}
(hidden-field-tag "_method" (method-str method))
body]))))
[opts body]
(let [[method url] (get opts :to)]
(if (browser-method? method)
(html
[:form {:method (method-str method) :action url}
body])
(html
[:form {:method "post" :action url
:enctype (if (get opts :multipart) "multipart/form-data")}
(hidden-field-tag "_method" (method-str method))
body]))))

(defn link-to
"Returns html for a link with anchor text to the url."
Expand All @@ -80,7 +79,7 @@
"Returns html for a form consisting only of a button that, when clicked,
will send a delete request to the given path."
[text url]
(form-to [:delete url]
(form {:to [:delete url]}
(submit-tag text)))

(def #^{:private true} mime-type-strs
Expand Down
6 changes: 3 additions & 3 deletions clj-html-helpers-ext/test/clj_html/helpers_ext_test.clj
Expand Up @@ -33,11 +33,11 @@
(assert= "<input name=\"commit\" type=\"submit\" value=\"foo\" />"
(submit-tag "foo")))

(deftest "form-to"
(deftest "form"
(assert= "<form action=\"/foo\" method=\"get\">inner</form>"
(form-to [:get "/foo"] "inner"))
(form {:to [:get "/foo"]} "inner"))
(assert= "<form method=\"post\" action=\"/foo\"><input type=\"hidden\" name=\"_method\" value=\"put\" />inner</form>"
(form-to [:put "/foo"] "inner")))
(form {:to [:put "/foo"]} "inner")))

(deftest "link-to"
(assert= "<a href=\"/bar\" title=\"foo\">foo</a>"
Expand Down

0 comments on commit 7411d80

Please sign in to comment.