Skip to content

Commit

Permalink
Gravatar: support linking to site other than http://gravatar.com/
Browse files Browse the repository at this point in the history
  • Loading branch information
ngocdaothanh committed Jul 19, 2009
1 parent 847c000 commit b30831c
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 2 deletions.
6 changes: 5 additions & 1 deletion src/ale.erl
Original file line number Diff line number Diff line change
Expand Up @@ -59,5 +59,9 @@ flash() -> ale_session:flash().
%-------------------------------------------------------------------------------

ff(Basename, Data) -> ale_utils:ff(Basename, Data).

md5_hex(Module, Data) -> ale_utils:md5_hex(Module, Data).
gravatar(Email, Size) -> ale_utils:gravatar(Email, Size).

gravatar(Email) -> ale_utils:gravatar(Email).
gravatar(Email, Size) -> ale_utils:gravatar(Email, Size).
gravatar(Email, Size, Url) -> ale_utils:gravatar(Email, Size, Url).
10 changes: 9 additions & 1 deletion src/ale_utils.erl
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@

-include("ale.hrl").

-define(DEFAULT_GRAVATAR_SIZE, 80).

%% Scans the project directory to find the first file with Basename, then reads
%% the file and apply io_lib:format/2. This function can be used to render
%% JavaScript template file.
Expand Down Expand Up @@ -43,10 +45,16 @@ md5_hex(Module, Data) ->
Md5 = Module:md5(Data),
lists:flatten([io_lib:format("~2.16.0b", [N]) || N <- binary_to_list(Md5)]).

gravatar(Email) ->
gravatar(Email, ?DEFAULT_GRAVATAR_SIZE).

gravatar(Email, Size) ->
gravatar(Email, Size, "http://gravatar.com").

gravatar(Email, Size, Url) ->
GravatarId = case Email of
undefined -> "";
_ -> md5_hex(erlang, Email)
end,
Src = io_lib:format("http://www.gravatar.com/avatar.php?size=~p&gravatar_id=~s", [Size, GravatarId]),
{a, [{href, "http://gravatar.com"}], {img, [{src, Src}]}}.
{a, [{href, Url}], {img, [{src, Src}]}}.

0 comments on commit b30831c

Please sign in to comment.