Fork me on GitHub
#beginners
<
2016-12-05
>
nathansmutz01:12:04

I'm trying to learn and tool up for a core.logic project. I've found good resources for learning the highlights of some parts. Am I missing some central source for learning all of it?

akiroz03:12:46

have you used similar logic programming systems (like prolog) before? I learned prolog in college but you can pretty much learn prolog stuff and apply it directly to core.logic, it's mainly just syntactical differences AFAIK.

vjunloc05:12:11

@roelofw I wasn't able to require the module from the repl, but it started working automatically later on.

nathansmutz08:12:04

@akiroz I've read some prolog/logic examples and have an idea for how I hope things work. I work for a university; and I'm building something to prove whether our majors can be completed in 4 years with a given plan of course offerings. I imagine I'll be using the simple database stuff a bit. (prerequisite class-1 class-2), etc. It's going to get complicated.

akiroz08:12:04

Nice! course registration at my uni was horrible and I could never register for the courses I wanted to take because of timetable/prerequisite issues..... to top it off, the online system is this super slow/buggy Java + OracleDB thing. Ughh...

agile_geek09:12:04

@roelofw I tried out your code this morning and this works fine:

(defn read-data-painting2
  "Reads the title, description, date , collection, colors and url of a image"
  [id]
  (let [art-objects (-> (str "" id "?key=14OGzuak&format=json&type=schilderij&toppieces=True")
                        (client/get {:as :json})
                        :body
                        :artObject)
        name        (-> art-objects
                        :principalMakers
                        first
                        :name)
        description (:description art-objects)
        date (get-in art-objects [:dating :year])
        collectie (first (:objectCollection art-objects))
        colors (:colors art-objects)]

    {:id id :name name :description description :date date :collectie collectie :colors colors}))

(read-data-painting2 "SK-A-1718")

agile_geek09:12:36

It returns:

{:id "SK-A-1718",
 :name "Hendrick Avercamp",
 :description
 "Winterlandschap met ijsvermaak. Dorpsgezicht met vele figuren op het ijs: schaatsers, kolfspelers, wandelaars. Rechts een arrenslede, links een kerk.",
 :date 1608,
 :collectie "schilderijen",
 :colors ["#B0AD92" " #64614A" " #D7D3BA" " #76806F" " #373B30" " #1F1C15" " #9E824E"]}

agile_geek09:12:59

I think in one version of the code you had an additional line in the let: painter (get-in name [:name]) and you had {:id id :name painter :description description :date date :collectie collectie :colors colors} being returned.

agile_geek09:12:07

that returned nil for :name as name is just a string already so you can't call get-in on it

roelofw11:12:05

I see this as output on my webpage :

{:id"SK-A-2963", 
  :name #object[clojure.core$name 0x96b47c "[email protected]"], 
  :description "Portret van Don Ramón Satué. Lid van de Sala de Alcaldes de Corte per la Audiencia Territorial de Madrid. Heupstuk, naar links, staande met de handen in de zakken.", 
  :date 1823, 
  :collectie "schilderijen", 
  :colors ["#322318" " #0F0E09" " #573525" " #764736" " #796956" " #9F947C" " #BDB89D"], 
  } 

roelofw11:12:02

so name does again return a object instead of a name

roelofw11:12:13

@agile_geek

roelofw11:12:42

Which version do you use. IM on clojure 1.8.0

agile_geek11:12:07

Shame - but there's never been anything magical about :name keyword. I am testing this just in a normal repl so I'm not serialising it for web but even so the name is just a String so it shouldn't have a problem. I suspect something else is going on. Try calling your fn in a REPL like I did above (read-data-painting "SK-A-1718")

roelofw11:12:14

Then it's working well

roelofw11:12:34

very very wierd, @agile_geek

agile_geek11:12:50

So something else is going on. It looks like something is evaluating name symbol as the name fn

roelofw11:12:59

Then I think there are two places where things are happing with the output :

roelofw11:12:07

(defn homepage [req] (render-file "home.html" {:paintings (api/do-both-in-parallel(api/read-numbers)) } ))

roelofw11:12:37

and here :

