Fork me on GitHub
#admin-announcements
<
2015-12-12
>
roelof12:12:08

if I right hiccup has no template inheritance. How can I make it work thatI made one template for several pages ? or can I better use selmer ?

roelof12:12:06

If I can better use selmer. How must I translate this : ' <script type="text/javascript" src="js/jquery-ui-1.10.2.custom.js"></script>

naomarik12:12:41

i've never seen anyone offended before for saying "hey guys." where I was raised and where I'm living now, it's inclusive of anyone male/female whatever. just a colloquial that everyone is used to. i know as programmers we are pretty pedantic but shouldn't make anyone feel bad for speaking the way they're used to talking

jeff.terrell13:12:37

@roelof: Hiccup is dealing with HTML as a data structure. So if you want to have a "template", in Hiccup that would be a function that returns a data structure that is partially the same no matter what you pass it, and partially depends on what you pass it. So, like, if your template is all the header and footer stuff, and you want to put some content within that template, write a function that accepts that content (as a Hiccup data structure) as the argument and returns the data for the whole page. It's just data structures, so it should be easy.

chedgren13:12:25

Where do people put clojure snippets on the web? Like codepen or jsfiddle or gist.

chedgren13:12:26

Gist had all the features i wanted (doesn't it always?) nvm.

roelof14:12:43

@jeff.terrell: sorry I do not fully understand you.

roelof14:12:15

Let's say I have a home page and a contact page which shares the same header and footer

roelof14:12:24

How would I do that ?

roelof14:12:31

@chedgren: Most of us use refheap. You can find it here : https://www.refheap.com/

jeff.terrell14:12:24

@roelof: Something like this:

(defn content->page [content]
  [:html
    [:head ...]
    [:body
      [:div.content content]
      [:div.footer ...]]])
You'd have to fill out the details of the header and footer. But then you could say e.g.:
(content->page [:p "Hello world!"])
…to get a full page with that content. Make sense?

jaen14:12:47

Yeah, basically in hiccup template inheritance can be done with language mechanisms - function composition and higher order functions.

roelof14:12:10

oke, so I can make functions for all and when I want to use them I could make a function call with the right parameters

roelof14:12:18

I hope I can make then a template like this page that way : https://laboutique.lemonstand.com/

roelof14:12:32

I will play and experiment with the idea

roelof14:12:43

thanks for the idea

roelof14:12:50

I already have figured out how to call css and js files

roelof14:12:08

In hiccup do they also have to be in the resoures directory

jeff.terrell14:12:29

I don't think hiccup cares about that, but resources/ is the standard place to put them.

roelof14:12:53

and do I understand it right I have to do all the templating of all the pages in one file

jaen14:12:02

No, why.

jaen14:12:09

You can split the functions as you wish

jaen14:12:15

Just like you would with Clojure source

jaen14:12:27

But I guess grouping things by a page is a good idea.

roelof14:12:49

I thought so by the example jeff gave

jaen14:12:04

Templating in hiccup is just writing Clojure functions

jaen14:12:10

That return hiccup vectors

roelof14:12:15

This is the first time I try with multiple sources

jaen14:12:19

So anything you would do with Clojure functions

jaen14:12:23

Applies here

jaen14:12:34

You may put everything in one file

jaen14:12:40

Or makes namespaces to group related things

jaen14:12:45

It's up to you

roelof14:12:10

oke, i will try to find some examples of using namespaces

jeff.terrell14:12:20

Right. You can have a different function for the header content, for example. Or you could have multiple different templates. Or whatever you want. It's just data.

jaen14:12:40

Also, you don't have to put hiccup templates in resource directory, you can have them in the same source directory the rest of code, since it's code like any other.

jaen14:12:47

But that's again - matter of taste.

jaen15:12:12

I usually keep my hiccup in the source directory under some namespace like project-name.templates.page-name or something.

jeff.terrell15:12:37

Yes, good point @jaen. To clarify, I think resources/ is a good place to put CSS and JS files, but I probably wouldn't put any Clojure functions (like my content->page example above) in resources/. Code goes in src/.

roelof15:12:31

oke, and I found here a example of what you are trying to tell me : https://github.com/yokolet/hiccup-samples/blob/master/src/

jaen15:12:59

Yup, that looks pretty sensible to me, though I usually wrap each function-template with the` html` macro, not just the top level one, but I'm unsure if that's wrong or right - that's just what I do.

roelof15:12:53

jaen: oke, do you have a example where I can look at

jaen15:12:22

No, but that would be the same as there.

jaen15:12:20

The difference would be I would be doing

(def template []
  (hiccup/html5 [:div "some hiccup"]))
instead of
(def template []
  [:div "some hiccup"])
in each template.

roelof15:12:03

oke, thanks everyone

roelof15:12:36

time to experiment with this and hopefully I have a page ready soon

roelof15:12:21

last question I hope. How do I translate this ` <meta charset="UTF-8"> <meta name="Description" content=""/>`

jaen15:12:45

Like any other tag, really

jaen15:12:35

[:meta {:charset "UTF-8"}]
[:meta {:name "Description" :content ""}]

jaen15:12:54

it's always

jaen15:12:19

[:tag-name {:attributes "go here"} "some content" 123]

roelof15:12:47

oke, thanks

naomarik18:12:46

@bhauman: devcards is pretty awesome 😉 just wondering if you knew how to get some jquery library initializing from the dom to play nicely with reagent

bhauman18:12:49

@naomarik: that's more of a React thing. Read up on how to create react components and the lifecycle https://facebook.github.io/react/docs/component-specs.html