Commits

Anonymous committed c705a01

Added ability to put links in the head section of a page, similar to setting the page's title. verified that if the same link aappears more than once, it is only rendered to the page once.

Comments (0)

Files changed (1)

   'render-as-html
   '+@
   '+title
+  '+link
   'hout
   'expansion
   'tags
   "The title of the page as it should be presented to the user in the browser"
 )
 
+(defvar *page-links* ()
+  "A list of link tags that should appear in the head of the page"
+  )
+
 (defvar *page-scripts*
       ()
   "A list of strings, each representing a script added to the page"
      )
   )
 
+(defmacro +link (
+		 &key
+		 ((:rel rel) nil)
+		 ((:type type) nil)
+		 ((:href href) nil)
+		 )
+  `(progn
+     (pushnew (list ,rel ,type ,href)
+	      *page-links*
+	      :test 'equal
+	      )
+     nil
+     )
+  )
+
 (defmacro defhtmltag (name
 		      &key
 		      ((:tag tag) nil)
   "Interpret the body as html markup, returning an HTML fragment"
   `(let (
 	 (*page-title* ())
+	 (*page-links* ())
 	 (*page-style-sheets* ())
 	 (*page-styles* ())
 	 (*page-script-libraries* ())
 		      )
 	     )
 	   )
-       (values content *page-title* *page-style-sheets* *page-styles* *page-script-libraries* *page-scripts* *page-ready-scripts*)
+       (values content *page-title* *page-links* *page-style-sheets* *page-styles* *page-script-libraries* *page-scripts* *page-ready-scripts*)
        )
      )
   )
   "Interpret the raw body as html markup, and return a complete HTML page"
   `(multiple-value-bind (page-attributes body) (separate-initializer-and-body (quote ,raw-body))
      (declare (ignorable page-attributes body ) )
-     (multiple-value-bind (page-content *page-title* *page-style-sheets* *page-styles* *page-script-libraries* *page-scripts* *page-ready-scripts*) 
+     (multiple-value-bind (page-content *page-title* *page-links* *page-style-sheets* *page-styles* *page-script-libraries* *page-scripts* *page-ready-scripts*) 
 	   (html (list ,@raw-body) )
 					; now render the page
 	 (with-output-to-string (*html-out*)
 	   (hout "<head>~%")
 
 	   (when *page-title*
-	     (hout "<title>~a</title>" *page-title*)
+	     (hout "<title>~a</title>~%" *page-title*)
+	     )
+
+	   (when *page-links*
+	     (dolist (link *page-links*)
+	       (destructuring-bind (rel type href) link
+		 (hout "<link~@[ rel='~a'~]~@[ type='~a'~]~@[ href='~a'~]/>~%"
+		       rel type href
+		       )
+		 )
+	       )	     
 	     )
 
 	   (when *page-style-sheets*
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.