Web Sequence Diagram

Featuring the Dragonfly web framework
Locked
PapoAnaya
Posts: 16
Joined: Mon Oct 24, 2005 6:55 pm

Web Sequence Diagram

Post by 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.

Code: Select all

;;
;; 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
Posts: 140
Joined: Sun Apr 19, 2009 10:09 pm
Location: Hannover, Germany
Contact:

Re: Web Sequence Diagram

Post by hilti »

Pretty cool! Thanks for sharing it.

Cheers
Hilti
--()o Dragonfly web framework for newLISP
http://dragonfly.apptruck.de

Locked