-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Major restructuring of extension processors, not yet complete
- Loading branch information
1 parent
e00beaf
commit 54b8293
Showing
8 changed files
with
185 additions
and
11 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
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,14 @@ | ||
classDiagram | ||
Class01 <|-- AveryLongClass : Cool | ||
Class03 *-- Class04 | ||
Class05 o-- Class06 | ||
Class07 .. Class08 | ||
Class09 --> C2 : Where am i? | ||
Class09 --* C3 | ||
Class09 --|> Class07 | ||
Class07 : equals() | ||
Class07 : Object[] elementData | ||
Class01 : size() | ||
Class01 : int chimp | ||
Class01 : int gorilla | ||
Class08 <--> C2: Cool label |
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,85 @@ | ||
(ns ^{:doc "Format Semagol's extended markdown format." | ||
:author "Simon Brooke"} | ||
smeagol.extensions.mermaid | ||
(:require [smeagol.extensions.utils :refer :all] | ||
[taoensso.timbre :as log])) | ||
|
||
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; | ||
;;;; | ||
;;;; Smeagol: a very simple Wiki engine. | ||
;;;; | ||
;;;; This program is free software; you can redistribute it and/or | ||
;;;; modify it under the terms of the GNU General Public License | ||
;;;; as published by the Free Software Foundation; either version 2 | ||
;;;; of the License, or (at your option) any later version. | ||
;;;; | ||
;;;; This program is distributed in the hope that it will be useful, | ||
;;;; but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
;;;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
;;;; GNU General Public License for more details. | ||
;;;; | ||
;;;; You should have received a copy of the GNU General Public License | ||
;;;; along with this program; if not, write to the Free Software | ||
;;;; Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, | ||
;;;; USA. | ||
;;;; | ||
;;;; Copyright (C) 2017 Simon Brooke | ||
;;;; | ||
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; | ||
;;;; | ||
;;;; Graphs can now be embedded in a page using the | ||
;;;; [Mermaid](https://mermaid-js.github.io/mermaid/#/) graph description | ||
;;;; language. The graph description should start with a line comprising three | ||
;;;; back-ticks and then the word `mermaid`, and end with a line comprising just | ||
;;;; three backticks. | ||
;;;; | ||
;;;; Here's an example culled from the Mermaid documentation. | ||
;;;; | ||
;;;; ### GANTT Chart | ||
;;;; | ||
;;;; ```mermaid | ||
;;;; gantt | ||
;;;; dateFormat YYYY-MM-DD | ||
;;;; title Adding GANTT diagram functionality to mermaid | ||
;;;; section A section | ||
;;;; Completed task :done, des1, 2014-01-06,2014-01-08 | ||
;;;; Active task :active, des2, 2014-01-09, 3d | ||
;;;; Future task : des3, after des2, 5d | ||
;;;; Future task2 : des4, after des3, 5d | ||
;;;; section Critical tasks | ||
;;;; Completed task in the critical line :crit, done, 2014-01-06,24h | ||
;;;; Implement parser and jison :crit, done, after des1, 2d | ||
;;;; Create tests for parser :crit, active, 3d | ||
;;;; Future task in critical line :crit, 5d | ||
;;;; Create tests for renderer :2d | ||
;;;; Add to mermaid :1d | ||
;;;; ``` | ||
;;;; | ||
;;;; Mermaid graph specifications can also be loaded from URLs. Here's another | ||
;;;; example. | ||
;;;; | ||
;;;; ### Class Diagram | ||
;;;; | ||
;;;; ```mermaid | ||
;;;; http://localhost:3000/data/classes.mermaid | ||
;;;; ``` | ||
;;;; | ||
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; | ||
|
||
|
||
(defn process-mermaid | ||
"If this `url-or-graph-spec` is a valid URL, it is assumed to point to a plain | ||
text file pointing to a valid `graph-spec`; otherwise, it is expected to BE a | ||
valid `graph-spec`. | ||
Lightly mung this `graph-spec`, assumed to be a mermaid specification." | ||
[^String url-or-graph-spec ^Integer index] | ||
(let [data (resource-url-or-data->data url-or-graph-spec) | ||
graph-spec (:data data)] | ||
(log/info "Retrieved graph-spec from " (:from data) " `" ((:from data) data) "`") | ||
(str "<div class=\"mermaid data-visualisation\" id=\"mermaid" index "\">\n" | ||
graph-spec | ||
"\n</div>"))) | ||
|
||
;; (fs/file? (str (nio/resource-path) "data/classes.mermaid")) | ||
;; (slurp (str (nio/resource-path) "data/classes.mermaid")) |
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,72 @@ | ||
(ns ^{:doc "Utility functions useful to extension processors." | ||
:author "Simon Brooke"} | ||
smeagol.extensions.utils | ||
(:require [cemerick.url :refer (url url-encode url-decode)] | ||
[clojure.string :as cs] | ||
[me.raynes.fs :as fs] | ||
[noir.io :as io] | ||
[taoensso.timbre :as log])) | ||
|
||
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; | ||
;;;; | ||
;;;; Smeagol: a very simple Wiki engine. | ||
;;;; | ||
;;;; This program is free software; you can redistribute it and/or | ||
;;;; modify it under the terms of the GNU General Public License | ||
;;;; as published by the Free Software Foundation; either version 2 | ||
;;;; of the License, or (at your option) any later version. | ||
;;;; | ||
;;;; This program is distributed in the hope that it will be useful, | ||
;;;; but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
;;;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
;;;; GNU General Public License for more details. | ||
;;;; | ||
;;;; You should have received a copy of the GNU General Public License | ||
;;;; along with this program; if not, write to the Free Software | ||
;;;; Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, | ||
;;;; USA. | ||
;;;; | ||
;;;; Copyright (C) 2017 Simon Brooke | ||
;;;; | ||
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; | ||
|
||
(defn resource-url-or-data->data | ||
"Interpret this `resource-url-or-data` string as data to be digested by a | ||
`process-extension` function. It may be a URL or the pathname of a local | ||
resource, in which case the content should be fetched; or it may just be | ||
the data itself. | ||
Returns a map with a key `:from` whose value may be `:url`, `:resource` or | ||
`:text`, and a key `:data` whose value is the data. There will be an | ||
additional key being the value of the `:from` key, whose value will be the | ||
source of the data." | ||
[^String resource-url-or-data] | ||
(let [default {:from :text | ||
:text resource-url-or-data | ||
:data resource-url-or-data}] | ||
(try | ||
(try | ||
;; is it a URL? | ||
(let [url (str (url resource-url-or-data)) | ||
result (slurp url)] | ||
{:from :url | ||
:url url | ||
:data result}) | ||
(catch java.net.MalformedURLException _ | ||
;; no. So is it a path to a local resource? | ||
(let [t (cs/trim resource-url-or-data) | ||
r (str (io/resource-path) t)] | ||
(if | ||
(fs/file? r) | ||
{:from :resource | ||
:resource t | ||
:data (slurp r)} | ||
default)))) | ||
(catch Exception x | ||
(log/error | ||
"Could not read mermaid graph specification from `" | ||
(cs/trim resource-url-or-data) | ||
"` because " | ||
(.getName (.getClass x)) | ||
(.getMessage x) ) | ||
default)))) |
Empty file.
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