Index: crystalize.rkt ================================================================== --- crystalize.rkt +++ crystalize.rkt @@ -35,11 +35,11 @@ pollen/core pollen/template racket/string txexpr "sqlite-tools.rkt" - "template-html.rkt" + "snippets-html.rkt" "dust.rkt") ;; ~~~ Provides ~~~ (provide spell-of-summoning! Index: pollen.rkt ================================================================== --- pollen.rkt +++ pollen.rkt @@ -30,23 +30,23 @@ (require pollen/tag pollen/setup racket/function "tags-html.rkt" - "template-html.rkt" + "snippets-html.rkt" "crystalize.rkt") (provide (all-defined-out) - (all-from-out "crystalize.rkt" "template-html.rkt")) + (all-from-out "crystalize.rkt" "snippets-html.rkt")) (module setup racket/base (require syntax/modresolve) (provide (all-defined-out)) (define poly-targets '(html)) (define cache-watchlist (map resolve-module-path '("tags-html.rkt" - "template-html.rkt" + "snippets-html.rkt" "dust.rkt" "crystalize.rkt")))) ;; Macro for defining tag functions that automatically branch based on the ;; current output format and the list of poly-targets in the setup module. ADDED snippets-html.rkt Index: snippets-html.rkt ================================================================== --- snippets-html.rkt +++ snippets-html.rkt @@ -0,0 +1,161 @@ +#lang pollen/mode racket/base + +;; Copyright (c) 2018 Joel Dueck. +;; +;; Licensed under the Apache License, Version 2.0 (the "License"); +;; you may not use this file except in compliance with the License. +;; A copy of the License is included with this source code, in the +;; file "LICENSE.txt". +;; You may also obtain a copy of the License at +;; +;; http://www.apache.org/licenses/LICENSE-2.0 +;; +;; Unless required by applicable law or agreed to in writing, software +;; distributed under the License is distributed on an "AS IS" BASIS, +;; WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +;; See the License for the specific language governing permissions and +;; limitations under the License. +;; +;; Author contact information: +;; joel@jdueck.net +;; https://joeldueck.com +;; ------------------------------------------------------------------------- + +;; Provides functions for displaying content in HTML templates. +(require pollen/core + pollen/template + racket/string + txexpr + openssl/sha1 + "dust.rkt") + +(provide html$-page-head + html$-page-body-open + html$-article-open + html$-article-close + html$-page-body-close + html$-note-title + html$-note-contents + html$-note-listing-full + html$-note-in-article + html$-notes-section) + +(define (html$-page-head [title #f]) + ◊string-append{ + ◊if[title title ""] + + + + }) + +(define (html$-page-body-open) + ◊string-append{
+
+ +

The Local Yarn

