diff --git a/src/statuses/views/form.clj b/src/statuses/views/form.clj new file mode 100644 index 0000000..d48ecde --- /dev/null +++ b/src/statuses/views/form.clj @@ -0,0 +1,19 @@ +(ns statuses.views.form + (:require [hiccup.def :refer [defelem]] + [hiccup.util :refer [to-uri]])) + +(defelem form-to + "Create a form that points to a particular method and route. + e.g. (form-to [:put \"/post\"] + ...)" + [[method action] & body] + (let [method-str (.toUpperCase (name method)) + action-uri (to-uri action)] + (-> (if (contains? #{:get :post} method) + [:form {:method method-str, :action action-uri}] + [:form {:method "POST", :action action-uri} + [:input {:type "hidden" + :name "_method" + :value method-str}]]) + (concat body) + (vec)))) diff --git a/src/statuses/views/main.clj b/src/statuses/views/main.clj index 51803a0..bd81f2e 100644 --- a/src/statuses/views/main.clj +++ b/src/statuses/views/main.clj @@ -2,11 +2,12 @@ (:require [clj-time.local :refer [format-local-time]] [hiccup.core :refer [html]] [hiccup.element :refer [link-to]] - [hiccup.form :refer [form-to hidden-field text-field]] + [hiccup.form :refer [hidden-field text-field]] [statuses.configuration :refer [config]] [statuses.routes :refer [avatar-path update-path updates-path]] [statuses.views.common :as common :refer [icon]] + [statuses.views.form :refer [form-to]] [statuses.views.layout :as layout])) (defn- button