Web Sequence Diagram

Started by PapoAnaya, January 28, 2010, 03:13:03 PM

Previous topic - Next topic

PapoAnaya

I was dabbling one night and I decided to translate the code to create sequence diagrams from websequencediagrams.com from python to newLisp.



The code might need some improvement, but it does work for me.





;;
;; Web Sequence Diagram Interface
;;

(define (url-encode str)  
    (replace {([^a-zA-Z0-9])} str (format "%%%2X" (char $1)) 0))


(define (url-decode str)
    (replace "+" str " ") ; optional
    (replace "%([0-9A-F][0-9A-F])" str (format "%c" (int (append "0x" $1))) 1))


(define (getSequenceDiagram text outputfile (style "default") )
  (set 'request (list (eval 'text) (eval 'style)) )
  (set 'urladdress "http://www.websequencediagrams.com/index.php")
  (set 'urldata (join (list "message=" text "&style=" (url-encode style) )))
  (set 'result (post-url  urladdress urldata ) )
  (set 'expr (regex "(\?img=[a-zA-Z0-9]+)" result ))
  (if (nil? expr)
      (write-line "Something went wrong")
      (let ()
         (set 'image (get-url (join (list "http://www.websequencediagrams.com/" (first expr) ) )) )
         (write-file outputfile image)  
      )
  )
)

(getSequenceDiagram "alice->bob: authentication request n bob-->alice: response" "c:\out.png" "qsd")


hilti

#1
Pretty cool! Thanks for sharing it.



Cheers

Hilti
--()o Dragonfly web framework for newLISP

http://dragonfly.apptruck.de\">http://dragonfly.apptruck.de