Convert Sandvox form to work with Lift

While I like Sandvox a lot and used it to make a few pages for my company, I want to make a script to convert the contact form generated by sandbox to be processed by the lift snippet mechanism. That is quite easy to do with the Clojure laser module:

File core.clj:

(ns convert-sandvox-form.core
  (:require [me.raynes.laser :as l]
            [clojure.java.io :refer [file]])
  (:gen-class))

(defn -main [filename]

  (let [ corrhtml (l/document (l/parse (file filename))
                              (l/descendant-of (l/id= "contactform")
                                               (l/element= :script)) (l/remove)
                              (l/descendant-of (l/element= :form)
                                               (l/class= "hidden")) (l/remove)
                              (l/element= :form) (l/attr :action "")
                              (l/element= :form) (l/attr :onsubmit "")
                              (l/element= :form) (l/attr :method "")
                              (l/element= :form) (l/add-class "lift:UserFeedBack?form=post")
                              (l/id= "contactform-results") (l/add-class "lift:Msg?id=msgcontact&errorClass=error")
                              )]
    (spit filename corrhtml)))

It will overwrite the original HTML file.


comments powered by Disqus
© MKRRF IT LIMITED 2013