Skip to content

Commit

Permalink
Give binary() instead of string() to Yaws.
Browse files Browse the repository at this point in the history
  • Loading branch information
Ummon committed Jul 14, 2016
1 parent 76459ac commit 504a9a2
Show file tree
Hide file tree
Showing 6 changed files with 41 additions and 33 deletions.
4 changes: 4 additions & 0 deletions js/jquery-1.7.2.min.js

Large diffs are not rendered by default.

37 changes: 20 additions & 17 deletions modules/erl/d_lan_common.erl
@@ -1,10 +1,10 @@
-module(d_lan_common).
-export([get_data/1, current_page/1, page_name/2, menu/1, image/2, image/3, images/1, download_button/2, send_release/3]).
-export([t/1, get_data/1, current_page/1, page_name/2, menu/1, image/2, image/3, images/1, download_button/2, send_release/3]).

-import(d_lan_lang, [tr/3, tr/4]).
-import(lists, [member/2, map/2, last/1, sort/1]).
-include("/usr/lib/yaws/include/yaws_api.hrl").

-include("/usr/lib/yaws/include/yaws_api.hrl").
-include("../include/d_lan_defines.hrl").

-define(MAIN_PAGE, "yssi/main.yaws").
Expand All @@ -22,7 +22,10 @@ pages() ->

hidden_pages() ->
[stats, donate].


t(Text) ->
unicode:characters_to_binary(Text).

get_data(A) ->
% We ignore the page.
case yaws_api:parse_query(A) of
Expand All @@ -35,16 +38,16 @@ get_data(A) ->
yaws_api:setcookie("lang", Lang, "/"),
{yssi, ?MAIN_PAGE}
];
_ ->
{yssi, ?MAIN_PAGE}
_ ->
{yssi, ?MAIN_PAGE}
end.

% Return the current page depending the page parameters.
current_page(A) ->
case yaws_api:queryvar(A, "p") of
{ok, PageStr} ->
try list_to_existing_atom(PageStr) of
Page ->
Page ->
case member(Page, pages() ++ hidden_pages()) of
true -> Page;
_ -> unknown
Expand All @@ -54,7 +57,7 @@ current_page(A) ->
end;
_ -> home
end.

page_name(A, P) -> tr(menu, P, A).

menu(A) ->
Expand All @@ -75,23 +78,23 @@ image(Filename, Caption, Comment) ->
{'div', [{class, "box gallery"}],
[
{a, [{href, "img/gallery/" ++ Filename ++ ".png"}, {rel, "group"}, {title, Comment}],
"<img src = \"img/gallery/" ++ Filename ++ "_thumb.png\" alt=\"" ++ Caption ++ "\" />"
["<img src = \"img/gallery/", Filename, "_thumb.png\" alt=\"", Caption, "\" />"]
},
{p, [], Caption}
]
}.

images(Filename_caption_list) ->
map(
fun
({Filename, Caption}) ->
({Filename, Caption}) ->
image(Filename, Caption);
({Filename, Caption, Comment}) ->
image(Filename, Caption, Comment)
end,
Filename_caption_list
).

