-
Notifications
You must be signed in to change notification settings - Fork 11
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #7 from kiranshila/templates
- Loading branch information
Showing
13 changed files
with
88 additions
and
96 deletions.
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
File renamed without changes.
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,22 @@ | ||
# Templates | ||
|
||
Cybermonday has very basic support for templates with | ||
[mustache](https://mustache.github.io/) syntax. This is basic in the sense that | ||
it only works for mustache tags, such as `{{foo}}` transforms to a | ||
`:markdown/mustache` IR node as `[:markdown/mustache {} "foo"]`. This feature is | ||
disabled by default but can be enabled by setting `:parse-templates?` to `true` | ||
in the `parse-md` opts map. | ||
|
||
You could then easily implement templating with a lowering fn such as | ||
|
||
```clojure | ||
(def replacements {:foo "bar"}) | ||
|
||
(defn lower-mustache [[_ _ body]] | ||
((keyword body) replacements)) | ||
``` | ||
|
||
However the default behavior, even when enabled is to leave the text as is. | ||
|
||
This feature should be considered very alpha and prone to change as we perhaps | ||
might want to pull in an actual implementation of mustache templating. |
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
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,35 @@ | ||
(ns cybermonday.templates | ||
(:require | ||
[cybermonday.utils :refer [hiccup? make-hiccup-node]] | ||
[clojure.walk :as walk] | ||
[clojure.string :as str])) | ||
|
||
(def blacklisted-tags #{:pre | ||
:code | ||
:markdown/indented-code-block | ||
:markdown/fenced-code-block}) | ||
|
||
(defn parse-templates [ast] | ||
(walk/postwalk | ||
(fn [item] | ||
(if (hiccup? item) | ||
(let [[key attr & body] item] | ||
(if (not (contains? blacklisted-tags key)) | ||
(make-hiccup-node | ||
key | ||
attr | ||
(apply | ||
concat | ||
(for [child body] | ||
(if (string? child) | ||
(let [split (str/split child #"\{\{|\}\}") | ||
items (partition-all 2 split)] | ||
(letfn [(process [[not-template template]] | ||
(if template | ||
[not-template [:markdown/mustache {} template]] | ||
[not-template]))] | ||
(mapcat process items))) | ||
[child])))) | ||
item)) | ||
item)) | ||
ast)) |
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