templates.lisp 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123
  1. ;;;; templates.lisp
  2. (in-package #:genie)
  3. ;;; "templates" goes here. Hacks and glory await!
  4. (defmacro define-html-template (name input &optional docstring)
  5. (let* ((old-name name)
  6. (name (intern (string-upcase old-name)))
  7. (docstring (if docstring
  8. docstring
  9. (format nil "Template caller for ~a, as ~a" old-name name)))
  10. (input (merge-pathnames input (asdf:system-source-directory '#:museum-system))))
  11. `(defun ,name (&rest args)
  12. ,docstring
  13. (with-output-to-string (*standard-output*)
  14. (funcall (create-template-printer ,input) args)))))
  15. (defmacro generate-static (name filename type script)
  16. (declare (string filename)
  17. (symbol type)
  18. (type (or string symbol) name))
  19. (let* ((name (intern (string-upcase name)))
  20. (type (getf (list :js "application/javascript"
  21. :javascript "application/javascript"
  22. :css "text/css")
  23. type)))
  24. `(define-route ,name (,filename
  25. :content-type ,type)
  26. ,script)))
  27. (defmacro define-css-page (name filename &rest body)
  28. (let* ((name (intern (string-upcase filename)))
  29. (css-chunks (map 'list #'compile-and-write body))
  30. (css (format nil "~{~a~^~%~%~}" css-chunks)))
  31. `(generate-static ,name
  32. ,filename
  33. :css
  34. ,css)))
  35. (defmacro define-js-page (name filename &rest script)
  36. (let ((name (intern (string-upcase filename))))
  37. `(generate-static ,name
  38. ,filename
  39. :javascript
  40. (ps ,@script))))
  41. (setq parenscript:*js-string-delimiter* #\")
  42. (setq html-template:*string-modifier* #'cl:identity)
  43. (define-css-page main.css "main.css"
  44. (*
  45. :margin 0
  46. :padding 0
  47. :font-family "Georgia, Palantino, Times, 'Times New Roman', sans-serif")
  48. (body
  49. :backgroud "#fff")
  50. (a
  51. :text-decoration "none")
  52. ("a:link, a:visited"
  53. :color "#f30")
  54. ("a:hover"
  55. :color "#f90")
  56. (div.main-content
  57. :position "absolute"
  58. :top "40px"
  59. :left "280px"
  60. :width "500px"
  61. (h1
  62. :font-size "40px"
  63. :font-weight "normal"
  64. :line-height "43px"
  65. :letter-spacing "-1px")
  66. (div.results
  67. :margin-top "20px"
  68. (ul
  69. :list-style-type "none")
  70. (li
  71. :font-size "18px"
  72. :line-height "24px"
  73. :margin-left "70px"))
  74. (div.page-list
  75. :text-align "center"
  76. :float "bottom")
  77. (dl
  78. :margin-top "10px")
  79. (dt
  80. :font-size "18px"
  81. :font-weight "bold")
  82. (dd
  83. :margin-left "20px"
  84. :margin-bottom "15px"))
  85. (div.nav
  86. :position absolute
  87. :top "40px"
  88. :left "20px"
  89. :width "200px"
  90. :padding "20px 20px 0 0"
  91. :border-right "1px solid #ccc"
  92. :text-align "right"
  93. (h2
  94. :text-transform "uppercase"
  95. :font-size "13px"
  96. :color "#333"
  97. :letter-spacing "1px"
  98. :line-height "20px"
  99. (a
  100. :color "#333"))
  101. (ul
  102. :list-style-type "none"
  103. :margin "20px 0")
  104. (li
  105. :font-size "14px"
  106. :line-height "20 px")
  107. (hr
  108. :height "1px"
  109. :color "#ccc"
  110. :margin-top "5px"
  111. :margin-bottom "5px")))
  112. (define-html-template main-page "mainpage.httmpl")