ParsePath

60 views
Skip to first unread message

Guillaume Massé

unread,
Jul 15, 2012, 6:18:12 PM7/15/12
to lif...@googlegroups.com
Hi,

I'm really stuck with this rewrite:

==>
Map( 'id' -> '3457yerter' )

What I got so far:
LiftRules.statelessRewrite.append {
case RewriteRequest( ParsePath( "index" :: id :: Nil, "", _, _ ), _, _ ) => 
RewriteResponse( "index", Map( "id" -> id ) )
}

Naftoli Gugenheim

unread,
Jul 15, 2012, 6:20:38 PM7/15/12
to lif...@googlegroups.com
So what's the problem?

Also what about Menu.param?



--
Lift, the simply functional web framework: http://liftweb.net
Code: http://github.com/lift
Discussion: http://groups.google.com/group/liftweb
Stuck? Help us help you: https://www.assembla.com/wiki/show/liftweb/Posting_example_code

Guillaume Massé

unread,
Jul 15, 2012, 9:01:12 PM7/15/12
to lif...@googlegroups.com
it gives me a 404

               LiftRules.statelessRewrite.append {
case RewriteRequest( ParsePath( "index" :: id :: Nil, "", _, _ ), _, _ ) => 
RewriteResponse( "index" :: Nil, Map( "id" -> id ) )
}

it try to match localhost:8080/index/3457yerter but I want it to match localhost:8080/3457yerter

               LiftRules.statelessRewrite.append {
case RewriteRequest( ParsePath( id :: Nil, "", _, _ ), _, _ ) => 
RewriteResponse( Nil, Map( "id" -> id ) )
}

wont work as well

Naftoli Gugenheim

unread,
Jul 15, 2012, 9:03:06 PM7/15/12
to lif...@googlegroups.com


On Sun, Jul 15, 2012 at 9:01 PM, Guillaume Massé <mas...@gmail.com> wrote:
wont work as well


Would you like to tell us what won't work in that case?

Guillaume Massé

unread,
Jul 15, 2012, 9:22:10 PM7/15/12
to lif...@googlegroups.com
also give me a 404

http://localhost:8080/aaaa
The Requested URL /aaaa was not found on this server

Guillaume Massé

unread,
Jul 15, 2012, 9:28:28 PM7/15/12
to lif...@googlegroups.com
and this give an infinite loop:

                 LiftRules.statelessRewrite.append {
case RewriteRequest( ParsePath( id :: Nil, "", _, _ ), _, _ ) => 
RewriteResponse( "index" :: Nil, Map( "id" -> id ) )
}

on any input

Naftoli Gugenheim

unread,
Jul 15, 2012, 9:39:21 PM7/15/12
to lif...@googlegroups.com
Try: case RewriteRequest( ParsePath( id :: Nil, "", _, _ ), _, _ )  if !id.isEmpty => 


Franz Bettag

unread,
Jul 15, 2012, 9:40:38 PM7/15/12
to lif...@googlegroups.com
So you want to catch everything starting at /?

Franz Bettag

unread,
Jul 15, 2012, 9:42:13 PM7/15/12
to lif...@googlegroups.com
Or use naftoli's :) his is prolly easier to understand

Guillaume Massé

unread,
Jul 15, 2012, 10:06:48 PM7/15/12
to lif...@googlegroups.com
hey guys,

thanks for the help,

it's not an uriNotFound catch all, it's a link to a ressource. I'm building something similar to jsfiddle for scala ( see : https://groups.google.com/forum/?fromgroups#!topic/liftweb/C4GOz8bMe5g )

so it would be something like: 

sca.la/3529342 where 3529342 is the id for some scala ressource someone wrote.

case RewriteRequest( ParsePath( id :: Nil, "", _, _ ), _, _ ) if !id.isEmpty => 
     RewriteResponse( "index" :: Nil, Map( "id" -> id ) )

wont work as well, some infinite loop also.

Guillaume

Naftoli Gugenheim

unread,
Jul 15, 2012, 10:07:45 PM7/15/12
to lif...@googlegroups.com
Just use Menu.param.


Guillaume Massé

unread,
Jul 15, 2012, 10:32:40 PM7/15/12
to lif...@googlegroups.com

Guillaume Massé

unread,
Jul 15, 2012, 11:33:08 PM7/15/12
to lif...@googlegroups.com
In that case Menu.Param wont work because you have to match the right template (index.html in my case).

