Skip to content

Commit

Permalink
fix for issue #31 - badly munged header tags
Browse files Browse the repository at this point in the history
  • Loading branch information
retrogradeorbit committed Nov 10, 2019
1 parent a5ade4b commit 5b64140
Show file tree
Hide file tree
Showing 4 changed files with 90 additions and 71 deletions.
2 changes: 1 addition & 1 deletion project.clj
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
(defproject bootleg "0.1.5"
(defproject bootleg "0.1.6-SNAPSHOT"
:description "Simple template processing command line tool to help build static websites"
:url "https://github.com/retrogradeorbit/bootleg"
:license {:name "EPL-2.0 OR GPL-2.0-or-later WITH Classpath-exception-2.0"
Expand Down
12 changes: 6 additions & 6 deletions src/bootleg/utils.clj
Original file line number Diff line number Diff line change
Expand Up @@ -30,12 +30,12 @@

(defn- munge-html-tags [markup]
(-> markup
(string/replace #"<html" "<html-bootleg-munged")
(string/replace #"</html" "</html-bootleg-munged")
(string/replace #"<head" "<head-bootleg-munged")
(string/replace #"</head" "</head-bootleg-munged")
(string/replace #"<body" "<body-bootleg-munged")
(string/replace #"</body" "</body-bootleg-munged")))
(string/replace #"<html([> ])" "<html-bootleg-munged$1")
(string/replace #"</html([> ])" "</html-bootleg-munged$1")
(string/replace #"<head([> ])" "<head-bootleg-munged$1")
(string/replace #"</head([> ])" "</head-bootleg-munged$1")
(string/replace #"<body([> ])" "<body-bootleg-munged$1")
(string/replace #"</body([> ])" "</body-bootleg-munged$1")))

(def munge-map {:html :html-bootleg-munged
:body :body-bootleg-munged
Expand Down
132 changes: 73 additions & 59 deletions test/bootleg/hiccup_test.clj
Original file line number Diff line number Diff line change
Expand Up @@ -56,29 +56,45 @@
")))
(testing "enlive"
(is (= (process-hiccup-data "test/files"
"(-> [:div [:p] [:p#id]]
"(-> [:div [:p] [:p#id]]
(convert-to :hickory-seq)
(net.cgrand.enlive-html/at
[:p#id] (net.cgrand.enlive-html/content \"new content\"))
(convert-to :hiccup))")
[:div {} [:p {}] [:p {:id "id"} "new content"]]))
[:div {} [:p {}] [:p {:id "id"} "new content"]]))
(is (= (process-hiccup-data "test/files"
"(-> [:div [:p] [:p#id]]
"(-> [:div [:p] [:p#id]]
(net.cgrand.enlive-html/at
[:p#id] (net.cgrand.enlive-html/content \"new content\")))")
[:div {} [:p {}] [:p {:id "id"} "new content"]]))
[:div {} [:p {}] [:p {:id "id"} "new content"]]))
(is (= (process-hiccup-data "test/files"
"(-> [:div [:p] [:p#id]]
"(-> [:div [:p] [:p#id]]
(convert-to :html)
(net.cgrand.enlive-html/at
[:p#id] (net.cgrand.enlive-html/content \"new content\")))")
"<div><p></p><p id=\"id\">new content</p></div>"))
"<div><p></p><p id=\"id\">new content</p></div>"))
(is (= (process-hiccup-data "test/files"
"(-> [:div [:p] [:p#id]]
"(-> [:div [:p] [:p#id]]
(convert-to :hickory)
(net.cgrand.enlive-html/at
[:p#id] (net.cgrand.enlive-html/content \"new content\")))")
{:type :element
{:type :element
:attrs nil
:tag :div
:content [{:type :element
:attrs nil
:tag :p
:content []}
{:type :element
:attrs {:id "id"}
:tag :p
:content ["new content"]}]}))
(is (= (process-hiccup-data "test/files"
"(-> [:div [:p] [:p#id]]
(convert-to :hickory-seq)
(net.cgrand.enlive-html/at
[:p#id] (net.cgrand.enlive-html/content \"new content\")))")
'({:type :element
:attrs nil
:tag :div
:content [{:type :element
Expand All @@ -88,26 +104,10 @@
{:type :element
:attrs {:id "id"}
:tag :p
:content ["new content"]}]}))
(is (= (process-hiccup-data "test/files"
"(-> [:div [:p] [:p#id]]
(convert-to :hickory-seq)
(net.cgrand.enlive-html/at
[:p#id] (net.cgrand.enlive-html/content \"new content\")))")
'({:type :element
:attrs nil
:tag :div
:content [{:type :element
:attrs nil
:tag :p
:content []}
{:type :element
:attrs {:id "id"}
:tag :p
:content ["new content"]}]})))
:content ["new content"]}]})))
(is (= (process-hiccup-data
"test/files"
"
"test/files"
"
(require '[net.cgrand.enlive-html :as html])
(html/defsnippet main-snippet \"header.html\" [:header] [heading navigation-elements]
Expand All @@ -119,35 +119,35 @@
(main-snippet \"heading\" [[\"caption 1\" \"url 1\"] [\"caption 2\" \"url 2\"]])
")
'({:type :element
:tag :header
:attrs nil
:content ["\n "
{:type :element
:tag :h1
:attrs nil
:content ["heading"]}
"\n "
{:type :element
:tag :ul
:attrs {:id "navigation"}
:content ["\n "
{:type :element
:tag :li
:attrs nil
:content [{:type :element
:tag :a
:attrs {:href "url 1"}
:content ["caption 1"]}]}
{:type :element
:tag :li
:attrs nil
:content [{:type :element
:tag :a
:attrs {:href "url 2"}
:content ["caption 2"]}]}
"\n "]}
"\n "]})))
'({:type :element
:tag :header
:attrs nil
:content ["\n "
{:type :element
:tag :h1
:attrs nil
:content ["heading"]}
"\n "
{:type :element
:tag :ul
:attrs {:id "navigation"}
:content ["\n "
{:type :element
:tag :li
:attrs nil
:content [{:type :element
:tag :a
:attrs {:href "url 1"}
:content ["caption 1"]}]}
{:type :element
:tag :li
:attrs nil
:content [{:type :element
:tag :a
:attrs {:href "url 2"}
:content ["caption 2"]}]}
"\n "]}
"\n "]})))

(is (= (process-hiccup-data
"test/files"
Expand Down Expand Up @@ -283,6 +283,20 @@
</html>"))



))
(testing "issue #31 - header tag munged"
(is (= (process-hiccup-data
"test/files"
"(mustache \"header.html\" {})")
'("<!DOCTYPE html>\n"
[:html {:lang "en"} "\n "
[:body {} "\n "
[:header {} "\n "
[:h1 {} "Header placeholder"] "\n "
[:ul {:id "navigation"} "\n "
[:li {}
[:a {:href "#"} "Placeholder for navigation"]]
"\n "]
"\n "]
"\n "]
"\n"]
"\n"))))))
15 changes: 10 additions & 5 deletions test/bootleg/utils_test.clj
Original file line number Diff line number Diff line change
Expand Up @@ -467,8 +467,13 @@
(is (= (convert-to ["text" "string"] :hiccup-seq)
["text" "string"]))
(is (= (convert-to ["text" "string"] :hickory-seq)
["text" "string"]))

)

)
["text" "string"])))

(testing "issue #31 - header tag munged"
(is (= (convert-to [:header [:div]] :html)
"<header><div></div></header>"))
(is (= (convert-to "<header><div></div></header>" :hiccup)
[:header {} [:div {}]]))
(is (= (convert-to "<html><header><div></div></header></html>" :hiccup)
[:html {} [:header {} [:div {}]]]))
))

0 comments on commit 5b64140

Please sign in to comment.