retrogradeorbit / bootleg

Simple template processing command line tool to help build static websites
Eclipse Public License 2.0
255 stars 12 forks source link

Hiccup and hiccup-seq? #35

Closed didibus closed 4 years ago

didibus commented 4 years ago

In the readme, you mention hiccup can't represent sibling elements like:

<p>one</p><p>two</p>

But I'm pretty sure you can do this in Hiccup by wrapping it in a list like:

(list [:p "one"] [:p "two"])
retrogradeorbit commented 4 years ago

Yep. That is what hiccup-seq is. A sequence (a list) of hiccup forms.

$ bootleg -d -e '(convert-to "<p>one</p><p>two</p>" :hiccup-seq)'
([:p {} "one"] [:p {} "two"])
retrogradeorbit commented 4 years ago

the reverse also works:

$ bootleg -e '(list [:p "one"] [:p "two"])'
<p>one</p><p>two</p>
retrogradeorbit commented 4 years ago

Just testing, hiccup does support this sequence:

test2.core=> (use 'hiccup.core)
nil
test2.core=> (html (list [:p "one"] [:p "two"]))
"<p>one</p><p>two</p>"

Will update the documentation to make this clear

retrogradeorbit commented 4 years ago

As an additional note, reagent proclaims to use hiccup syntax but does not support the list form.

In reagent:

(defn test-page []
  (list [:p "one"] [:p "two"]))

(defn current-page []
  (fn []
    [:div
     [test-page]]))

gives:

Error: Objects are not valid as a React child (found: object with keys {ns, name, fqn, _hash, cljs$lang$protocol_mask$partition0$, cljs$lang$protocol_mask$partition1$}). If you meant to render a collection of children, use an array instead.
    in myreagent.core.test_page (created by myreagent.core.current_page)
    in div (created by myreagent.core.current_page)
    in myreagent.core.current_page 3 react-dom.inc.js:13951:28

Trying a vector:

(defn test-page []
  (vector [:p "one"] [:p "two"]))

(defn current-page []
  (fn []
    [:div
     [test-page]]))

results in

Error: No item [:p "two"] in vector of length 2 2 core.cljs:5383:9

defining a single hiccup form works:

(defn test-page []
  (last (list [:p "one"])) [:p "two"])

(defn current-page []
  (fn []
    [:div
     [test-page]]))

results in

<div><p>two</p></div>