Tactical commit

This commit is contained in:
Simon Brooke 2018-06-30 20:05:55 +01:00
parent 2d7e39ca29
commit 16f953741b

View file

@ -99,8 +99,7 @@
"See [Application Description Language](https://github.com/simon-brooke/adl)."
"-->")
(emit-content filename spec entity application :head)
(emit-content filename spec entity application :top)
"{% block content %}")))))
(emit-content filename spec entity application :top))))))
(defn file-footer
@ -111,11 +110,7 @@
([filename spec entity application]
(s/join
"\n"
(flatten
(list
"{% endblock %}"
(emit-content filename spec entity application :foot)
)))))
(emit-content filename spec entity application :foot))))
(defn prompt
@ -362,6 +357,7 @@
[keyfields (children
;; there should only be one key; its keys are properties
(first (children entity #(= (:tag %) :key))))]
{:content
{:tag :div
:attrs {:id "content" :class "edit"}
:content
@ -380,7 +376,7 @@
#(= (:distict (:attrs %)) :system)
(fields entity)))
(save-widget form entity application)
(delete-widget form entity application)))}]}))
(delete-widget form entity application)))}]}}))
@ -536,16 +532,46 @@
taken from this `application`. If `list` is nill, generate a default list
template for the entity."
[list-spec entity application]
{:tag :form
:attrs {:id "content" :class "list"}
(let [form-name
(str
"list-"
(:name (:attrs entity))
"-"
(:name (:attrs list-spec)))]
{:big-links
{:tag :div
:content
[(big-link (str "Add a new " (pretty-name entity)) (editor-name entity application))
[{:tag :div :attrs {:class "big-link-container"}
:content
[{:tag :a :attrs {:id "next-selector" :role "button" :class "big-link"}
:content ["Next"]}]}
(big-link (str "Add a new " (pretty-name entity)) (editor-name entity application))]}
:content
{:tag :form
:attrs {:id form-name :class "list"
:action (str "{{servlet-context}}/" form-name)
:method "POST"}
:content
[
(csrf-widget)
{:tag :input :attrs {:id "offset" :type "hidden" :value "{{offset|0}}"}}
{:tag :input :attrs {:id "limit" :type "hidden" :value "{{limit|50}}"}}
(big-link (str "Add a new " (pretty-name entity)) (editor-name entity application))
{:tag :table
:attrs {:caption (:name (:attrs entity))}
:content
[(list-thead list-spec entity application)
(list-tbody list-spec entity application)
(list-tfoot list-spec entity application)]}]})
(list-tfoot list-spec entity application)]}]}
:extra-script
(str "var form = document.getElementById('" form-name "');
var ow = document.getElementById('offset');
var lw = document.getElementById('limit');
document.getElementById('next-selector').addEventListener('click', function () {
ow.text=(parseInt(ow.text)+parseInt(lw.text));
//form.submit();
});")}))
(defn entity-to-templates
@ -591,6 +617,7 @@
[first-class-entities (filter
#(children-with-tag % :list)
(children-with-tag application :entity))]
{:content
{:application-index
{:tag :dl
:attrs {:class "index"}
@ -617,7 +644,7 @@
:tag :p
:content (:content d)))
(children-with-tag % :documentation))))
first-class-entities)))}}))
first-class-entities)))}}}))
@ -630,11 +657,24 @@
(str *output-path* filename)
(s/join
"\n"
(flatten
(list
(file-header filename application)
(doall
(map
#(let [content (template %)]
(list
(str "{% block " (name %) " %}")
(cond (string? content)
content
(map? content)
(with-out-str
(x/emit-element template))
(file-footer filename application))))
(x/emit-element content))
true
(str "<!-- don't know what to do with '" content "' -->"))
"{% endblock %}")
(keys template))))
(file-footer filename application)))))
(catch Exception any
(spit
(str *output-path* filename)