-
Notifications
You must be signed in to change notification settings - Fork 83
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Make it possible to use djula as template engine #107
Open
libre-man
wants to merge
8
commits into
coleslaw-org:master
Choose a base branch
from
libre-man:template-engine
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
6ab3acc
Initial implementation of djula as templating engine
e59ec41
Added some documentation for djula templates.
ce9947d
Added a hyde-djula theme and corrected a spelling mistake.
8dd41e9
Corrected the name for template-engine in the config
6df131d
Updated some documentation
f2cd595
Refactored code to implement template engine as plugins
f648061
Added templates for atom, rss and sitemap each template engine
ff4e320
Updated source to add template engine to calls for rendering
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
(eval-when (:compile-toplevel :load-toplevel) | ||
(ql:quickload :cl-closure)) | ||
|
||
(defpackage :coleslaw-cl-closure | ||
(:use :cl) | ||
(:import-from :closure-template #:compile-template) | ||
(:import-from :local-time #:format-rfc1123-timestring) | ||
(:import-from :coleslaw #:find-theme | ||
#:app-path | ||
#:render | ||
#:find-injections | ||
#:*config* | ||
#:theme | ||
#:do-files | ||
#:render | ||
#:theme-package) | ||
(:export #:enable)) | ||
|
||
(in-package :coleslaw-cl-closure) | ||
|
||
(defclass cl-closure () ()) | ||
|
||
(defmethod coleslaw:compile-theme ((cl-closure cl-closure) theme) | ||
"Compile the templates used by cl-closure" | ||
(do-files (file (app-path "themes/auxiliary") | ||
"cl-closure") | ||
(compile-template :common-lisp-backend file)) | ||
(do-files (file (find-theme theme) "tmpl") | ||
(compile-template :common-lisp-backend file))) | ||
|
||
(defmethod coleslaw:render-page ((template cl-closure) content &optional theme-fn &rest render-args) | ||
(apply (or theme-fn (get-theme-fn 'theme 'base)) | ||
:config *config* | ||
:content content | ||
:pubdate (format-rfc1123-timestring nil (local-time:now)) | ||
:injections (find-injections content) | ||
:raw (apply #'render content render-args) | ||
render-args)) | ||
|
||
(defmethod coleslaw:get-theme-fn ((template cl-closure) name &optional (package (theme *config*))) | ||
(let ((closure-func (find-symbol (princ-to-string name) (theme-package package)))) | ||
(lambda (&rest template-args) | ||
(funcall closure-func template-args)))) | ||
|
||
(defun enable ()) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
(eval-when (:compile-toplevel :load-toplevel) | ||
(ql:quickload :djula)) | ||
|
||
(defpackage :coleslaw-djula | ||
(:use :cl :cl-ppcre) | ||
(:import-from :djula #:compile-template* | ||
#:render-template*) | ||
(:import-from :local-time #:format-rfc1123-timestring) | ||
(:import-from :coleslaw #:get-theme-fn | ||
#:render-page | ||
#:find-theme | ||
#:app-path | ||
#:render | ||
#:find-injections | ||
#:*config* | ||
#:theme | ||
#:do-files) | ||
(:import-from :cl-ppcre #:create-scanner | ||
#:regex-replace) | ||
(:export #:enable)) | ||
|
||
(in-package :coleslaw-djula) | ||
|
||
(defclass djula () | ||
((templates :initform (make-hash-table :test #'equalp) :accessor templates))) | ||
|
||
(defparameter +remove-extension+ (create-scanner "(.*)\\..*")) | ||
|
||
(defun compile-djula (djula file &optional (filename (regex-replace +remove-extension+ (file-namestring file) "\\1"))) | ||
(setf (gethash filename | ||
(templates djula)) (compile-template* file))) | ||
|
||
(defmethod coleslaw:compile-theme ((djula djula) theme) | ||
(do-files (file (app-path "themes/auxiliary") | ||
"djula") | ||
(compile-djula djula file)) | ||
(do-files (file (find-theme theme) "html") | ||
(compile-djula djula file))) | ||
|
||
(defmethod coleslaw:render-page ((djula djula) content &optional theme-fn &rest render-args) | ||
(apply (or theme-fn #'render) | ||
content | ||
:config *config* | ||
:content content | ||
:pubdate (format-rfc1123-timestring nil (local-time:now)) | ||
:injections (find-injections content) | ||
render-args)) | ||
|
||
(defmethod coleslaw:get-theme-fn ((djula djula) name &optional package) | ||
(declare (ignore package)) | ||
(break) | ||
(let ((theme (gethash (string name) (templates djula)))) | ||
(lambda (&rest template-args) | ||
(with-output-to-string (stream) | ||
(apply #'render-template* theme stream template-args))))) | ||
|
||
(defun enable ()) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,16 +3,27 @@ | |
(defvar *last-revision* nil | ||
"The git revision prior to the last push. For use with GET-UPDATED-FILES.") | ||
|
||
(defvar *templating-engine* nil | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I would prefer the templating engine (and any related vars like |
||
"The templating engine to use. This will be set during the main routine. | ||
Possible options at this time are djula and cl-closure.") | ||
|
||
(defvar *djula-post-template* nil | ||
"The template to use for rendering a post using a djula template.") | ||
|
||
(defvar *djula-index-template* nil | ||
"The template to use for rendering the index using a djula template.") | ||
|
||
(defun main (repo-dir &optional oldrev) | ||
"Load the user's config file, then compile and deploy the blog stored | ||
in REPO-DIR. Optionally, OLDREV is the revision prior to the last push." | ||
(load-config repo-dir) | ||
(let ((*templating-engine* (template-engine *config*))) | ||
(setf *last-revision* oldrev) | ||
(load-content) | ||
(compile-theme (theme *config*)) | ||
(compile-theme (template-engine *config*) (theme *config*)) | ||
(let ((dir (staging-dir *config*))) | ||
(compile-blog dir) | ||
(deploy dir))) | ||
(deploy dir)))) | ||
|
||
(defun load-content () | ||
"Load all content stored in the blog's repo." | ||
|
@@ -55,17 +66,15 @@ in REPO-DIR. Optionally, OLDREV is the revision prior to the last push." | |
(let ((current-working-directory (cl-fad:pathname-directory-pathname path))) | ||
(unless *config* | ||
(load-config (namestring current-working-directory)) | ||
(compile-theme (theme *config*))) | ||
(compile-theme (template-engine *config*) (theme *config*))) | ||
(let* ((file (rel-path (repo-dir *config*) path)) | ||
(content (construct content-type (read-content file)))) | ||
(write-file "tmp.html" (render-page content))))) | ||
(write-file "tmp.html" (render-page (template-engine *config*) content))))) | ||
|
||
(defun render-page (content &optional theme-fn &rest render-args) | ||
"Render the given CONTENT to HTML using THEME-FN if supplied. | ||
Additional args to render CONTENT can be passed via RENDER-ARGS." | ||
(funcall (or theme-fn (theme-fn 'base)) | ||
(list :config *config* | ||
:content content | ||
:raw (apply 'render content render-args) | ||
:pubdate (format-rfc1123-timestring nil (local-time:now)) | ||
:injections (find-injections content)))) | ||
(defgeneric render-page (template-engine content &optional theme-fn &rest render-args) | ||
(:documentation "Render a page using the given theme. TEMPLATE-ENGINE should be | ||
an instance of a template-engine object specified in one of the plugins. This | ||
object is stored in the config object. CONTENT should be the object to render as | ||
main part of the page, THEME-FN should be the function to render the page with | ||
and RENDER-ARGS should be additional arguments that should be passed to the | ||
render function(s).")) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If at all possible, I would prefer we load djula in an
eval-when
in the plugin as we do with other plugins that have additional library dependencies. If it is necessary to also initialize/compile templates at that time, the data necessary to do so can be passed into theenable
method in the plugin and they can be compiled then.