Skip to content

Commit

Permalink
Add support for adding an initial version
Browse files Browse the repository at this point in the history
using the selmer templating engine and a basic DTBook template in the
resources directory
  • Loading branch information
egli committed Jun 20, 2024
1 parent 65a2733 commit 6257f34
Show file tree
Hide file tree
Showing 3 changed files with 78 additions and 4 deletions.
51 changes: 51 additions & 0 deletions resources/templates/DTBookTemplate.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE dtbook PUBLIC "-//NISO//DTD dtbook 2005-3//EN" "http://www.daisy.org/z3986/2005/dtbook-2005-3.dtd">
<dtbook xmlns="http://www.daisy.org/z3986/2005/dtbook/"
xmlns:brl="http://www.daisy.org/z3986/2009/braille/"
{% if language = "it" %}version="2005-3-sbs-full"{% else %}version="2005-3-sbs-minimal"{% endif %}
xml:lang="{{ language }}">
<head>
{# for a list of all the metadata fileds see http://www.daisy.org/z3986/2005/Z3986-2005.html #}
<meta name="dc:Title" content="{{ title }}"/>
<meta name="dc:Creator" content="{{ author }}"/>
<meta name="dc:Subject" content="{{ subject }}"/>
<meta name="dc:Description" content="{{ description }}"/>
<meta name="dc:Publisher" content="{{ publisher }}"/>
<meta name="dc:Date" content="{{ date }}"/>
<meta name="dc:Type" content="Text"/>
<meta name="dc:Format" content="ANSI/NISO Z39.86-2005"/>
<meta name="dc:Identifier" content="{{ identifier }}"/>
<meta name="dc:Source" content="{{ source }}"/>
<meta name="dc:Language" content="{{ language }}"/>
<meta name="dc:Rights" content="{{ rights }}"/>
<meta name="dtb:uid" content="{{ identifier }}"/>
{% if source_date %}
<meta name="dtb:sourceDate" content="{{ source_date }}"/>
{% endif %}
<meta name="dtb:sourceEdition" content="{{ source_edition }}"/>
<meta name="dtb:sourcePublisher" content="{{ source_publisher }}"/>
<meta name="dtb:sourceRights" content="{{ source_rights }}"/>
{# producer specific metadata #}
<meta name="prod:series" content="{{ production_series }}"/>
<meta name="prod:seriesNumber" content="{{ production_series_number }}"/>
<meta name="prod:source" content="{{ production_source }}"/>
</head>

<book>
<frontmatter>
<doctitle>{{ title }}</doctitle>
<docauthor>{{ author }}</docauthor>
<level1>
<p></p>
</level1>
</frontmatter>

<bodymatter>
<level1>
<h1></h1>
<p></p>
</level1>
</bodymatter>

</book>
</dtbook>
28 changes: 26 additions & 2 deletions src/clj/daisyproducer2/documents/versions.clj
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,13 @@
[clojure.tools.logging :as log]
[daisyproducer2.config :refer [env]]
[daisyproducer2.db.core :as db]
[daisyproducer2.documents.utils :refer [with-tempfile]]
[daisyproducer2.documents.metadata-validation :as metadata-validation]
[daisyproducer2.documents.metadata-validation :as metadata-validation]
[daisyproducer2.documents.schema-validation :as schema-validation]
[daisyproducer2.documents.utils :refer [with-tempfile]]
[daisyproducer2.metrics :as metrics]
[daisyproducer2.pipeline1 :as pipeline1]
[iapetos.collector.fn :as prometheus]
[selmer.parser :as parser]
[sigel.xslt.core :as xslt])
;; Universally Unique Lexicographically Sortable Identifiers (https://github.com/ulid/spec)
(:import [io.azam.ulidj ULID]))
Expand Down Expand Up @@ -87,6 +88,29 @@
;; ... and return the new key
db/get-generated-key)))

(defn initial-content
"Create the initial XML content from a set of metadata given in `document`"
[document]
(parser/render-file "templates/DTBookTemplate.xml" document))

(defn insert-initial-version
[{:keys [document-id] :as document}]
(let [document-root (env :document-root)
name (str (ULID/random) ".xml")
path (fs/path (str document-id) "versions" name)
absolute-path (fs/absolutize (fs/path document-root path))]
;; make sure path exists
(fs/create-dirs (fs/parent absolute-path))
;; write the initial contents into the archive
(spit (fs/file absolute-path) (initial-content document))
;; store it in the db ...
(->
(db/insert-version {:document-id document-id :content (str path)
:user "abacus"
:comment "Initial version created from meta data"})
;; ... and return the new key
db/get-generated-key)))

(defn version-path [version]
(let [document-root (env :document-root)]
(fs/path document-root (:content version))))
Expand Down
3 changes: 1 addition & 2 deletions src/clj/daisyproducer2/layout.clj
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@
[ring.middleware.anti-forgery :refer [*anti-forgery-token*]]
[ring.util.response]))

(parser/set-resource-path! (clojure.java.io/resource "html"))
(parser/add-tag! :csrf-field (fn [_ _] (anti-forgery-field)))
(filters/add-filter! :markdown (fn [content] [:safe (md-to-html-string content)]))

Expand All @@ -36,4 +35,4 @@
[error-details]
{:status (:status error-details)
:headers {"Content-Type" "text/html; charset=utf-8"}
:body (parser/render-file "error.html" error-details)})
:body (parser/render-file "html/error.html" error-details)})

0 comments on commit 6257f34

Please sign in to comment.