hiccup icon indicating copy to clipboard operation
hiccup copied to clipboard

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

Open danielcompton opened this issue 7 years ago • 7 comments

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?

danielcompton avatar Apr 16 '17 18:04 danielcompton

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.

weavejester avatar Apr 16 '17 18:04 weavejester

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

danielcompton avatar Apr 18 '17 01:04 danielcompton

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 ^^.

danielcompton avatar Apr 24 '17 04:04 danielcompton

@danielcompton I've seen the same behaviour

mgerlach-klick avatar Dec 26 '18 16:12 mgerlach-klick

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.

john-shaffer avatar Oct 14 '19 02:10 john-shaffer

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

PEZ avatar Feb 24 '20 15:02 PEZ

@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.

john-shaffer avatar Feb 24 '20 22:02 john-shaffer