+
}) + +(define (html$-article-open title? title-html-flow published) + (define published (select-from-metas 'published (current-metas))) + (cond + [title? + ◊string-append{
+

◊|title-html-flow|

+

+ +

+
}] + [else + ◊string-append{
+

+ +

+
}])) + +(define (html$-article-close footertext) + (cond [(non-empty-string? footertext) + ◊string-append{
+
(◊|footertext|)
+
}] + [else "
"])) + +(define (html$-page-body-close) + ◊string-append{ +
}) + +;; Notes +;; +(define (html$-note-title author pagenode parent-title) + (define author-part + (cond [(and (non-empty-string? author) + (not (string-ci=? author default-authorname))) + (format "A note from ~a, " author)] + [else ""])) + (define article-part + (format "Re: ~a" + pagenode + parent-title)) + (string-append author-part article-part)) + +(define (html$-note-contents disposition-mark elems) + (define-values (first-tag first-attrs first-elems) (txexpr->values (car elems))) + (define disposition + (cond [(non-empty-string? disposition-mark) + `(span [[class "disposition-mark"]] ,disposition-mark)] + [else ""])) + (define body-elems + (cond + [(equal? 'p first-tag) + (cons (txexpr 'p first-attrs (cons disposition first-elems)) (cdr elems))] + [else + (cons disposition elems)])) + (string-append* (map ->html body-elems))) + +(define (html$-note-listing-full pagenode note-id title-html-flow date contents [author default-authorname] [author-url ""]) + (define author-part + (cond [(non-empty-string? author-url) + ◊string-append{ +
+ —◊|author| +
}] + [else ◊string-append{ +
+ —◊|author| +
}])) + (define maybe-author-class? + (cond [(string=? author default-authorname) "by-proprietor"] + [else ""])) + + ◊string-append{ +
+

◊|title-html-flow|

+

+ +

+
+
◊|contents|
+ ◊author-part +
+
}) + +(define (html$-note-in-article id date contents author author-url) + (define maybe-author-class? + (cond [(or (string=? author default-authorname) (string=? author "")) "by-proprietor"] + [else ""])) + + ◊string-append{
+

+

+
+ ◊contents +
+
+ —◊|author| +
+
}) + +(define (html$-notes-section note-htmls) + ◊string-append{
+

Further Notes

+ ◊(apply string-append note-htmls) +
}) DELETED template-html.rkt Index: template-html.rkt ================================================================== --- template-html.rkt +++ template-html.rkt @@ -1,161 +0,0 @@ -#lang pollen/mode racket/base - -;; Copyright (c) 2018 Joel Dueck. -;; -;; Licensed under the Apache License, Version 2.0 (the "License"); -;; you may not use this file except in compliance with the License. -;; A copy of the License is included with this source code, in the -;; file "LICENSE.txt". -;; You may also obtain a copy of the License at -;; -;; http://www.apache.org/licenses/LICENSE-2.0 -;; -;; Unless required by applicable law or agreed to in writing, software -;; distributed under the License is distributed on an "AS IS" BASIS, -;; WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -;; See the License for the specific language governing permissions and -;; limitations under the License. -;; -;; Author contact information: -;; joel@jdueck.net -;; https://joeldueck.com -;; ------------------------------------------------------------------------- - -;; Provides functions for displaying content in HTML templates. -(require pollen/core - pollen/template - racket/string - txexpr - openssl/sha1 - "dust.rkt") - -(provide html$-page-head - html$-page-body-open - html$-article-open - html$-article-close - html$-page-body-close - html$-note-title - html$-note-contents - html$-note-listing-full - html$-note-in-article - html$-notes-section) - -(define (html$-page-head [title #f]) - ◊string-append{ - ◊if[title title ""] - - - - }) - -(define (html$-page-body-open) - ◊string-append{
-
- -

The Local Yarn

-
}) - -(define (html$-article-open title? title-html-flow published) - (define published (select-from-metas 'published (current-metas))) - (cond - [title? - ◊string-append{
-

◊|title-html-flow|

-

- -

-
}] - [else - ◊string-append{
-

- -

-
}])) - -(define (html$-article-close footertext) - (cond [(non-empty-string? footertext) - ◊string-append{
-
(◊|footertext|)
-
}] - [else "
"])) - -(define (html$-page-body-close) - ◊string-append{ -
}) - -;; Notes -;; -(define (html$-note-title author pagenode parent-title) - (define author-part - (cond [(and (non-empty-string? author) - (not (string-ci=? author default-authorname))) - (format "A note from ~a, " author)] - [else ""])) - (define article-part - (format "Re: ~a" - pagenode - parent-title)) - (string-append author-part article-part)) - -(define (html$-note-contents disposition-mark elems) - (define-values (first-tag first-attrs first-elems) (txexpr->values (car elems))) - (define disposition - (cond [(non-empty-string? disposition-mark) - `(span [[class "disposition-mark"]] ,disposition-mark)] - [else ""])) - (define body-elems - (cond - [(equal? 'p first-tag) - (cons (txexpr 'p first-attrs (cons disposition first-elems)) (cdr elems))] - [else - (cons disposition elems)])) - (string-append* (map ->html body-elems))) - -(define (html$-note-listing-full pagenode note-id title-html-flow date contents [author default-authorname] [author-url ""]) - (define author-part - (cond [(non-empty-string? author-url) - ◊string-append{ -
- —◊|author| -
}] - [else ◊string-append{ -
- —◊|author| -
}])) - (define maybe-author-class? - (cond [(string=? author default-authorname) "by-proprietor"] - [else ""])) - - ◊string-append{ -
-

◊|title-html-flow|

-

- -

-
-
◊|contents|
- ◊author-part -
-
}) - -(define (html$-note-in-article id date contents author author-url) - (define maybe-author-class? - (cond [(or (string=? author default-authorname) (string=? author "")) "by-proprietor"] - [else ""])) - - ◊string-append{
-

-

-
- ◊contents -
-
- —◊|author| -
-
}) - -(define (html$-notes-section note-htmls) - ◊string-append{
-

Further Notes

- ◊(apply string-append note-htmls) -
})