From 8171819db55768521199ffca09ea875b6843fed4 Mon Sep 17 00:00:00 2001
From: Cherie Yang <cyang@common-lisp.net>
Date: Mon, 24 Apr 2017 16:35:35 -0400
Subject: [PATCH] Add functions for including CSS files (basic, WIP)

---
 globals.lisp                  |  2 +-
 helpers.lisp                  |  4 ++--
 layout/css/main.css           | 16 ++++++++++++++++
 layout/templates/primary.html | 19 +++++++++++++++++--
 main.lisp                     |  4 +++-
 process.lisp                  | 17 +++++++++++++----
 6 files changed, 52 insertions(+), 10 deletions(-)
 create mode 100644 layout/css/main.css

diff --git a/globals.lisp b/globals.lisp
index 1ac885b..54b7d6c 100644
--- a/globals.lisp
+++ b/globals.lisp
@@ -14,7 +14,7 @@
 ;; Location and list of styles
 ;; *STYLES* should be list of strings representing relative filenames.
 ;; @TO-DO: replace this with better css preprocessing.
-(defparameter *STYLES-DIR* (asdf:system-relative-pathname :cl-site "content/css/"))
+(defparameter *STYLES-DIR* (asdf:system-relative-pathname :cl-site "layout/css/"))
 (defparameter *STYLES* 
   (list "main.css"))
 
diff --git a/helpers.lisp b/helpers.lisp
index a7289df..044727a 100644
--- a/helpers.lisp
+++ b/helpers.lisp
@@ -2,8 +2,8 @@
 (in-package :cl-site)
 
 ; Makes pathname from prefix + page object
-(defun make-path (prefix page)
-  (let ((path (cdr (assoc :content page))))
+(defun make-path (prefix suffix &optional page)
+  (let ((path (if page (cdr (assoc :content suffix)) suffix)))
     (if (pathnamep prefix)
         (merge-pathnames path prefix)
         (pathname (concatenate 'string 
diff --git a/layout/css/main.css b/layout/css/main.css
new file mode 100644
index 0000000..c6b3413
--- /dev/null
+++ b/layout/css/main.css
@@ -0,0 +1,16 @@
+html, body {
+    margin: 0; 
+    padding: 0; 
+    height: 100%; 
+}
+* { box-sizing: border-box; }
+
+.header, .main {
+    width: 70%; 
+    margin-left: auto; 
+    margin-right: auto; 
+}
+
+.header {
+    
+}
\ No newline at end of file
diff --git a/layout/templates/primary.html b/layout/templates/primary.html
index bbe293c..bb30d11 100644
--- a/layout/templates/primary.html
+++ b/layout/templates/primary.html
@@ -2,12 +2,27 @@
 <html>
   <head>
     <title>{{title}}</title>
+    
+    {{#styles}}
+    <link href="{{location}}" rel="stylesheet" type="text/css">
+    {{/styles}}
+
   </head>
   <body>
 
-    <header>Site Title</header>
+    <header class="header">
+
+    </header>
+
+    <main class="main">
+      <aside class="sidebar">
+	Sidebar
+      </aside>
 
-    {{page-content}}
+      <section class="content">
+      {{page-content}}
+      </section>
+    </main>
 
   </body>
 </html>
diff --git a/main.lisp b/main.lisp
index 964877f..2a6d4a9 100644
--- a/main.lisp
+++ b/main.lisp
@@ -2,4 +2,6 @@
 (in-package :cl-site)
 
 (defun make-site () 
-    (process-pages))
\ No newline at end of file
+  (progn 
+    (process-styles)
+    (process-pages)))
\ No newline at end of file
diff --git a/process.lisp b/process.lisp
index 670c24b..6aed170 100644
--- a/process.lisp
+++ b/process.lisp
@@ -2,7 +2,15 @@
 (in-package :cl-site)
 
 ;; Copies/renders stylesheets + adds to global context
-(defun process-styles () )
+(defun process-styles () 
+  (let 
+      ((styles-list (mapcar 
+		     (lambda (s) (progn
+				   (uiop:copy-file (make-path *STYLES-DIR* s)
+						   (make-path *OUTPUT-DIR* s))
+				   (cons :location s)))
+		     *STYLES*))) 
+    (push (cons :styles styles-list) *GLOBAL-CONTEXT*)))
 
 ;; Copies/renders static assets (imgs, etc)
 (defun process-static () )
@@ -11,15 +19,16 @@
 ;; process-pages : Copies/renders pages - called last
 (defun render-page (page template-path)
   (let* 
-    ((page-path (make-path *PAGES-DIR* page))
-     (output-path (make-path *OUTPUT-DIR* page))
+    ((page-path (make-path *PAGES-DIR* page t))
+     (output-path (make-path *OUTPUT-DIR* page t))
      (page-content (file-to-string page-path))
      (page-context (remove-if (lambda (p) (find p *PRIVATE-KEYS*)) 
        (push (cons :page-content page-content) page) :key 'car)))
 
       (with-open-file (output-stream output-path :direction :output
 				     :if-exists :supersede) 
-        (mustache:render template-path page-context output-stream))))
+        (mustache:render template-path (append page-context *GLOBAL-CONTEXT*) 
+			 output-stream))))
 
 (defun process-pages () 
   (let 
-- 
GitLab