Re: I'm trying to make proper urls, but I seem to be failing at it.

2014-03-12 Thread David Toomey
Yes, that certainly did help. Can't believe I didn't see this and it still 
flew over my head when others pointed it out. 

Looks a bit hacky, but this is the result I came up with (for future 
person's reference): 

(GET  /:profile-page [profile-page]
(if (= (.indexOf profile-page  ) -1)
  (let [profile-page (clojure.string/replace profile-page #-  )]
(let [[{user-profile :handle}] (db/get-users profile-page)]
  (if (not (nil? user-profile))
(layout/page-top
 (str profile-page's Profile Page)
 (profile/profile-page profile-page)))


It's sort of the finishing touches on a relatively complete project. Of 
course, gotta mind those anchors (thanks for that reminder, lest I'd see 
everything blow up). 

Thank you everyone for the time and patience. 

On Monday, March 10, 2014 11:00:32 PM UTC-7, Jarrod Swart wrote:

 No edit button so I have to post again, that first example should end with 
 ;; (make-profile-url John Smith) = /John-Smith

 And to reiterate you decide what your url will look like in your template:

 a href=http://myapp.com/JohnSmith;View John Smith's Profile/a
 or
 a href=http://myapp.com/John-Smith;View John Smith's Profile/a
 or
 a href=http://myapp.com/john-smith;View John Smith's Profile/a

 Then compojure + your route handler respond to the browser requesting the 
 link:

 ;; obviously this is ALL just psedo code of the important elements to give 
 you an idea
 (GET /:username [username] (view-profile-page username)) ;; this route 
 definition will handle any of the above links

 ;; assume you chose the last link type, in stack-overflow style. this 
 means username from the route is john-smith
 (defn view-profile-page [username]
   (let [user (db/get-user-by-username username)]
 (render-template user)))

 (defn get-user-by-username [username]
   (let [no-dash (clojure.string/replace username #-  ) ;; munge 
 username to match what is in DB
  capitalized (capitalize-words no-dash)]
 (select-user-by-name capitalized)))

 So as you can see whatever link or browser request is called, compojure 
 grabs that url param and passes it in.  You then modify that param to fit 
 what you expect and look it up in your DB.  You were essentially working 
 backwards I think.

 Hope that helps!



-- 
You received this message because you are subscribed to the Google
Groups Clojure group.
To post to this group, send email to clojure@googlegroups.com
Note that posts from new members are moderated - please be patient with your 
first post.
To unsubscribe from this group, send email to
clojure+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/clojure?hl=en
--- 
You received this message because you are subscribed to the Google Groups 
Clojure group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to clojure+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: I'm trying to make proper urls, but I seem to be failing at it.

2014-03-11 Thread Jarrod Swart
No edit button so I have to post again, that first example should end with 
;; (make-profile-url John Smith) = /John-Smith

And to reiterate you decide what your url will look like in your template:

a href=http://myapp.com/JohnSmith;View John Smith's Profile/a
or
a href=http://myapp.com/John-Smith;View John Smith's Profile/a
or
a href=http://myapp.com/john-smith;View John Smith's Profile/a

Then compojure + your route handler respond to the browser requesting the 
link:

;; obviously this is ALL just psedo code of the important elements to give 
you an idea
(GET /:username [username] (view-profile-page username)) ;; this route 
definition will handle any of the above links

;; assume you chose the last link type, in stack-overflow style. this means 
username from the route is john-smith
(defn view-profile-page [username]
  (let [user (db/get-user-by-username username)]
(render-template user)))

(defn get-user-by-username [username]
  (let [no-dash (clojure.string/replace username #-  ) ;; munge 
username to match what is in DB
 capitalized (capitalize-words no-dash)]
(select-user-by-name capitalized)))

So as you can see whatever link or browser request is called, compojure 
grabs that url param and passes it in.  You then modify that param to fit 
what you expect and look it up in your DB.  You were essentially working 
backwards I think.

Hope that helps!

-- 
You received this message because you are subscribed to the Google
Groups Clojure group.
To post to this group, send email to clojure@googlegroups.com
Note that posts from new members are moderated - please be patient with your 
first post.
To unsubscribe from this group, send email to
clojure+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/clojure?hl=en
--- 
You received this message because you are subscribed to the Google Groups 
Clojure group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to clojure+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: I'm trying to make proper urls, but I seem to be failing at it.

2014-03-10 Thread David Toomey
Thanks for the repiles -- and sorry for the delayed reply. I guess I'm 
doing something obnoxiously stupid.

The code I'm working with looks like this: 

  (GET  /:profile-page [profile-page]
   . ;;; check if user is in database, if so, show the profile 
page: ))

I've tried several variations on the theme, but the only thing that doesn't 
throw an error is this: 

(:require [ring.util.codec :as codec)

  (GET (codec/url-encode /:profile-page) [profile-page]

Which does not give the desired result and throws a 404. 

I tried adding it in middleware, converting the arguments to a map, stuff 
like this: 

  (GET (str /:profile-page (codec/url-encode [profile-page]))

At this point, I'm clearly guessing and I fear I did something wrong 
somewhere else. I'm still confused as to why, even after using this, the 
urls do not replace any of the spaces with %20 or anything else. 

It's probably not the least bit surprising that this works without throwing 
a 404, but of course, does not replace the blank spaces:

  (GET (codec/url-decode /:profile-page) [profile-page]

Thanks;
David

-- 
You received this message because you are subscribed to the Google
Groups Clojure group.
To post to this group, send email to clojure@googlegroups.com
Note that posts from new members are moderated - please be patient with your 
first post.
To unsubscribe from this group, send email to
clojure+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/clojure?hl=en
--- 
You received this message because you are subscribed to the Google Groups 
Clojure group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to clojure+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: I'm trying to make proper urls, but I seem to be failing at it.

2014-03-10 Thread James Reeves
You should be able to write:

(GET /:profile-page [profile-page] ...)

Compojure (via Clout) automatically decodes parameters in the URL, so there
shouldn't be any need to decode the data any further.

However, for future reference, routes in Compojure have a syntax very
similar to functions. So writing:

(GET /:profile-page (codec/url-encode [profile-page]))

Is similar to writing:

(fn (codec/url-encode [profile-page]))

You'll just get a syntax error. Instead, you need to write something like:

(GET /:profile-page [profile-page]
  (let [profile-page (codex/url-encode profile-page)]
...))

- James

On 10 March 2014 07:07, David Toomey dbtoo...@gmail.com wrote:

 Thanks for the repiles -- and sorry for the delayed reply. I guess I'm
 doing something obnoxiously stupid.

 The code I'm working with looks like this:

   (GET  /:profile-page [profile-page]
. ;;; check if user is in database, if so, show the profile
 page: ))

 I've tried several variations on the theme, but the only thing that
 doesn't throw an error is this:

 (:require [ring.util.codec :as codec)

   (GET (codec/url-encode /:profile-page) [profile-page]

 Which does not give the desired result and throws a 404.

 I tried adding it in middleware, converting the arguments to a map, stuff
 like this:

   (GET (str /:profile-page (codec/url-encode [profile-page]))

 At this point, I'm clearly guessing and I fear I did something wrong
 somewhere else. I'm still confused as to why, even after using this, the
 urls do not replace any of the spaces with %20 or anything else.

 It's probably not the least bit surprising that this works without
 throwing a 404, but of course, does not replace the blank spaces:

   (GET (codec/url-decode /:profile-page) [profile-page]

 Thanks;
 David

 --
 You received this message because you are subscribed to the Google
 Groups Clojure group.
 To post to this group, send email to clojure@googlegroups.com
 Note that posts from new members are moderated - please be patient with
 your first post.
 To unsubscribe from this group, send email to
 clojure+unsubscr...@googlegroups.com
 For more options, visit this group at
 http://groups.google.com/group/clojure?hl=en
 ---
 You received this message because you are subscribed to the Google Groups
 Clojure group.
 To unsubscribe from this group and stop receiving emails from it, send an
 email to clojure+unsubscr...@googlegroups.com.
 For more options, visit https://groups.google.com/d/optout.


-- 
You received this message because you are subscribed to the Google
Groups Clojure group.
To post to this group, send email to clojure@googlegroups.com
Note that posts from new members are moderated - please be patient with your 
first post.
To unsubscribe from this group, send email to
clojure+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/clojure?hl=en
--- 
You received this message because you are subscribed to the Google Groups 
Clojure group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to clojure+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: I'm trying to make proper urls, but I seem to be failing at it.

2014-03-10 Thread David Toomey
You should be able to write:

(GET /:profile-page [profile-page] ...)

Compojure (via Clout) automatically decodes parameters in the URL, so there 
shouldn't be any need to decode the data any further.

Heh, I would have thought something was baked in, but I still get urls with 
nothing filling in the blank-space. 

I'm concerned about XXS, but I'm also irritated because the urls look like 
a drooling idiot created my project. I guess the only option is to disallow 
blank spaces in the user names, but this is pretty disappointing. 

Thanks;
David

-- 
You received this message because you are subscribed to the Google
Groups Clojure group.
To post to this group, send email to clojure@googlegroups.com
Note that posts from new members are moderated - please be patient with your 
first post.
To unsubscribe from this group, send email to
clojure+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/clojure?hl=en
--- 
You received this message because you are subscribed to the Google Groups 
Clojure group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to clojure+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: I'm trying to make proper urls, but I seem to be failing at it.

2014-03-10 Thread Jarrod Swart
This has become super confusing to follow, possibly because you have the 
wrong expectation of compojure?

Compojure is not specificy how your routes will look, it is responding to 
whatever URLs you put in place.

In the case of:

(GET /:profile-page [profile-page] ...)

:profile-page in the route string, becomes profile-page the variable.

So if you make the link: http://myapp.com/some user then profile-page 
will be some user.

If you make the link: http://myapp.com/SomeUser; then profile-page will be 
SomeUser.  The route is simply capturing whatever is sent, not specifying 
or creating anything.  Once you have profile-page you can then modify it as 
you see fit.

When you create the links in your app's template you will specify what URL 
is called, that is when you decide how to display the user's profile name 
in the URL.  

I recommend not having a space, take a look at google+ where my username is 
Jarrod Swart but my profile url is: plus.google.com/+JarrodSwart

Hopefully this helps, or perhaps I misread the thread.

-- 
You received this message because you are subscribed to the Google
Groups Clojure group.
To post to this group, send email to clojure@googlegroups.com
Note that posts from new members are moderated - please be patient with your 
first post.
To unsubscribe from this group, send email to
clojure+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/clojure?hl=en
--- 
You received this message because you are subscribed to the Google Groups 
Clojure group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to clojure+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: I'm trying to make proper urls, but I seem to be failing at it.

2014-03-10 Thread David Toomey


Fair enough. So if I want pretty urls, I have to have an extra column in my 
database then. This is one compromise, but I was hoping for something a 
little more programmatic. 

As a counter to G+, StackOverflow alters the name to lower-case and add a 
'-', so that M User becomes www./m-user.



On Monday, March 10, 2014 9:21:13 PM UTC-7, Jarrod Swart wrote:

 This has become super confusing to follow, possibly because you have the 
 wrong expectation of compojure?

 Compojure is not specificy how your routes will look, it is responding to 
 whatever URLs you put in place.

 In the case of:

 (GET /:profile-page [profile-page] ...)

 :profile-page in the route string, becomes profile-page the variable.

 So if you make the link: http://myapp.com/some user then profile-page 
 will be some user.

 If you make the link: http://myapp.com/SomeUser; then profile-page will 
 be SomeUser.  The route is simply capturing whatever is sent, not 
 specifying or creating anything.  Once you have profile-page you can then 
 modify it as you see fit.

 When you create the links in your app's template you will specify what URL 
 is called, that is when you decide how to display the user's profile name 
 in the URL.  

 I recommend not having a space, take a look at google+ where my username 
 is Jarrod Swart but my profile url is: plus.google.com/+JarrodSwart

 Hopefully this helps, or perhaps I misread the thread.


-- 
You received this message because you are subscribed to the Google
Groups Clojure group.
To post to this group, send email to clojure@googlegroups.com
Note that posts from new members are moderated - please be patient with your 
first post.
To unsubscribe from this group, send email to
clojure+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/clojure?hl=en
--- 
You received this message because you are subscribed to the Google Groups 
Clojure group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to clojure+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: I'm trying to make proper urls, but I seem to be failing at it.

2014-03-10 Thread Jarrod Swart
Right, either way the compojure route would be the same.  (GET 
/:profile-name [profile-name] ...).  

You don't need an extra column in your DB unless you want to do so.

The route/compojure is simply responding to the URL you write out in your 
template, or that is requested by some other mechanism.

The change would be in your template, where you decide how to write out 
those URLs.

(defn make-profile-url [username]
  (let [safe-name (clojure.string/replace username #  -)]
(str / safe-name)))
;; (make-profile-url John Smith) = John-Smith

or

(defn make-profile-url [username]
  (let [safe-name (clojure.string/replace username #  )]
(str / safe-name)))
;; (make-profile-url John Smith) = /JohnSmith

You can do whatever you like best.

Compojure is at the end, receiving the request.  In order for anything to 
happen you need to actually put an anchor on your template any way you 
want, then write the compojure routes to receive them.


-- 
You received this message because you are subscribed to the Google
Groups Clojure group.
To post to this group, send email to clojure@googlegroups.com
Note that posts from new members are moderated - please be patient with your 
first post.
To unsubscribe from this group, send email to
clojure+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/clojure?hl=en
--- 
You received this message because you are subscribed to the Google Groups 
Clojure group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to clojure+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: I'm trying to make proper urls, but I seem to be failing at it.

2014-02-25 Thread Rob Day
What are url-encode and url-decode doing wrong? They look like they
should work (e.g.
https://github.com/ring-clojure/ring-codec/blob/master/test/ring/util/test/codec.clj#L21).

On 25 February 2014 07:14, David Toomey dbtoo...@gmail.com wrote:
 I'm building a site and I would like to allow users to create and account,
 and I would like them to have an option to use whitespaces in their handle.
 Apparently I am doing something way wrong here, so it is possible that I
 messed up something somewhere else.

 When I create a user, for example some user, this user name is inserted
 into a database. The site is set up so that users can have profiles. This
 person's profile would be this:

   www.mysite/some user

 That is bad. I am hoping to have profile pages look like this:

  www.mysite/some%20user

 or:

   www.mysite/some-user

 I attempted to use (url-encode), (url-decode), regex, and all sorts of
 things. Nothing I have tried has worked.

 I'm actually kind of surprised that this isn't baked into Compojure itself,
 but I digress.

 Thanks;

 --
 You received this message because you are subscribed to the Google
 Groups Clojure group.
 To post to this group, send email to clojure@googlegroups.com
 Note that posts from new members are moderated - please be patient with your
 first post.
 To unsubscribe from this group, send email to
 clojure+unsubscr...@googlegroups.com
 For more options, visit this group at
 http://groups.google.com/group/clojure?hl=en
 ---
 You received this message because you are subscribed to the Google Groups
 Clojure group.
 To unsubscribe from this group and stop receiving emails from it, send an
 email to clojure+unsubscr...@googlegroups.com.
 For more options, visit https://groups.google.com/groups/opt_out.



-- 
Robert K. Day
robert@merton.oxon.org

-- 
You received this message because you are subscribed to the Google
Groups Clojure group.
To post to this group, send email to clojure@googlegroups.com
Note that posts from new members are moderated - please be patient with your 
first post.
To unsubscribe from this group, send email to
clojure+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/clojure?hl=en
--- 
You received this message because you are subscribed to the Google Groups 
Clojure group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to clojure+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.


Re: I'm trying to make proper urls, but I seem to be failing at it.

2014-02-25 Thread Dave Della Costa
You can use the default Java classes which are available:

= (- (java.net.URI. http www.mysite /some user nil) .toURL
.toString)
http://www.mysite/some%20user;
=

ring-codec is easy too:

(https://github.com/ring-clojure/ring-codec)

= (str www.mysite/ (ring.util.codec/url-encode some user))
www.mysite/some%20user
=


(2014/02/25 16:14), David Toomey wrote:
 I'm building a site and I would like to allow users to create and
 account, and I would like them to have an option to use whitespaces in
 their handle. Apparently I am doing something way wrong here, so it is
 possible that I messed up something somewhere else.
 
 When I create a user, for example some user, this user name is
 inserted into a database. The site is set up so that users can have
 profiles. This person's profile would be this:
 
   www.mysite/some user
 
 That is bad. I am hoping to have profile pages look like this:
 
  www.mysite/some%20user
 
 or:
 
   www.mysite/some-user
 
 I attempted to use (url-encode), (url-decode), regex, and all sorts of
 things. Nothing I have tried has worked.
 
 I'm actually kind of surprised that this isn't baked into Compojure
 itself, but I digress.
 
 Thanks;
 
 -- 
 You received this message because you are subscribed to the Google
 Groups Clojure group.
 To post to this group, send email to clojure@googlegroups.com
 Note that posts from new members are moderated - please be patient with
 your first post.
 To unsubscribe from this group, send email to
 clojure+unsubscr...@googlegroups.com
 For more options, visit this group at
 http://groups.google.com/group/clojure?hl=en
 ---
 You received this message because you are subscribed to the Google
 Groups Clojure group.
 To unsubscribe from this group and stop receiving emails from it, send
 an email to clojure+unsubscr...@googlegroups.com.
 For more options, visit https://groups.google.com/groups/opt_out.

-- 
You received this message because you are subscribed to the Google
Groups Clojure group.
To post to this group, send email to clojure@googlegroups.com
Note that posts from new members are moderated - please be patient with your 
first post.
To unsubscribe from this group, send email to
clojure+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/clojure?hl=en
--- 
You received this message because you are subscribed to the Google Groups 
Clojure group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to clojure+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.


I'm trying to make proper urls, but I seem to be failing at it.

2014-02-24 Thread David Toomey
I'm building a site and I would like to allow users to create and account, 
and I would like them to have an option to use whitespaces in their handle. 
Apparently I am doing something way wrong here, so it is possible that I 
messed up something somewhere else. 

When I create a user, for example some user, this user name is inserted 
into a database. The site is set up so that users can have profiles. This 
person's profile would be this:

  www.mysite/some user

That is bad. I am hoping to have profile pages look like this: 

 www.mysite/some%20user

or:

  www.mysite/some-user

I attempted to use (url-encode), (url-decode), regex, and all sorts of 
things. Nothing I have tried has worked. 

I'm actually kind of surprised that this isn't baked into Compojure itself, 
but I digress. 

Thanks;

-- 
You received this message because you are subscribed to the Google
Groups Clojure group.
To post to this group, send email to clojure@googlegroups.com
Note that posts from new members are moderated - please be patient with your 
first post.
To unsubscribe from this group, send email to
clojure+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/clojure?hl=en
--- 
You received this message because you are subscribed to the Google Groups 
Clojure group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to clojure+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.