I would also like a function without A, because A is not always 
available (especially in the views). Most of the time (especially in the 
production environment) a "/module/function/params" url is more than enough

> I like this functionality. I tend to hardcode my urls as strings in
> the view templates, but this is a better solution because it lets you
> change your URL scheme later without modifying a bunch of templates.
> This could be very useful in making your URLs work both in and out of
> Facebook, which annoyingly prepends all relative urls with
> /[app-name]/.
>
> A comment: if you create the url so it can be sent through a socket as
> an iolist, this line is inefficient:
>
> lists:flatten(base(A) ++ "/" ++ MStr ++ "/" ++ FStr ++ PStr).
>
> I would rewrite it as
>
> [base(A), $/, MStr, $/, Fstr, Pstr].
>
> Yariv
>
> On Jan 28, 2008 3:22 PM, jm <[EMAIL PROTECTED]> wrote:
>   
>> make_url/4 calculates a URL with out the protocol://host:port/ prefix it
>> returns the form /base/module/function/params given a yaws arg record A,
>> a module name M, a function name F, and a list of parameters Params.
>> There may be errors in this code as it was copy and pasted from else
>> where and modififed here. It may also be be possible to get rid of one
>> of the reverses or make other optimisations. Consider this a first cut.
>>
>> Todo: find protocol, host, and port used by client and include in url
>>        add when-clauses to function
>>
>> Jeff.
>> ------
>>
>> base(A) ->
>>      L = length(yaws_arg:appmoddata(A)),
>>      lists:reverse(lists:nthtail(L,lists:reverse(yaws_arg:server_path(A)))).
>>
>> make_url(A, M, F, Params) ->
>>      PStr = lists:foldl(fun(P, Acc) ->
>>                                 PL = erlydb_base:field_to_iolist(P),
>>                                 [["/" |  PL] | Acc]
>>                         end,
>>                         [],
>>                         lists:reverse(Params)),
>>      io:format("PStr ~p~n", [PStr]),
>>      MStr = erlydb_base:field_to_iolist(M),
>>      FStr = erlydb_base:field_to_iolist(F),
>>      lists:flatten(base(A) ++ "/" ++ MStr ++ "/" ++ FStr ++ PStr).
>>
>>
>> test_make_url() ->
>>    make_url(A, module, function, [1,2,3]).
>>
>>     
>
> >
>
>   


--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"erlyweb" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/erlyweb?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to