weavejester / hiccup

Fast library for rendering HTML in Clojure
http://weavejester.github.io/hiccup
Eclipse Public License 1.0
2.68k stars 174 forks source link

Migrate hiccup.page (and others?) to hiccup2 namespace? #144

Open danielcompton opened 7 years ago

danielcompton commented 7 years ago

I'm adopting hiccup2 on a project, but noticed that hiccup.page doesn't have a hiccup2 version. This means as far as I can tell, the only way to get the html5 macro or others is to make a copy of them from hiccup into my own code, and change the html reference to point to hiccup2.core/html. Would you consider having other necessary namespaces ported over, or is there another way to do this?

weavejester commented 7 years ago

You should be able to wrap it in hiccup2.core/html:

(hiccup2/html (page/html5 ...))

But a hiccup2.page namespace (or similar) is certainly on the agenda.

danielcompton commented 7 years ago

Ah right, that makes sense, I'll do that instead. Thanks!

danielcompton commented 7 years ago

I tried that, and it didn't seem to work, the h2/html was re-escaping the html5 document.

;; requires:
;;            [hiccup2.core :as h2]
;;            [hiccup.core :as h]
;;            [hiccup.page :refer [html5]

(str
  (h/html
    (html5
      [:h1 "Available commands"])
    ))
=> "<!DOCTYPE html>\n<html><h1>Available commands</h1></html>"
(str
  (h2/html
    (html5
      [:h1 "Available commands"])
    ))
=> "&lt;!DOCTYPE html&gt;\n&lt;html&gt;&lt;h1&gt;Available commands&lt;/h1&gt;&lt;/html&gt;"

I'm happy with my own html5 macro for now, but just thought I'd mention it. Also, I may have done something dumb in the above ^^.

mgerlach-klick commented 5 years ago

@danielcompton I've seen the same behaviour

john-shaffer commented 4 years ago

Since I wanted the escaping behavior for my projects, I've forked this repo to move the relevant namespaces under hiccup2. The html5 macro is at hiccup2.page/html5. The lein coordinates are [org.clojars.john-shaffer/hiccup "2.0.0-SNAPSHOT"]

I tried to use -alpha version tagging, but for some reason I get a compile-time error "Syntax error compiling at (hiccup2/core.clj:30:28). No such var: compiler/compile-html-with-bindings" if I do that, even though absolutely everything is the same except the version string.

I added the function hiccup.element/html-comment, as I'm basing my page off files from https://templated.co/, and I want to preserve the attribution.

Edit: Now I get that same error even with a SNAPSHOT version. Everything works fine when I copy the new files into my website repo and use [hiccup "2.0.0-alpha2"], even though that puts the exact same code on the classpath. I thought that maybe a dependency was including hiccup, but that's not the case.

PEZ commented 4 years ago

Thanks, @john-shaffer ! I have the same situation where your fork only works if I inline the code. But, hey, it works!

john-shaffer commented 4 years ago

@PEZ I've actually been using Rum's server-side rendering, since it provides the same auto-escaping functionality but can also be used with ClojureScript. I would highly recommend giving it a look.