;;;# The HTML Generator
;;;t \index{PS-HTML}
;;;t \index{HTML generation}
-;;;t \index{CSS}
-;;;t \index{CSS generation}
-
; (PS-HTML html-expression)
+ (disabled || !authorized ? ' disabled=\"' + 'disabled' + '\"' : '')
+ '>Edit me</textarea>';
-; (CSS-INLINE css-expression)
-
-;;; Stylesheets can also be created in ParenScript.
-
-(css-inline :color "red"
- :font-size "x-small")
- => 'color:red;font-size:x-small'
-
-(defun make-color-div(color-name)
- (return (ps-html ((:div :style (css-inline :color color-name))
- color-name " looks like this."))))
- => function makeColorDiv(colorName) {
- return '<div style=\"' + ('color:' + colorName) + '\">' + colorName
- + ' looks like this.</div>';
- }
-
;;;# Macrology
;;;t \index{macro}
;;;t \index{macrology}
:author "Manuel Odendahl <manuel@bl0rg.net>"
:maintainer "Vladimir Sedach <vsedach@gmail.com>"
:licence "BSD"
- :description "Parenscript is a lispy language that compiles to Javascript."
+ :description "Parenscript is a Lispy language that compiles to JavaScript."
:components ((:static-file "parenscript.asd")
(:module :src
:serial t
(:file "deprecated-interface")
;; standard library
(:module :lib
- :components ((:static-file "functional.lisp")
- (:file "js-html")
- (:file "css" )
- (:file "js-utils")
- (:file "js-lib"))
+ :components ((:file "ps-html")
+ (:file "ps-macro-lib")
+ (:file "ps-runtime-lib"))
:depends-on ("compilation-interface")))))
:depends-on ())
+++ /dev/null
-(in-package :parenscript)
-
-(defun make-css-rule (selectors properties)
- (list (mapcar #'val-to-string
- (if (atom selectors)
- (list selectors)
- selectors))
- properties))
-
-(defun css-rule-selectors (css-rule)
- (first css-rule))
-
-(defun css-rule-properties (css-rule)
- (second css-rule))
-
-(defmacro css-rule (selectors &rest properties)
- `(make-css-rule ',selectors ',properties))
-
-(defun propval-to-string (propval)
- (format nil "~A:~A" (val-to-string (first propval))
- (val-to-string (second propval))))
-
-(defun css-rule-to-string (css-rule)
- (format nil "~A {~%~{~A;~%~}}~%~%"
- (string-join (css-rule-selectors css-rule) ",")
- (loop for propval on (css-rule-properties css-rule) by #'cddr
- collect (concatenate 'string " " (propval-to-string propval)))))
-
-(defun css-to-string (rules)
- (string-join (mapcar #'css-rule-to-string rules) "; "))
-
-(defmacro css (&rest rules)
- `((:style :type "text/css")
- (:princ #\Newline "<!--" #\Newline)
- (:princ ,@(mapcar #'(lambda (rule) `(css-rule-to-string (css-rule ,@rule))) rules))
- (:princ "-->" #\Newline)))
-
-(defun css-inline-func (proplist)
- (string-join (loop for propval on proplist by #'cddr
- collect (propval-to-string propval))
- ";"))
-
-(defmacro css-inline (&rest propvals)
- `(parenscript::css-inline-func ,propvals))
-
-(defmacro css-file (&rest rules)
- `(html
- (:princ
- ,@(mapcar #'(lambda (rule) `(css-rule-to-string (css-rule ,@rule))) rules))))
-
-;;; examples
-
-;;; generate a CSS file
-#+nil
-(html-stream *standard-output*
- (css-file (* :border "1px solid black")
- (div.bl0rg :font-family "serif")
- (("a:active" "a:hoover") :color "black" :size "200%")))
-
-
-;;; generate an inline CSS spec in a HTML head element
-#+nil
-(html-stream *standard-output*
- (html
- (:html
- (:head
- (css (* :border "1px solid black")
- (div.bl0rg :font-family "serif")
- (("a:active" "a:hoover") :color "black" :size "200%"))))))
-
-;;; generate a style attribute for a DIV element
-#+nil
-(html-stream *standard-output*
- (html (:html (:body ((:div :style (css-inline :border "1px solid black"))
- "foobar")))))
-
(declare (ignore expecting))
(compile-parenscript-form (process-html-forms forms)))
-(defun process-css-forms (proplist)
- (optimize-string-list (butlast
- (loop for propval on proplist by #'cddr appending
- (list (string-downcase (symbol-name (first propval)))
- ":"
- (second propval)
- ";")))))
-
-
-(define-ps-special-form css-inline (expecting &rest forms)
- (declare (ignore expecting))
- (compile-parenscript-form (cons '+ (process-css-forms forms))))
#:while
;; v v v STUFF WE SHOULD PROBABLY MOVE TO OTHER LIBS v v v
-
- ;; CSS
- #:css
- #:css-to-string
- #:css-inline
- #:css-file
;; html generator for javascript
#:ps-html
(when keep-separators (push (string (char string i)) res))
(setf last (1+ i)))))
+(defun concat-constant-strings (list)
+ (reverse (reduce (lambda (optimized-list next-obj)
+ (if (and (or (numberp next-obj) (stringp next-obj)) (stringp (car optimized-list)))
+ (cons (format nil "~a~a" (car optimized-list) next-obj) (cdr optimized-list))
+ (cons next-obj optimized-list)))
+ (cons () list))))
+
(defparameter *special-chars*
'((#\! . "Bang")
(#\? . "What")
(a-parenthesis #\)))
(is (char= char-before a-parenthesis))))
-;; A problem with long nested operator, when the statement spanned several rows
-;; the rows would not be joined together correctly.
-(test-ps-js bug-dwim-join
- (alert (ps-html ((:div :id 777
- :style (css-inline :border "1pxsssssssssss"
- :font-size "x-small"
- :height (* 2 200)
- :width (* 2 300))))))
- "alert('<div id=\"777\" style=\"'
- + ('border:1pxsssssssssss;font-size:x-small;height:' + 2 * 200 + ';width:'
- + 2 * 300)
- + '\"></div>')") ;";This line should start with a plus character.
-
-
(test-ps-js simple-slot-value
(let* ((foo (create :a 1)))
(alert (slot-value foo 'a)))
+ (disabled || !authorized ? ' disabled=\"' + 'disabled' + '\"' : '')
+ '>Edit me</textarea>';")
-(test-ps-js the-html-generator-5
- (css-inline :color "red"
- :font-size "x-small")
- "'color:red;font-size:x-small'")
-
-(test-ps-js the-html-generator-6
- (defun make-color-div(color-name)
- (return (ps-html ((:div :style (css-inline :color color-name))
- color-name " looks like this."))))
- "function makeColorDiv(colorName) {
- return '<div style=\"' + ('color:' + colorName) + '\">' + colorName
- + ' looks like this.</div>';
-}")
-