admin-announcements

Announcements from the Clojurians Admin Team (@U11BV7MTK @U077BEWNQ @U050TNB9F @U0ETXRFEW @U04V70XH6 @U8MJBRSR5 and others)
roelof 2015-12-12T12:42:08.001179Z

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 ?

roelof 2015-12-12T12:44:06.001180Z

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>

naomarik 2015-12-12T12:51:41.001182Z

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

πŸ‘ 1
jeff.terrell 2015-12-12T13:37:37.001183Z

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

2015-12-12T13:54:25.001184Z

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

2015-12-12T13:57:26.001185Z

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

roelof 2015-12-12T14:04:43.001186Z

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

roelof 2015-12-12T14:05:15.001187Z

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

roelof 2015-12-12T14:05:24.001188Z

How would I do that ?

roelof 2015-12-12T14:06:31.001189Z

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

jeff.terrell 2015-12-12T14:11:24.001190Z

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

jaen 2015-12-12T14:31:47.001191Z

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

roelof 2015-12-12T14:46:10.001192Z

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

roelof 2015-12-12T14:47:18.001193Z

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

roelof 2015-12-12T14:47:32.001194Z

I will play and experiment with the idea

roelof 2015-12-12T14:47:43.001195Z

thanks for the idea

roelof 2015-12-12T14:48:50.001196Z

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

roelof 2015-12-12T14:49:08.001197Z

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

roelof 2015-12-12T14:49:10.001198Z

?

jeff.terrell 2015-12-12T14:55:29.001199Z

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

roelof 2015-12-12T14:55:53.001200Z

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

jaen 2015-12-12T14:57:02.001201Z

No, why.

jaen 2015-12-12T14:57:09.001202Z

You can split the functions as you wish

jaen 2015-12-12T14:57:15.001203Z

Just like you would with Clojure source

jaen 2015-12-12T14:57:27.001204Z

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

roelof 2015-12-12T14:57:49.001205Z

I thought so by the example jeff gave

jaen 2015-12-12T14:58:04.001206Z

Templating in hiccup is just writing Clojure functions

jaen 2015-12-12T14:58:10.001207Z

That return hiccup vectors

roelof 2015-12-12T14:58:15.001208Z

This is the first time I try with multiple sources

jaen 2015-12-12T14:58:19.001209Z

So anything you would do with Clojure functions

jaen 2015-12-12T14:58:23.001210Z

Applies here

jaen 2015-12-12T14:58:34.001211Z

You may put everything in one file

jaen 2015-12-12T14:58:40.001212Z

Or makes namespaces to group related things

jaen 2015-12-12T14:58:45.001213Z

It's up to you

roelof 2015-12-12T14:59:10.001214Z

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

jeff.terrell 2015-12-12T14:59:20.001215Z

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.

jaen 2015-12-12T14:59:40.001216Z

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.

jaen 2015-12-12T14:59:47.001217Z

But that's again - matter of taste.

jaen 2015-12-12T15:00:12.001218Z

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

jeff.terrell 2015-12-12T15:02:37.001219Z

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

roelof 2015-12-12T15:04:31.001220Z

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

jaen 2015-12-12T15:05:59.001222Z

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.

roelof 2015-12-12T15:06:53.001223Z

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

jaen 2015-12-12T15:07:22.001224Z

No, but that would be the same as there.

jaen 2015-12-12T15:08:20.001225Z

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.

roelof 2015-12-12T15:09:03.001226Z

oke, thanks everyone

roelof 2015-12-12T15:09:36.001227Z

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

roelof 2015-12-12T15:24:21.001228Z

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

jaen 2015-12-12T15:24:45.001229Z

Like any other tag, really

jaen 2015-12-12T15:25:35.001230Z

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

jaen 2015-12-12T15:25:54.001231Z

it's always

jaen 2015-12-12T15:26:19.001232Z

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

roelof 2015-12-12T15:29:47.001234Z

oke, thanks

naomarik 2015-12-12T18:34:46.001239Z

@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

bhauman 2015-12-12T18:40:49.001240Z

@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

jaen 2015-12-12T22:00:06.001242Z

https://github.com/Day8/re-frame/wiki/Using-Stateful-JS-Components might be helpful