Permalink
Browse files

html-template%%

  • Loading branch information...
1 parent 2c034d7 commit 6339616bde3d298258eac23853571d73720cd8ac asdr committed Jan 27, 2011
Showing with 43 additions and 15 deletions.
  1. +17 −15 project-util.lisp
  2. +17 −0 template-util.lisp
  3. +2 −0 template-util.lisp~
  4. +7 −0 util.lisp
View
@@ -6,32 +6,34 @@
("_view" . "lisp")
("template-app" . "asd")))
-(defvar *easyweb-template-application-dir* "/home/admin-o/pjs/easyweb/template-app")
+(defvar *easyweb-template-application-dir* "/home/asdr/projects/easyweb/template-app")
-(defun create-appender (initial-list)
- (let ((acc-list initial-list)
- (tail (nthcdr (1- (length initial-list)) initial-list)))
- (lambda (&rest lists)
- (dolist (al lists acc-list)
- (setf (cdr tail) al)
- (setf tail (nthcdr (1- (length al)) al))))))
+(defun write-from-template (in out variables)
+ (let ((template-printer (html-template:create-template-printer in)))
+ (html-template:fill-and-print-template template-printer
+ variables
+ :stream out)))
-
-(defun write-to-file (in out project-name)
- (html-template:fill-and-print-template (html-template:create-template-printer in) (list ':APPLICATION_NAME project-name) :stream out))
-
-(defun clone-file (if-path of-path project-name)
+(defun clone-file (if-path of-path &rest variables &key application_name)
(with-open-file (in if-path :direction :input)
(with-open-file (out of-path :direction :output
:if-exists :supersede)
- (write-to-file in out project-name))))
+ (write-from-template in out variables))))
(defun remove-trailing-slash (string)
(if (= (position #\/ string :from-end t)
(1- (length string)))
(subseq string 0 (1- (length string)))
string))
+(defun seperate-path (path)
+ (let* ((correct-path (remove-trailing-slash path))
+ (last-position (1+ (position #\/
+ correct-path
+ :from-end t))))
+ (values (subseq correct-path 0 last-position)
+ (subseq correct-path last-position))))
+
(defun make-project (project-path)
(let* ((project-path-n (remove-trailing-slash project-path))
(last-position (1+ (position #\/
@@ -62,4 +64,4 @@
:directory path
:name name
:type type))))
- (clone-file if-path of-path project-name))))))))
+ (clone-file if-path of-path :application_name project-name))))))))
View
@@ -0,0 +1,17 @@
+(in-package :easyweb)
+
+(defvar *atemplate-reader* '(path printer variables))
+(defparameter *template-cache* (make-hash-table :test #'string=))
+
+(defun use-template (path &rest variables)
+ (let ((template (gethash path *template-cache*)))
+ (unless template
+ (multiple-value-bind (dir file)
+ (seperate-path path)
+ (setf template (setf (gethash path *template-cache*)
+ (list path
+ (html-template:create-template-printer (make-pathname
+ :directory dir
+ :name file))
+ variables)))))
+ template))
View
@@ -0,0 +1,2 @@
+(in-package :easyweb)
+
View
@@ -24,6 +24,13 @@
tree
(mapcar #'macroexpand-tree tree)))
+(defun create-appender (initial-list)
+ (let ((acc-list initial-list)
+ (tail (nthcdr (1- (length initial-list)) initial-list)))
+ (lambda (&rest lists)
+ (dolist (al lists acc-list)
+ (setf (cdr tail) al)
+ (setf tail (nthcdr (1- (length al)) al))))))
#| - LET OVER LAMBDA UTILITIES -
(defun mkstr (&rest args)

0 comments on commit 6339616

Please sign in to comment.