/[claw]/trunk/main/claw-html/src/tags.lisp
ViewVC logotype

Diff of /trunk/main/claw-html/src/tags.lisp

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 183 by achiumenti, Fri Dec 26 07:24:28 2008 UTC revision 184 by achiumenti, Tue Jan 13 13:03:03 2009 UTC
# Line 301  an unique id attribute when provided. Line 301  an unique id attribute when provided.
301    "The CLAW page currently rendering    "The CLAW page currently rendering
302  ")  ")
303    
304    (defvar *calw-this-component* nil
305      "Variable set when rendering a WCOMPONENT-TEMPLATE so it is accessible inside the template")
306    
307  (defvar *id-table-map* (make-hash-table :test 'equal)  (defvar *id-table-map* (make-hash-table :test 'equal)
308    "Holds an hash table of used components/tags id as keys and the number of their occurrences as values.    "Holds an hash table of used components/tags id as keys and the number of their occurrences as values.
309  So if you have a :id \"compId\" given to a previous component, the second  So if you have a :id \"compId\" given to a previous component, the second
# Line 396  When used with :STATIC-ID the generated Line 399  When used with :STATIC-ID the generated
399           (id (getf attributes :id))           (id (getf attributes :id))
400           (static-id (getf attributes :static-id))           (static-id (getf attributes :static-id))
401           (render-condition (getf attributes :render-condition))           (render-condition (getf attributes :render-condition))
402             (claw-type (getf attributes :clawtype))
403           (real-id (or static-id id))           (real-id (or static-id id))
404           (instance))           (instance))
405      (when static-id      (when static-id
# Line 403  When used with :STATIC-ID the generated Line 407  When used with :STATIC-ID the generated
407        (setf id nil))        (setf id nil))
408      (when render-condition      (when render-condition
409        (remf attributes :render-condition))        (remf attributes :render-condition))
410      (setf instance (make-instance parent      (if claw-type
411                                    :empty emptyp        (let (clawtype-sybol-list (split "([:]){1,2}" (string-upcase claw-type)))
412                                    :real-id real-id          (if (second clawtype-sybol-list)
413                                    :name (string-downcase tag-name)              (setf claw-type (find-symbol (second clawtype-sybol-list)
414                                    :render-condition render-condition                                           (first clawtype-sybol-list)))
415                                    :attributes attributes              (setf claw-type (find-symbol (first clawtype-sybol-list))))
416                                    :body (second fbody)))          (make-component claw-type attributes (second fbody)))
417      (when real-id        (progn
418        (if (null static-id)          (setf instance (make-instance (or claw-type parent)
419            (when (and id-table-map id)                                        :empty emptyp
420              (setf (htcomponent-client-id instance) (generate-id id)))                                        :real-id real-id
421            (setf (htcomponent-client-id instance) static-id)))                                        :name (string-downcase tag-name)
422      instance))                                        :render-condition render-condition
423                                          :attributes attributes
424                                          :body (second fbody)))
425            (when real-id
426              (if (null static-id)
427                  (when (and id-table-map id)
428                    (setf (htcomponent-client-id instance) (generate-id id)))
429                  (setf (htcomponent-client-id instance) static-id)))
430            instance))))
431    
432  (defun generate-tagf (tag-name emptyp)  (defun generate-tagf (tag-name emptyp)
433    "Internal function that generates an htcomponent creation function from the component class name    "Internal function that generates an htcomponent creation function from the component class name
# Line 487  Only components with a matching id and t Line 499  Only components with a matching id and t
499                               :documentation "Symbol for page charset encoding \(Such as UTF-8)")                               :documentation "Symbol for page charset encoding \(Such as UTF-8)")
500     (injection-writing-p :initform nil     (injection-writing-p :initform nil
501                          :accessor page-injection-writing-p                          :accessor page-injection-writing-p
502                          :documentation "Flag that becomes true when rendering page injections"))                          :documentation "Flag that becomes true when rendering page injections")
503       (teamplate :initarg :template
504                  :accessor template
505                  :documentation "A lambda function with no parameters that, when not nil, is used as page-content."))
506    (:default-initargs :writer t    (:default-initargs :writer t
507      :external-format-encoding :utf-8      :external-format-encoding :utf-8
508      :script-files nil      :script-files nil
# Line 501  Only components with a matching id and t Line 516  Only components with a matching id and t
516      :xmloutput nil      :xmloutput nil
517      :doc-type *html-4.01-transitional*      :doc-type *html-4.01-transitional*
518      :request-parameters nil      :request-parameters nil
519        :template nil
520      :mime-type "text/html")      :mime-type "text/html")
521    (:documentation "A page object holds claw components to be rendered") )    (:documentation "A page object holds claw components to be rendered") )
522    
523    (defmethod page-content ((page page))
524      (when-let (lambda-content (template page))
525        (funcall lambda-content)))
526    
527  (defun make-page-renderer (page-class http-post-parameters http-get-parameters)  (defun make-page-renderer (page-class http-post-parameters http-get-parameters)
528    "Generates a lambda function from PAGE-RENDER method, that may be used into LISPLET-REGISTER-FUNCTION-LOCATION"    "Generates a lambda function from PAGE-RENDER method, that may be used into LISPLET-REGISTER-FUNCTION-LOCATION"
529    #'(lambda () (with-output-to-string (*standard-output*)    #'(lambda () (with-output-to-string (*standard-output*)
# Line 572  If the value is T then component will be Line 592  If the value is T then component will be
592    (:default-initargs :raw nil)    (:default-initargs :raw nil)
593    (:documentation "Component needed to render strings"))    (:documentation "Component needed to render strings"))
594    
595    (defclass htignore (htcomponent)
596      ()
597      (:documentation "Ignore all content"))
598    
599    
600    
601  (defmethod initialize-instance :after ((inst tag) &rest keys)  (defmethod initialize-instance :after ((inst tag) &rest keys)
# Line 589  If the value is T then component will be Line 613  If the value is T then component will be
613    "Creates a non escaping htstring component"    "Creates a non escaping htstring component"
614    (make-instance 'htstring :body value :raw t))    (make-instance 'htstring :body value :raw t))
615    
616    (defun ignore> (&rest ignore)
617      "Creates an ignore content"
618      (declare (ignore ignore))
619      (make-instance 'htignore))
620    
621  (defclass htscript (tag) ()  (defclass htscript (tag) ()
622    (:documentation "Creates a component for rendering a <script> tag"))    (:documentation "Creates a component for rendering a <script> tag"))
623    
# Line 1062  If the value is T then component will be Line 1091  If the value is T then component will be
1091                (htcomponent-render injection page)))                (htcomponent-render injection page)))
1092            (tag-render-endtag hthead page))))))            (tag-render-endtag hthead page))))))
1093    
1094    ;;;========= HTIGNORE ===================================
1095    (defmethod htcomponent-rewind((htignore htignore) (page page)))
1096    (defmethod htcomponent-prerender((htignore htignore) (page page)))
1097    (defmethod htcomponent-render ((htignore htignore) (page page)))
1098    
1099  ;;;========= HTSTRING ===================================  ;;;========= HTSTRING ===================================
1100    
1101  (defmethod htcomponent-rewind((htstring htstring) (page page)))  (defmethod htcomponent-rewind((htstring htstring) (page page)))
# Line 1222  Informal parameters are the ones not def Line 1256  Informal parameters are the ones not def
1256     (allow-informal-parameters :initarg :allow-informal-parameters     (allow-informal-parameters :initarg :allow-informal-parameters
1257                                :reader wcomponent-allow-informal-parametersp                                :reader wcomponent-allow-informal-parametersp
1258                                :allocation :class                                :allocation :class
1259                                :documentation "Determines if the component accepts informal parameters"))                                :documentation "Determines if the component accepts informal parameters")
1260       (teamplate :initarg :template
1261                  :accessor template
1262                  :documentation "A lambda function with no parameters that, when not nil, is used as page-content. *CLAW-THIS-COMPONENT* is set as a closure, so that may be directly used inside the template."))
1263    (:default-initargs :reserved-parameters nil    (:default-initargs :reserved-parameters nil
1264      :allow-informal-parameters t)      :allow-informal-parameters t)
1265    (:documentation "Base class for creationg customized web components. Use this or one of its subclasses to make your own."))    (:documentation "Base class for creationg customized web components. Use this or one of its subclasses to make your own."))
1266    
1267    (defmethod wcomponent-template ((wcomponent wcomponent))
1268      (let ((*claw-this-component* wcomponent))
1269        (when-let (lambda-content (template page))
1270          (funcall lambda-content))))
1271    
1272  (defmethod wcomponent-created ((wcomponent wcomponent))  (defmethod wcomponent-created ((wcomponent wcomponent))
1273    nil)    nil)
1274    
# Line 1270  Informal parameters are the ones not def Line 1312  Informal parameters are the ones not def
1312  (defun make-component (name parameters content)  (defun make-component (name parameters content)
1313    "This function instantiates a wcomponent by the passed NAME, separetes parameters into formal(the ones that are the    "This function instantiates a wcomponent by the passed NAME, separetes parameters into formal(the ones that are the
1314  initarg of a slot, and informal parameters, that have their own slot in common. The CONTENT is the body content."  initarg of a slot, and informal parameters, that have their own slot in common. The CONTENT is the body content."
1315      (remf :clawtype parameters)
1316    (unless (or (getf parameters :id)    (unless (or (getf parameters :id)
1317                (getf parameters :static-id))                (getf parameters :static-id))
1318      (setf (getf parameters :id) "claw"))      (setf (getf parameters :id) "claw"))

Legend:
Removed from v.183  
changed lines
  Added in v.184

  ViewVC Help
Powered by ViewVC 1.1.5