Re: using tinymce in cl-http

Rainer Joswig <[email protected]> Mon, 16 Feb 2009 17:20:05 +0100
Newsgroups gmane.lisp.cl-http
Message-ID <[email protected]>
Am 13.02.2009 um 20:00 schrieb Mark Klein:

>
> Has anyone had any success using a javascript HTML editor (e.g.
> tinymce) in a page generated by cl-http? I've had no luck, and I'd
> appreciate any pointers people may have.

Hi Mark,

the following example works for me.

I have changed the WITH-SCRIPT macro so that it does not put the  
script into comments.
Then I have also added the .js file extension to javascript files.

You might need to change the directories and URLs. I've downloaded a  
copy of tinymce,
extracted the files and exported the javascript directory.

The form function generates the form and puts a string into a textarea.
The response function saves that string back into a global variable.

I can then edit the text with styles and get HTML back on submit.

Regards,

Rainer


(in-package "HTML4.0")

(define-macro with-script ((media-type &key script-location no-content  
charset language (stream '*output-stream*)) &body body)
   "Provides an environment for emitting a client-side script with  
MEDIA-TYPE on STREAM.

MEDIA-TYPE is required and must be the content type for the scripting  
language, like:

      (:text :javascript)  -- JavaScript script
      (:text :tcl)         -- TCL script
      (:text :vbscript)    -- Visual Basic script

MEDIA-TYPE overrides any default scripting language declarations in  
the document preamble.

BODY executes code that emit the script the source on STREAM, or  
alternatively
SCRIPT-LOCATION may used to designate a URI that loads the script text  
into the client.

NO-CONTENT is a boolean that informs the browser that the script  
emitted within BODY or
loaded from SCRIPT-LOCATION will not display content, and so, the  
browser may handle
this asynchronously and continue rendering the document.

CHARSET is the character encoding of the script text (see ISO 10646).

LANGUAGE (deprecated) is keyword or string identifying the scripting  
language."
   `(%with-environment
        ("script" :stream ,stream)
        (%write-with-script-arguments ,stream ,media-type ,script- 
location ,no-content ,charset ,language)
      (fresh-line stream)

        ,@body))

;;; Example

(in-package "HTTP-USER")

(http:define-url-export-type :java-script-file :javascript
                              (:text :javascript)
                              :copy-mode #.http::+standard-text-copy- 
mode+
                              :data-type :text
                              :alternate-extensions (:js))

(http:export-url #u"/js/tiny_mce/"
                  :directory
                  :pathname (pathname "/Lisp/software/CL-HTTP-archive/ 
tinymce/jscripts/tiny_mce/")
                  :recursive-p t)

(defparameter *mytext* "Hi there from CL-HTTP.")

(defun generate-tinymce-example (url stream)
   (declare (ignore url))
   (with-successful-response (stream :html)
     (with-html-document (:stream stream)
       (with-document-preamble (:stream stream)
         (declare-title "tinymce example" :stream stream)
         (with-script ('(:text :javascript) :script-location "/js/ 
tiny_mce/tiny_mce.js" :stream stream))
         (with-script ('(:text :javascript) :stream stream)
           (princ "tinyMCE.init({mode : \"textareas\" });" stream)))
       (with-document-body (:stream stream)
         (html:with-fillout-form (:post #u"/tinymceexample" :stream  
stream)
           (html:accept-input 'html:multi-line-text "content"
                              :default *mytext*
                              :stream stream)
           (html2:break-line :stream stream)
           (html:with-rendition (:bold :stream stream)
             (html:accept-input 'html:submit-button "Submit" :stream  
stream)))))))

(defun generate-tinymce-example-response (url stream query-alist)
   (http:bind-query-values (content) (url query-alist)
     (setf *mytext* content)
     (generate-tinymce-example url stream)))

(http:export-url #u"/tinymceexample"
                  :computed-form
                  :form-function 'generate-tinymce-example
                  :response-function 'generate-tinymce-example-response)





>
>
> 	Mark
>
> -----------------
> Mark Klein
> Principal Research Scientist
> MIT Center for Collective Intelligence
> http://cci.mit.edu/klein/
>
>
>
>
>
> _______________________________________________
> WWW-CL mailing list
> [email protected]
> https://lists.csail.mit.edu/mailman/listinfo/www-cl

Rainer Joswig, Hamburg, Germany
http://lispm.dyndns.org/
mailto:[email protected]




_______________________________________________
WWW-CL mailing list
[email protected]
https://lists.csail.mit.edu/mailman/listinfo/www-cl