ex:

Boot.scala
val sitemap = List( Menu( Kata.loc ) )
LiftRules.setSiteMap(SiteMap(sitemap:_*))

Kata.scala
case class KataRessource( id: String )
object Kata
{
val menu = Menu.param[KataRessource](
"Kata","Kata",
id => Full(KataRessource(id)),
kata => kata.id
) / "kata"     // << this will match kata.html
lazy val loc = menu.toLoc

val menu2 = Menu.param[KataRessource](
"Kata","Kata",
id => Full(KataRessource(id)),
kata => kata.id
) / ""     // << this will match ???
lazy val loc2 = menu2.toLoc
}

Naftoli Gugenheim

unread,
Jul 15, 2012, 11:57:57 PM7/15/12
to lif...@googlegroups.com
There are LocParams that let calculate the template. I'm not able to access the specifics at the moment but hopefully that will point you in the right direction.

Guillaume Massé

unread,
Jul 16, 2012, 1:18:44 AM7/16/12
to lif...@googlegroups.com
Hey,

I found the template resolving you were talking about:

object Kata
{
val menu = Menu.param[KataRessource](
"Kata", "Kata", 
      id => Full( KataRessource(id) ), 
      kata => kata.id ) / * >> 
Template( () =>
Templates( "kata" :: Nil ) openOr <b>template not found</b>
)

lazy val loc = menu.toLoc
}

notice the * catch all

notice that http://localhost:8080/ will have id "index"

Thanks again :-)

Guillaume

Antonio Salazar Cardozo

unread,
Jul 16, 2012, 10:13:49 AM7/16/12
to lif...@googlegroups.com
Yeah for what it's worth the RewriteRequest case match above needed to check whether id was == to "index" to avoid an infinite loop.

SiteMap is the way to go though :)
Thanks,
Antonio

Tobias Pfeiffer

unread,
Jul 16, 2012, 1:38:04 PM7/16/12
to lif...@googlegroups.com
Hi,

Am Montag, 16. Juli 2012, 07:18 schrieb Guillaume Massé:
> object Kata
> {
> val menu = Menu.param[KataRessource](
> "Kata", "Kata",
> id => Full( KataRessource(id) ),
> kata => kata.id ) / * >>
> Template( () =>
> Templates( "kata" :: Nil ) openOr <b>template not found</b>
> )
>
> lazy val loc = menu.toLoc
> }
>
> notice the * catch all

Will that catchall still allow you to serve other objects at, say,
/index or /help/xyz or will all of them be served by your Menu.param? Or
would you need separate RewriteRules for those cases?

Thanks
Tobias

David Pollak

unread,
Jul 16, 2012, 1:46:57 PM7/16/12
to lif...@googlegroups.com
The key thing about Menu.param is the function that takes the parameter and converts it into a typed value... in this case:
id => Full( KataRessource(id) 

If the function does not return a Full() Box, then the menu is not matched and other menus will be tested.

So, if the function is:

id => KataResource.find(id)

Will match existing KataResources but will not match the likes of "index" or "wombat".

Thanks,

David
 

Thanks
Tobias

--
Lift, the simply functional web framework: http://liftweb.net
Code: http://github.com/lift
Discussion: http://groups.google.com/group/liftweb
Stuck? Help us help you: https://www.assembla.com/wiki/show/liftweb/Posting_example_code



--
Telegram, Simply Beautiful CMS https://telegr.am
Lift, the simply functional web framework http://liftweb.net


Tobias Pfeiffer

unread,
Jul 16, 2012, 1:53:43 PM7/16/12
to lif...@googlegroups.com
Hi David,

Am Montag, 16. Juli 2012, 19:46 schrieb David Pollak:
> The key thing about Menu.param is the function that takes the
> parameter and converts it into a typed value... in this case:
> id => Full( KataRessource(id)
>
> If the function does not return a Full() Box, then the menu is not
> matched and other menus will be tested.
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

That's a valuable piece of information, thanks! I assumed it would just
return 404 if there's no match.

Thanks,
Tobias

Guillaume Massé

unread,
Jul 16, 2012, 3:48:59 PM7/16/12
to lif...@googlegroups.com
Hum I was hoping for the other way around:

look the sitemap if we find something useful and then fallback on the catchall.

Thanks,
Guillaume
Reply all
Reply to author
Forward
0 new messages