Skip to content

Commit

Permalink
yaws_api: Allow binary attribute values in ehtml
Browse files Browse the repository at this point in the history
Binary attribute values are already supported in exhtml.
  • Loading branch information
weisslj committed Aug 25, 2014
1 parent b513bdd commit 49d69b2
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 9 deletions.
2 changes: 1 addition & 1 deletion doc/yaws.tex
Expand Up @@ -524,7 +524,7 @@ \section{EHTML}

$HtmlAttribute = atom()$

$Value = string() | atom() | integer() | float() |\\*
$Value = string() | binary() | atom() | integer() | float() |\\*
\hspace*{0.55 in} \{Module, Fun, [Args]\} | fun/0$

$Body = EHTML$
Expand Down
2 changes: 1 addition & 1 deletion man/yaws_api.5
Expand Up @@ -749,7 +749,7 @@ EHTML = [EHTML] | {Tag, Attrs, Body} | {Tag, Attrs} | {Tag} |
Tag = atom()
Attrs = [{Key, Value}]
Key = atom()
Value = string() | atom() | integer() | float() |
Value = string() | binary() | atom() | integer() | float() |
{Module, Fun, [Args]} | fun/0
Body = EHTML
.fi
Expand Down
10 changes: 9 additions & 1 deletion src/yaws_api.erl
Expand Up @@ -1728,7 +1728,7 @@ is_abs_URI1(_) ->
%% Tag = atom()
%% Attrs = [{Key, Value}]
%% Key = atom()
%% Value = string() | atom() | integer() | float() |
%% Value = string() | binary() | atom() | integer() | float() |
%% {Module, Fun, [Args]} | fun/0
%% Body = EHTML

Expand Down Expand Up @@ -1781,6 +1781,7 @@ ehtml_attrs([{Name, Value} | Tail]) ->
ValueString = [$", if
is_atom(Value) -> atom_to_list(Value);
is_list(Value) -> Value;
is_binary(Value) -> Value;
is_integer(Value) -> integer_to_list(Value);
is_float(Value) -> float_to_list(Value)
end, $"],
Expand All @@ -1794,6 +1795,7 @@ ehtml_attrs([{check, Name, Value} | Tail]) ->
Val = if
is_atom(Value) -> atom_to_list(Value);
is_list(Value) -> Value;
is_binary(Value) -> Value;
is_integer(Value) -> integer_to_list(Value);
is_float(Value) -> float_to_list(Value)
end,
Expand Down Expand Up @@ -2119,6 +2121,12 @@ deepmember(C,[L|Cs]) when is_list(L) ->
false -> deepmember(C,Cs)
end;
deepmember(C,[N|Cs]) when C /= N ->
deepmember(C, Cs);
deepmember(_C,<<>>) ->
false;
deepmember(C, <<C,_Cs/binary>>) ->
true;
deepmember(C, <<_,Cs/binary>>) ->
deepmember(C, Cs).


Expand Down
15 changes: 9 additions & 6 deletions test/eunit/ehtml_test.erl
Expand Up @@ -22,12 +22,15 @@ non_void_element_test() ->
P = lists:flatten(yaws_api:ehtml_expand(E)).

attributes_test() ->
{ehtml, E} = {ehtml, [{img, [{check, src, "quote\".png"},
{check, width, 10},
{height, 20},
{check, alt, "quote\""}]}]},
Img = "<img src='quote\".png' width=\"10\" height=\"20\" alt='quote\"' />",
Img = lists:flatten(yaws_api:ehtml_expand(E)).
{ehtml, E1} = {ehtml, [{img, [{check, src, <<"quote\".png">>},
{check, width, 10},
{height, 20},
{check, alt, "quote\""}]}]},
Img = <<"<img src='quote\".png' width=\"10\" height=\"20\" alt='quote\"' />">>,
Img = iolist_to_binary(yaws_api:ehtml_expand(E1)),
{ehtml, E2} = {ehtml, [{a, [{href, <<"test">>}], <<"test link">>}]},
A = <<"<a href=\"test\">test link</a>">>,
A = iolist_to_binary(yaws_api:ehtml_expand(E2)).

get_title() ->
"Funtest Title".
Expand Down

0 comments on commit 49d69b2

Please sign in to comment.