% 'Platform' is a folder where the releases are put.
% For example: "windows".
download_button(A, Platform) ->
Expand All @@ -104,24 +107,24 @@ download_button(A, Platform) ->
{match, [Version, Version_tag, Year, Month, Day, Archi]} =
case Extension of
"deb" ->
re:run(Filename, "D-LAN-((?:\\d|\\.)+)([^-]*)-(\\d+)-(\\d+)-(\\d+)_.*-(\\w+)\\..*", [{capture, all_but_first, list}]);
re:run(Filename, "D-LAN-((?:\\d|\\.)+)([^-]*)-(\\d+)-(\\d+)-(\\d+)_.*-(\\w+)\\..*", [{capture, all_but_first, list}]);
_ ->
{match, Values} = re:run(Filename, "D-LAN-((?:\\d|\\.)+)([^-]*)-(\\d+)-(\\d+)-(\\d+).*\\..*", [{capture, all_but_first, list}]),
{match, Values ++ ["win32"]}
end,
File_size = filelib:file_size(Relase_platform_folder ++ "/" ++ Filename),
File_size_mb = float(File_size) / 1048576,
{'div', [{class, "download" ++ " " ++ Extension ++ " " ++ Archi}],
[{a, [{class, "installer"}, {href, file_to_url(A, Filename, Platform)}],
[{a, [{class, "installer"}, {href, file_to_url(A, Filename, Platform)}],
[
{em, [], [tr(download_button, download, A) ++ " (" ++ io_lib:format("~.2f", [File_size_mb]) ++ " MiB)"]}, {br},
{em, [], [tr(download_button, download, A), " (", io_lib:format("~.2f", [File_size_mb]), " MiB)"]}, {br},
tr(download_button, version, A,
[Version ++ if Version_tag =/= [] -> " " ++ Version_tag; true -> [] end, Platform_formatted]
), {br},
tr(download_button, released, A, [httpd_util:month(list_to_integer(Month)) ++ " " ++ Day ++ " " ++ Year])
%"Number of download : " ++ integer_to_list(d_lan_download_db(Filename))
]
}]
}]
++ % Add a link to the torrent file if it exists.
case lists:reverse(sort([F || F <- Filenames, string:right(F, 8) =:= ".torrent"])) of
[Torrent_file | _] ->
Expand Down
13 changes: 7 additions & 6 deletions modules/erl/d_lan_lang.erl
@@ -1,22 +1,24 @@
-module(d_lan_lang).
-export([langs/0, plain_lang/1, current_lang/1, tr/3, tr/4]).

-import(d_lan_common, [t/1]).

-include("/usr/lib/yaws/include/yaws_api.hrl").
-include("../include/d_lan_defines.hrl").

-spec langs() -> atom().
-spec plain_lang(atom()) -> string().
-spec current_lang(#arg{}) -> atom().
-spec tr(atom(), atom(), #arg{}) -> string().
-spec tr(atom(), atom(), #arg{}, [term()]) -> string().
-spec tr(atom(), atom(), #arg{}) -> binary().
-spec tr(atom(), atom(), #arg{}, [term()]) -> binary().

% See here for the language codes : http://en.wikipedia.org/wiki/List_of_ISO_639-1_codes
% Return a list of all accepted languages.
langs() ->
[en, fr].

plain_lang(en) -> "English";
plain_lang(fr) -> "Français".
plain_lang(en) -> t("English");
plain_lang(fr) -> t("Français").

%%%%%%%%%%

Expand Down Expand Up @@ -365,5 +367,4 @@ tr(Page, Section, A) ->
tr(Page, Section, A, []).

tr(Page, Section, A, Params) ->
io_lib:format(translate(current_lang(A), Page, Section), Params).

t(io_lib:format(translate(current_lang(A), Page, Section), Params)).
2 changes: 1 addition & 1 deletion yaws_conf/yaws.conf
Expand Up @@ -7,4 +7,4 @@ max_size_cached_file = 200000
cache_refresh_secs = 0
pick_first_virthost_on_nomatch = true

subconfig = yaws_conf/localhost.conf
subconfig = localhost.conf
6 changes: 3 additions & 3 deletions yssi/about.yaws
@@ -1,6 +1,6 @@
<erl>
-import(d_lan_lang, [tr/3, tr/4]).

out(A) ->
{ehtml, [
{a, [{href, "files/D-LAN%20logo.svg"}, {class, "logo"}], {img, [{src, "img/d-lan_logo_128.png"}], []}},
Expand All @@ -14,6 +14,6 @@
{ul, [], tr(about, tech_used_tools, A)},
{h3, [], tr(about, tech_used_website_title, A)},
{ul, [], tr(about, tech_used_website, A)}
]}.
]}.

</erl>
12 changes: 6 additions & 6 deletions yssi/home.yaws
@@ -1,7 +1,7 @@
<erl>
-import(d_lan_lang, [tr/3, tr/4]).
image_of_the_day(A) ->

image_of_the_day(A) ->
case calendar:day_of_the_week(date()) of
1 -> % Monday.
d_lan_common:image("browse", tr(gallery, browse, A), tr(gallery, browse_comment, A));
Expand All @@ -14,11 +14,11 @@
5 -> % Friday.
d_lan_common:image("upload", tr(gallery, upload, A));
_ -> % Week-end.
d_lan_common:image("download_files", tr(gallery, download_files, A), tr(gallery, download_files_comment, A))
d_lan_common:image("download_files", tr(gallery, download_files, A), tr(gallery, download_files_comment, A))
%d_lan_common:image("skin", tr(gallery, skin, A)) % The skin screenshot is terrible...
end.
out(A) ->

out(A) ->
{ehtml,
[
image_of_the_day(A),
Expand All @@ -34,5 +34,5 @@
d_lan_common:download_button(A, "Raspberry Pi"),
{'div', [{class, "spacer"}]}
]
}.
}.
</erl>

0 comments on commit 504a9a2

Please sign in to comment.