{% for data  in  paintings %}
   {{ data }} </br> </br>
{% endfor %}  

roelofw11:12:40

do-both in parallel does this :

(defn do-both-in-parallel [ids]
  (let [paint-thread (future (pmap read-data-painting ids))
        image-thread (future (pmap read-image-url ids))]
    (pmap merge @paint-thread @image-thread)))  

roelofw11:12:08

so its making the big seq of maps with al the data I want

agile_geek11:12:39

So I can't see anything obviously wrong. I have said this before but using map for side effects like making an http call like you are doing here is bad practice as it sometimes means that the side effect never happens so we tend to force realisation using something like doall but if this was the problem you would see no data at all in the response.

roelofw11:12:09

oke, I use pmap because I want to work as much as possible with the api calls. Otherwise it takes long to display things. Some 7 seconds

agile_geek11:12:25

I understand that and it's not the problem you are seeing.

agile_geek11:12:05

There's some odd behaviour here as what's happening is that the name function is being returned instead of the value of the name var bound in your let. This may be some side effect of all the async threads you are using as as well as pmap you are using future but I think you may have found a bug. Either way shadowing a fn's name is bad practice in def let or argument vectors so I would just change your symbol used in the let to painter or painter-name as you did.

agile_geek11:12:10

If you have the entire code base somewhere you can share it, like on github, I can take a longer look sometime but it won't be for a while.

roelofw11:12:07

@agile_geek I can put it into github or bitbucket

roelofw11:12:50

and it's no problem that it takes a while. I have a working code so I can continue on

agile_geek12:12:47

Github would be good. Make sure it's the entire codebase incuding all the resources, project.clj etc. i.e. push the root project directory

roelofw12:12:49

oke, I did experiment again and when I change :name to :painter everything works well

agile_geek12:12:59

Stick with that for now but push the code you have so I can try it out.

sb12:12:35

That is strange. I tested your code, and that is work fine at me too. Please share with me what is the problem.. because I work on rest-api too. (like a beginner)

roelofw12:12:50

@sb : I do not work with rest-api but with clj-http

sb12:12:06

I use cheshire

sb12:12:53

I think, similar ok. I don’t know which faster, maybe clj-http

roelofw12:12:58

and the problem is that if I use :name I see a object as output. When rename it to for example : painter everything works well

roelofw12:12:53

I do not have to use cheshire because clj-http can convert json as a clojure object

roelofw12:12:26

@agile_geek is the link what you need ?

agile_geek12:12:01

@roelofw that's fine

sb12:12:36

@roelofw Ok!

sb12:12:38

I see the x y parameter wrong (maybe that is true?) (but I really don’t understand what is the main problem.. I don’t have really big experience)

sb12:12:17

I see at the pic two zero

agile_geek12:12:48

FYI the #object[clojure.core$name 0x96b47c "[email protected]"] is telling you that the thing in the map is clojure.core/name which is a Clojure function that takes a String, Symbol or Keyword and returns the String representation of it. https://clojuredocs.org/clojure.core/name

agile_geek12:12:02

@roelofw found it!

agile_geek12:12:11

