Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
danielcompton opened this issue Apr 16, 2017 · 7 comments
Open

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

danielcompton opened this issue Apr 16, 2017 · 7 comments

Comments

@danielcompton
Copy link

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
Copy link
Owner

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
Copy link
Author

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

@danielcompton
Copy link
Author

danielcompton commented Apr 24, 2017

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
Copy link

@danielcompton I've seen the same behaviour

@john-shaffer
Copy link

john-shaffer commented Oct 14, 2019

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
Copy link

PEZ commented Feb 24, 2020

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

@john-shaffer
Copy link

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants