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

Swappable templating #106

Open
madstap opened this issue Nov 30, 2017 · 6 comments
Open

Swappable templating #106

madstap opened this issue Nov 30, 2017 · 6 comments

Comments

@madstap
Copy link
Contributor

madstap commented Nov 30, 2017

I prefer hiccup syntax to selmer, so I would like to be able to choose templating solutions.

@harlanji
Copy link

Hey @madstap, do you have any proposed solution yet? Have you made any progress?

Selmer is great and flexible, but Hiccup layouts would be a welcome complement to the EDN Front Matter adaptation. I'm working toward a full stack solution with minimal educational dependencies, so cutting out HTML templates for EDN templates that can be evaluated as Hiccup would be epic. It would both make teaching by example easier, and drive Cryogen toward being more compelling than both Jekyll and the up-and-coming Gatsby project.

As a side point, a second layout implementation would uncover natural hooking points and let stuff like the generated feeds be customized cleanly (I modified cryogen-core 0.1.60 RSS to look like YouTube's feed, for example, and it's a burden to push it up stream into a merge-able PR).

I'm just now starting to research this, started here.

@niamu
Copy link
Contributor

niamu commented Feb 4, 2019

I have a working Hiccup markup plugin here: niamu/cryogen-hiccup

Check it out and let me know what needs improving.

Here's a sample post that can be placed in resources/templates/hiccup/posts/2014-11-04-second-post.edn

{:title "Yet Another Post"
 :layout :post
 :tags  ["very fetch"]}

[:h3 "This Post So Fetch"]
[:p "some more stuff happened"]

@harlanji
Copy link

harlanji commented Feb 5, 2019

Hey @niamu, very good!

It is different than what we are describing here in my interpretation, but indeed a step toward a solution. This ticket would allow specifying the :post layout with Hiccup and replacing content markers with the rendered markup; your repo rather being an additional Markup. But Hiccup markups and themes together is an interesting addition that I’d not considered. As it stands, Selmer is hardcoded in the layout portion, meaning core needs to incorporate it or be refactored to allow pluggable Templates in addition to markups... I believe render.clj would require similar machinery like a protocol, similar to the pluggable Markup. I’d like to see core refactored and the existing Selmer template pulled into a plugin, and then Hiccup support added via a plugin such as yours. Thanks!

@niamu
Copy link
Contributor

niamu commented Feb 5, 2019

@harlanji have you given any thought as to how a Hiccup template system might work in regards to whether or not it should have extends and block and other template features as Selmer does?

I was giving it some thought today and I'm not sure exactly how we would solve the for loop iterations like Selmer does in a Hiccup-like template system. Ideally we would have an EDN file with Hiccup-like syntax in it and not a full namespace that has requires and evaluates inline Clojure code, right?

@harlanji
Copy link

harlanji commented Feb 5, 2019

@niamu, sounds similar to what I envision. I imagine forms could be injected into the context, including base forms like for/if. Questionable about defn, perhaps instead doing it via actual .clj like how Selmer filters are added. This would avoud the need for require, too, I think. A selmer filter adapter would be neat and allow for incremental incorporation/experimentation into existing code bases. Pardon my non-concrete replies, I am mobile and tied up until at least later this week, but love that this is materializing and will give feedback whenever requested or I see something.

@niamu
Copy link
Contributor

niamu commented Feb 5, 2019

Was playing around a bit and came up with this small proof of concept: hedn.core-test.

I'm not really happy with the eval call in hedn.core/render-template but it does get things working more or less how I was hoping they would. I don't think there are many security implications with this considering we're not shipping a running server that is going to execute code in the wild and instead the intent is to just run this within Cryogen, but maybe there is a better way. Thoughts?

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

No branches or pull requests

4 participants