(defn read-image-url
  "Reads the image-url"
  [id]
  (let [art-objects (-> (str "" id "/tiles?key=14OGzuak&format=json")
                        (client/get {:as :json})
                        :body
                        :levels
                        )

        url (filter #(= (:name %) "z4") art-objects)
        tiles (:tiles (first url))
         ]
    {:id id :name name :tiles tiles}))

agile_geek12:12:42

You merge the results of read-image-url with the results of read-data-painting

agile_geek12:12:08

here:

(defn do-both-in-parallel [ids]
  (let [paint-thread (future (pmap read-data-painting ids))
        image-thread (future (pmap read-image-url ids))]
    (pmap merge @paint-thread @image-thread)))

roelofw12:12:38

yes , image-url takes care of the tiles part. read-data takes care of the rest of the output

agile_geek12:12:12

As the @image-thread maps coming back from read-image-url is last it's :name value overwrites any :name from read-data-painting

agile_geek12:12:42

so you always get the :name from the call to read-image-url

agile_geek12:12:08

look at the way you construct name in read-image-url

agile_geek12:12:30

where is the value on name set?

roelofw12:12:59

yes, im filtering on the items where name : z4

agile_geek12:12:30

where do you assign a value to the name symbol in the let?

roelofw12:12:03

in the other function as I understand where you are going to

agile_geek12:12:12

you set art-objects, url and tiles but no name

agile_geek12:12:53

so when you reference name when constructing the map returned from read-image-url you are returning the name function

roelofw12:12:58

yes, the name is a part of the json reponse. not data that I want to be the output

agile_geek12:12:29

But you are referencing a symbol called name without giving it a value in read-image-url

roelofw12:12:23

which one makes now the function. the filter one or the -> one

agile_geek12:12:54

look at the map returned from read-image-url here: {:id id :name name :tiles tiles}

roelofw12:12:07

yep, there I use :name

agile_geek12:12:33

you are setting a key :name with the value from a symbol called name

agile_geek12:12:47

but you have no value for the symbol name

roelofw12:12:05

yep, where name schould be the one in the let of the same function

agile_geek12:12:53

but there's no name declared in the let in read-image-url do you see?

agile_geek12:12:26

(let [art-objects (-> (str "" id "/tiles?key=14OGzuak&format=json")
                        (client/get {:as :json})
                        :body
                        :levels
                        )

        url (filter #(= (:name %) "z4") art-objects)
        tiles (:tiles (first url))
         ]
    {:id id :name name :tiles tiles})

roelofw12:12:24

name is is only declared in the read-data-url in the let

roelofw12:12:07

chips, name schould not be there

roelofw12:12:54

I messed up my code

roelofw12:12:10

When I delete that part , everything works well

roelofw12:12:22

@agile_geek thanks for the time

roelofw12:12:27

next challenge : make a own design inspired by this one : http://wedesignthemes.com/html/redart/default/

roelofw12:12:59

first I have to look up how to make a picture frame with css that fits all the paintings

roelofw13:12:29

@agile_geek any furthers remarks on the code

roelofw13:12:45

This is my first projct ever made in clojure

agile_geek13:12:16

@roelofw no problem. This is how we learn

roelofw14:12:51

@agile_geek yes, and we learn from our mistakes not from the things that we can do without any problem

roelofw15:12:12

@agile_geek now some html and css work to do , to make a nice layout to show all the images

roelofw15:12:36

How can I tell selmer that the styles.css is in the resources folder ; {% style "styles.css" %}

roelofw16:12:34

also chancing it to {% style "css/styles.css" %} and putting the css file into resources/css does not make that the css file is found

roelofw16:12:11

maybe luminus is a good way for a starting project

roelofw16:12:58

@dpsutton still confused. I do now (render "{% style \"/css/screen.css\" %}"

roelofw16:12:17

and now I see render " " on my screen

dpsutton16:12:21

I'm not sure. I've never used selmer

dpsutton16:12:30

just pointing you to the documentation in case you hadn't seen it

roelofw16:12:45

What do you use then ?

roelofw16:12:06

I thought selmer was a easy choice but im fighting all the way now

dominicm16:12:59

Selmer is easy. The style tag just makes it easy to link to css. You need to serve your css like normal using ring

nathansmutz16:12:41

#akiroz Was it Elucian Banner perchance? :-)

roelofw16:12:56

@dominicm : So I schould so <link rel="stylesheet" type="text/css" href="public/css/styles.css">

roelofw16:12:18

nope, still not found 😞

akiroz16:12:20

@nathansmutz I'm not sure what the underlaying system is called since they styled it to our uni but... might be~ I only found out about the tech stack when the server returned stacktraces in a 500 response xD

roelofw16:12:16

Is there a sort of bare luminus template ?

akiroz16:12:59

@roelofw lein new luminus <project-name>

dominicm16:12:09

@roelofw can you go to localhost:3000/public/css/styles.css ? If not, that's why it's broke

roelofw16:12:43

not found. also 'resources/public/css/styles.css` give a 404 error

dominicm16:12:22

So are you serving your public folder? If so, how are you doing it?

roelofw16:12:26

I did not change anything in the code. Just placing things into that directory and try to point to it

roelofw16:12:24

maybe I can better find a good book/tutorial about web development with only ring and compojure

roelofw16:12:39

I know that Home.html is found bu selmer bu just doing ( render 'home.html ..... )

roelofw16:12:54

I thought css files are also found that way

roelofw16:12:50

someone who can recommend a book ?

roelofw17:12:30

is this a book only about luminus or also about making web apps with just compojure

roelofw17:12:15

@agile_geek do you have a idea why <link rel="stylesheet" type="text/css" href="/css/style.css"> cannot find a css file which resides in resources/public/css directory ?

agile_geek17:12:34

I have edition 1 but it covers how to build a simple web app with just ring/compojure not sure about edition 2

agile_geek17:12:55

re: your second question, depends on how your organising your resources and the routes defined in compojure. Can't tell without code and I'm at work in middle of another issue atm

roelofw17:12:54

This is my handler file with the routes :

(ns paintings.handler
  (:require [compojure.core :refer :all]
            [compojure.route :as route]
            [ring.middleware.defaults :refer [wrap-defaults site-defaults]]
            [paintings.views :as views]
            ))

(defroutes app-routes
  (GET "/" [] views/homepage)
  (route/not-found "Not Found"))

(def app
  (wrap-defaults app-routes site-defaults))  

roelofw17:12:34

I have then a home.html in resources and a home.css file in resources/public/css

sb17:12:55

@roelofw http://safaribooksonline.com/ free in every 14 days 🙂

sb17:12:06

lot of book there.. I read that books

dpsutton17:12:04

well, if its not at "/", then you return a 404

dpsutton17:12:24

so your handler can't possibly return anything but your homepage of 404

roelofw17:12:03

oke, so I have to make another entry for the css files and so on , @dpsutton ?

dpsutton17:12:17

you probably want to serve your public folder

agile_geek17:12:20

@roelofw you probably need to add a (route/resources "/") to your app-routes

agile_geek17:12:17

that should serve static routes from your resources folder

roelofw17:12:43

oke, I will hit some tutorials where I have to do that

agile_geek17:12:45

It's been a while since I did this but it probably needs to go after the GET but before the not-found

roelofw17:12:19

so something like this :

(defroutes app-routes
  (GET "/" [] views/homepage)
           (route/resources "/")
  (route/not-found "Not Found")) 

agile_geek17:12:40

Yep although the indentation is a bit strange in that snippet but that's probably just slack

roelofw17:12:48

still no luck

agile_geek17:12:23

you probably need to check that the reference in the html is correct too..it's been a while since I did this from scratch and I can't remember what the path to resources is relative too.

agile_geek17:12:35

find an example somewhere

roelofw17:12:38

I m a little bit further. Can selmer work with html5

roelofw17:12:05

I have this template now :

<!doctype html>

<html lang="en">
<head>
   <meta charset="utf-8">

   <title>The HTML5 Herald</title>
   <meta name="description" content="The HTML5 Herald">
   <meta name="author" content="SitePoint">

    <link rel="stylesheet" type="text/css" href="/css/styles.css">

   <!--[if lt IE 9]>
   <script src="https://cdnjs.cloudflare.com/ajax/libs/html5shiv/3.7.3/html5shiv.js"></script>
   <![endif]-->
</head>

<body>
 <h1> ik wordt gek van clojure</h1>

</body>
</html>
 

roelofw17:12:27

and I see two errors on Edge. First the end tag of head is not right

roelofw17:12:44

and second it says there are more then 1 body tag

agile_geek17:12:44

I'd get rid of that IE9 script hack unless you really need it to test...its probably not the problem but it's another thing that can go wrong.

agile_geek17:12:27

I haven't used Selmer for 3 years so I'm not going to be much help

roelofw17:12:12

@agile_geek what do you use then

roelofw17:12:36

I work now with selmer for 2 / 3 days and its making me grazy

roelofw17:12:40

I see now the background when I putting it into the css folder. crazy

agile_geek17:12:42

Mostly Reagent and Re-frame to serve single page apps or plain hiccup but I rarely write an app from scratch so this stuff is usually already in place.

roelofw17:12:56

oke, maybe I also will try luminus

roelofw17:12:13

then I also know that some things are in place

roelofw17:12:32

from nothing is one step too far for me

dpsutton17:12:54

you are doing from nothing right now i think

roelofw17:12:59

pity, that I get a lot of libraries with it that I do not need

dpsutton17:12:00

he means he usually works on existing apps

roelofw17:12:19

@dpsutton yep, and so far no fun

agile_geek18:12:31

@dpsutton Correct I am usually working on something someone else started. Frequently it's a service not a UI as well so it's often just api request/responses

agile_geek18:12:03

I've written apps from scratch just not for a little while

dpsutton18:12:05

were you at the conj by any chance?

agile_geek18:12:48

No I co-organise Clojure eXchange in London which was on at same time

dpsutton18:12:05

ah. i'll need to watch those videos

dpsutton18:12:18

was wondering if we had run into each other by any chance but it sounds like we haven't

agile_geek18:12:06

Nope but maybe next year? 😀

agile_geek18:12:43

I'm considering going to a US conference but Strange Loop is top of my list

roelofw18:12:51

on luminus when I do this : [paintings2.api_get :as api])) does it find the file api_get.clj which resides in src ?

seancorfield18:12:51

I decided to skip Strange Loop this year and go to the Conj instead (I went to Clojure/West and could only do one more conference). Having gone to Strange Loop four times, as well as several past Clojure/West and Clojure/conj events, I think that was the right decision (for me). If you’ve never been to Strange Loop, it’s definitely worth going at least once — it can be pretty inspirational and the talks are often fascinating — but I find I get more value out of /West and /conj these days.

roelofw18:12:26

I use the paintings2.api-get in the directory routes

seancorfield18:12:28

@roelofw You mean in a (:require …) clause inside (ns …) ?

roelofw18:12:00

see here :

(ns paintings2.routes.home
  (:require [paintings2.layout :as layout]
            [compojure.core :refer [defroutes GET]]
            [ring.util.http-response :as response]
            [ :as io]
            [paintings2.api_get :as api]))  

seancorfield18:12:09

If the (ns …) inside src/paintings2/api_get.clj says paintings2.api-get (which it should), then the :require should match that.

seancorfield18:12:26

The rule of thumb is: _ in filenames, - in namespaces.

roelofw18:12:55

and that is correct, in src there is a file called api-get.clj

seancorfield18:12:20

The file should be api_get.clj, the namespace should be api-get.

roelofw18:12:22

but I see this familiar error : Caused by: java.io.FileNotFoundException: Could not locate paintings2/api_get__init.class or paintings2/api_get.clj on classpath.

seancorfield18:12:40

If your file is called api-get.clj, that’s wrong.

roelofw18:12:52

oke, then I mixed up the rwo

seancorfield18:12:56

Files have underscores. Namespaces have hyphens.

roelofw18:12:22

Still errors :

java.lang.Exception: namespace 'paintings2.api-get' not found after loading '/paintings2/api_get'  

roelofw18:12:40

(ns paintings2.routes.home
  (:require [paintings2.layout :as layout]
            [compojure.core :refer [defroutes GET]]
            [ring.util.http-response :as response]
            [ :as io]
            [paintings2.api-get :as api]))

(defn home-page []
  (layout/render
    "home.html"  "home.html"  {:paintings (api/do-both-in-parallel(api/read-numbers))  }))

(defroutes home-routes
  (GET "/" [] (home-page)))  

roelofw18:12:49

filename : api_get.clj

roelofw18:12:59

what did I do wrong

roelofw18:12:21

the file has a underscore and the namespace a hypens

roelofw18:12:09

or do I need to say which directory the api-get resides

jjfine18:12:35

it figures out the directory based on the namespace

jjfine18:12:01

so it should be paintings2/api_get.clj

jjfine18:12:23

and the file you posted should be in paintings2/routes/home.clj

roelofw18:12:14

@jjfine that is all correct

roelofw18:12:22

and still the error 😞

jjfine18:12:26

does paintings2/api_get.clj look like:

(ns paintings2.api-get ...

roelofw18:12:38

if I look at the error , this is somehow wrong : [paintings2.api-get :as api]))

jjfine18:12:22

thats the problem

jjfine18:12:30

underscore instead of dash

roelofw18:12:44

except the ns is this : (ns paintings2.api_get

jjfine18:12:20

change it to a dash

jjfine18:12:45

the require and the ns need to match

jjfine18:12:05

the filename needs a underscore

roelofw18:12:05

oke, that part worked

roelofw18:12:34

now I see this error : ' java.lang.String cannot be cast to clojure.lang.Associative `

roelofw18:12:27

oke, that one is solved also

roelofw18:12:43

Now hoping I can get the layout that I wanted now

roelofw18:12:30

the same problem. I have a background-image on resources/public/img and a css file on resources/public/css

roelofw18:12:54

and when I do background: url(../img/old-wall.jpg) no-repeat center center fixed;

roelofw18:12:00

no background to see

roelofw19:12:59

anyone a idea how to make this work

agile_geek20:12:28

@roelofw you need to remove the .. at the start of the image url

agile_geek20:12:54

resources are served relative to the resources dir

agile_geek20:12:25

you may need /public/img/old-wall.jpg I can't remember

agile_geek20:12:52

try with and without public

roelofw20:12:55

nope, this background: url('/img/old-wall.jpg') no-repeat center center fixed; is not showing the background

roelofw20:12:05

and this is not working also background: url('/public/img/old-wall.jpg') no-repeat center center fixed;

agile_geek20:12:53

silly question but you do have a file called old-wall.jpg in the directory resources/public/img/?

agile_geek20:12:34

and you have (routes/resources "/") in the routes def?

roelofw20:12:44

Directory of C:\Users\rwobb\Desktop\clojure\paintings2\resources\public\img

05-12-2016  19:45    <DIR>          .
05-12-2016  19:45    <DIR>          ..
05-12-2016  16:24            69.716 old-wall.jpg
               1 File(s)         69.716 bytes
               2 Dir(s)  771.299.135.488 bytes free  

roelofw20:12:53

and this is the routes/home.clj file made by lumunis :

(ns paintings2.routes.home
  (:require [paintings2.layout :as layout]
            [compojure.core :refer [defroutes GET]]
            [ring.util.http-response :as response]
            [ :as io]
            [paintings2.api-get :as api]))

(defn home-page []
  (layout/render
    "home.html" {:paintings (api/do-both-in-parallel(api/read-numbers))  }))

(defroutes home-routes
  (GET "/" [] (home-page)))  

roelofw20:12:23

so no 'routes/resources "/")` part

agile_geek20:12:33

Yes that may be it

roelofw20:12:39

the css seems to be found now

agile_geek20:12:56

I think you don't need public in the path

agile_geek20:12:10

even though the img dir is below public

roelofw20:12:19

when I do

(defroutes home-routes
  (GET "/" [] (home-page))
  (routes/resources "/")  )  

roelofw20:12:51

I see this error message : No such namespace: routes, compiling:(paintings2/routes/home.clj:14:3)

roelofw20:12:22

here the whole route file :

(ns paintings2.routes.home
  (:require [paintings2.layout :as layout]
            [compojure.core :refer [defroutes GET]]
            [ring.util.http-response :as response]
            [ :as io]
            [paintings2.api-get :as api]))

(defn home-page []
  (layout/render
    "home.html" {:paintings (api/do-both-in-parallel(api/read-numbers))  }))

(defroutes home-routes
  (GET "/" [] (home-page))
  (routes/resources "/")  )
 

agile_geek20:12:38

The (routes/resources "/") is mapping all static resources starting at a path "/" to the default public folder in resources

agile_geek20:12:55

add resoources to the refer vector in the require for compojure like so: [compojure.core :refer [defroutes GET resources]]

agile_geek20:12:10

then you can just say (resources "/")

agile_geek20:12:45

should be this:

agile_geek20:12:23

[compojure.route :refer [resources]]

agile_geek20:12:37

as a new line in the :require

agile_geek20:12:54

and the compojure.core line stays as it was

agile_geek20:12:33

as resources is defined in compojure.route not compojure.core

agile_geek20:12:29

what happened to your not-found route?

agile_geek20:12:22

is there another namespace with routes in it where you've already defined not-found and resources?

agile_geek20:12:41

I think I'm confusing you because I can only see a small part of your entire code base

roelofw20:12:59

nope, I started again with a luminus template

roelofw20:12:15

and I think there is no not-found route

roelofw20:12:56

No such namespace: routes

roelofw20:12:28

must that line not be [compojure.route :refer [routes]]

agile_geek20:12:43

I have never used liminus so I may be steering you wrong but I think that if you need to serve static files like css and images you need resources route defined and you will need not-found to handle URLs that don't match a route.

agile_geek20:12:02

Stop fo ra minute while I explain

agile_geek20:12:54

In a namespace declaration you can bring in libraries using the :require keyword as above

agile_geek20:12:08

there are several patterns for this

agile_geek20:12:58

you can give a required namespace an alias like this: [compojure.route :as routes]

agile_geek20:12:39

the :as will mean I can call a fn in the compojure.route namespace like this (routes/not-found)

agile_geek20:12:46

I can prefix any fn in the compojure.route namespace with routes and it will find it so I can also say (routes/resources)

agile_geek20:12:03

Another way to require fn's from a namespace is like this:

agile_geek20:12:40

[compojure.route :refer [not-found resources]]

agile_geek20:12:50

this will just require the names fn's

agile_geek20:12:15

in this case just not-found and resources but nothing else in compojure.route

agile_geek20:12:55

There is another way to do this which is not recommended which is to require all fn's without a namespace alias or listing them:

agile_geek20:12:09

[compojure.route :refer :all]

roelofw20:12:25

oke, I sometimes see that

agile_geek20:12:12

So to get both not-found and resources which are both in compjure.route I could do this:

roelofw20:12:35

when I use refer , is it right to use not-found like this (not-found) or do I use (clojure.route/not-found) ?

agile_geek20:12:32

(ns ....
   (:require [compojure.route :as routes])

...
(defroutes app
  (routes/resources "/")
  (routes/not-found))

agile_geek20:12:49

(ns ...
  (:require [compojure.route :refer [not-found resources])

...
(defroutes app
  (resources "/")
  (not-found))

agile_geek20:12:14

I've left out the GET in the defroutes but you would obviously have that too

agile_geek20:12:24

Does that make sense?

roelofw20:12:32

yes, makes a lot sense

roelofw20:12:52

so I did

(defroutes home-routes
  (GET "/" [] (home-page))
  (resources "/")  ) 

roelofw20:12:30

but still no background 😞

agile_geek20:12:34

So you would need the [ ... :refer [...]] version of require

roelofw20:12:50

I did that

roelofw20:12:06

ns paintings2.routes.home
  (:require [paintings2.layout :as layout]
            [compojure.core :refer [defroutes GET  ]]
            [ring.util.http-response :as response]
            [ :as io]
            [paintings2.api-get :as api]
            [compojure.route :refer [resources]]))

(defn home-page []
  (layout/render
    "home.html" {:paintings (api/do-both-in-parallel(api/read-numbers))  }))

(defroutes home-routes
  (GET "/" [] (home-page))
  (resources "/")  )
 

agile_geek20:12:07

OK that looks OK so must be something to do with the path in the html template file

roelofw20:12:22

I think so

agile_geek20:12:39

Anyway got to go...good luck

roelofw20:12:03

I did a lot of googeling but I did not find any link/tutorial for a background-image

dpsutton20:12:53

you don't need a tutorial on background image

dpsutton20:12:57

you need a tutorial on serving static files

dpsutton20:12:13

follow that tutorial and get the site up and running how they ahve

dpsutton20:12:23

and then adapt it to your needs afterwards

roelofw21:12:18

@dpsutton I did everything according to that tutorial

roelofw21:12:30

both css and the img are in the public directory

roelofw21:12:31

So I have no idea why the image is not shown