|
@@ -7,7 +7,7 @@
|
|
|
|
|
|
|
|
|
-export([atom/1, q/1, q/2, qc/1, qc/2,
|
|
|
- hte/1, config/3, pickle/1, depickle/1, unique_integer/0, temp_id/0,
|
|
|
+ config/3, pickle/1, depickle/1, unique_integer/0, temp_id/0,
|
|
|
script/0, script/1, actions/0, actions/1, state/1, state/2,
|
|
|
redirect/1, cookie_expire/1, cookie/2, cookie/3, cookies/0, cookie/1,
|
|
|
f/1, f/2, coalesce/1,
|
|
@@ -23,18 +23,16 @@
|
|
|
|
|
|
|
|
|
atom(List) when erlang:is_list(List) ->
|
|
|
- string:join([ nitro:to_list(L) || L <- List], "_");
|
|
|
-atom(Scalar) -> nitro:to_list(Scalar).
|
|
|
+ string:join([ ?MODULE:to_list(L) || L <- List], "_");
|
|
|
+atom(Scalar) -> ?MODULE:to_list(Scalar).
|
|
|
|
|
|
|
|
|
q(Key) -> q(Key, []). %% todo unwrap
|
|
|
q(Key, Def) -> case get(Key) of undefined -> Def; Val -> Val end.
|
|
|
|
|
|
qc(Key) -> CX = get(context), qc(Key,CX#cx.req).
|
|
|
-qc(Key, Req) -> proplists:get_value(nitro:to_binary(Key),cowboy_req:parse_qs(Req)).
|
|
|
+qc(Key, Req) -> proplists:get_value(?MODULE:to_binary(Key),cowboy_req:parse_qs(Req)).
|
|
|
|
|
|
-hte(X) when erlang:is_binary(X) -> nitro:to_binary(html_encode(X));
|
|
|
-hte(X) -> html_encode(X).
|
|
|
config(App, Key, Default) -> application:get_env(App, Key, Default).
|
|
|
%%js_escape(Value) -> nitro_conv:js_escape(Value). %% todo mv to this module
|
|
|
|
|
@@ -86,8 +84,8 @@ to_binary(F) when erlang:is_float(F) -> erlang:float_to_binary(F, [{decimals, 9}
|
|
|
to_binary(L) when erlang:is_list(L) -> erlang:iolist_to_binary(L);
|
|
|
to_binary(X) when erlang:is_tuple(X) -> erlang:term_to_binary(X).
|
|
|
|
|
|
-to_integer(A) when erlang:is_atom(A) -> to_integer(erlang:atom_to_list(A));
|
|
|
-to_integer(B) when erlang:is_binary(B) -> to_integer(erlang:binary_to_list(B));
|
|
|
+to_integer(A) when erlang:is_atom(A) -> ?MODULE:to_integer(erlang:atom_to_list(A));
|
|
|
+to_integer(B) when erlang:is_binary(B) -> ?MODULE:to_integer(erlang:binary_to_list(B));
|
|
|
to_integer(I) when erlang:is_integer(I) -> I;
|
|
|
to_integer([]) -> 0;
|
|
|
to_integer(L) when erlang:is_list(L) -> erlang:list_to_integer(L);
|
|
@@ -162,7 +160,7 @@ wire(Actions) -> action_wire:wire(Actions).
|
|
|
|
|
|
|
|
|
unique_integer() -> erlang:unique_integer().
|
|
|
-temp_id() -> "auto" ++ integer_to_list(unique_integer() rem 1000000).
|
|
|
+temp_id() -> "auto" ++ erlang:integer_to_list(unique_integer() rem 1000000).
|
|
|
|
|
|
|
|
|
%% Fast HEX
|
|
@@ -226,7 +224,7 @@ js_escape(<<>>, Acc) -> Acc.
|
|
|
html_encode(L, Fun) when erlang:is_function(Fun) ->
|
|
|
Fun(L);
|
|
|
html_encode(L, EncType) when erlang:is_atom(L) ->
|
|
|
- html_encode(nitro:to_list(L), EncType);
|
|
|
+ html_encode(?MODULE:to_list(L), EncType);
|
|
|
html_encode(L, EncType) when erlang:is_integer(L) ->
|
|
|
html_encode(erlang:integer_to_list(L), EncType);
|
|
|
html_encode(L, EncType) when erlang:is_float(L) ->
|
|
@@ -236,14 +234,14 @@ html_encode(L, false) ->
|
|
|
html_encode(L, true) ->
|
|
|
L;
|
|
|
html_encode(L, whites) ->
|
|
|
- html_encode_whites(nitro:to_list(lists:flatten([L]))).
|
|
|
+ html_encode_whites(?MODULE:to_list(lists:flatten([L]))).
|
|
|
|
|
|
html_encode(<<>>) ->
|
|
|
[];
|
|
|
html_encode([]) ->
|
|
|
[];
|
|
|
html_encode(B) when is_binary(B) ->
|
|
|
- nitro:to_binary(
|
|
|
+ ?MODULE:to_binary(
|
|
|
html_encode(erlang:binary_to_list(B))
|
|
|
);
|
|
|
html_encode([$\n |T]) ->
|
|
@@ -259,7 +257,7 @@ html_encode([H|T]) ->
|
|
|
BigNum when erlang:is_integer(BigNum) andalso BigNum > 255 ->
|
|
|
%% Any integers above 255 are converted to their HTML encode equivalent
|
|
|
%% Example: 7534 gets turned into ᵮ
|
|
|
- [$&, $# | nitro:to_list(BigNum)] ++ ";" ++ html_encode(T);
|
|
|
+ [$&, $# | ?MODULE:to_list(BigNum)] ++ ";" ++ html_encode(T);
|
|
|
Tup when erlang:is_tuple(Tup) ->
|
|
|
erlang:throw({html_encode, encountered_tuple, Tup});
|
|
|
_ ->
|
|
@@ -403,11 +401,11 @@ insert_bottom(Target, Elements) ->
|
|
|
|
|
|
|
|
|
clear(Target) ->
|
|
|
- nitro:wire("var x = qi('" ++ nitro:to_list(Target) ++ "');"
|
|
|
+ nitro:wire("var x = qi('" ++ ?MODULE:to_list(Target) ++ "');"
|
|
|
"while(x && x.firstChild) x.removeChild(x.firstChild);").
|
|
|
|
|
|
remove(Target) ->
|
|
|
- nitro:wire("var x = qi('" ++ nitro:to_list(Target) ++ "');"
|
|
|
+ nitro:wire("var x = qi('" ++ ?MODULE:to_list(Target) ++ "');"
|
|
|
"x && x.parentNode.removeChild(x);").
|
|
|
|
|
|
|
|
@@ -424,16 +422,16 @@ redirect(Url) -> nitro:wire(#jq{target = 'window', property = location, args = s
|
|
|
|
|
|
|
|
|
setAttr(Element, Attr, Value) ->
|
|
|
- nitro:wire("{ var x = qi('" ++ nitro:to_list(Element) ++ "');"
|
|
|
- "if(x) x.setAttribute('" ++ nitro:to_list(Attr) ++ "', '" ++ nitro:to_list(Value) ++ "'); }").
|
|
|
+ nitro:wire("{ var x = qi('" ++ ?MODULE:to_list(Element) ++ "');"
|
|
|
+ "if(x) x.setAttribute('" ++ ?MODULE:to_list(Attr) ++ "', '" ++ ?MODULE:to_list(Value) ++ "'); }").
|
|
|
|
|
|
|
|
|
style(Element, Style) ->
|
|
|
setAttr(Element, "style", Style).
|
|
|
|
|
|
style(Element, Style, Value) ->
|
|
|
- nitro:wire("{ var x = qi('" ++ nitro:to_list(Element) ++ "');"
|
|
|
- "if(x) x.style." ++ nitro:to_list(Style) ++ " = '" ++ nitro:to_list(Value) ++ "'; }").
|
|
|
+ nitro:wire("{ var x = qi('" ++ ?MODULE:to_list(Element) ++ "');"
|
|
|
+ "if(x) x.style." ++ ?MODULE:to_list(Style) ++ " = '" ++ ?MODULE:to_list(Value) ++ "'; }").
|
|
|
|
|
|
|
|
|
display(Element, Status) -> style(Element, "display", Status).
|
|
@@ -455,7 +453,7 @@ compact(Tuple) when erlang:is_tuple(Tuple) ->
|
|
|
lists:sublist(erlang:tuple_to_list(Tuple), 1, Min)),
|
|
|
"{" ++ string:join([ io_lib:format("~s", [compact(F)]) || {_, F} <- Fields ], ",") ++ "}";
|
|
|
compact(T) ->
|
|
|
- nitro:js_escape(nitro:to_list(T)).
|
|
|
+ nitro:js_escape(?MODULE:to_list(T)).
|
|
|
|
|
|
|
|
|
meg(X) -> erlang:integer_to_list(X div 1000000) ++ "M".
|
|
@@ -476,7 +474,7 @@ cookie_expire(SecondsToLive) ->
|
|
|
cookie(Id, Value) -> cookie(Id, Value, 2147483647). %% expire never
|
|
|
cookie(Id, Value, Expire) ->
|
|
|
Format = "document.cookie='~s=~s; path=/; expires=~s';",
|
|
|
- nitro:wire(nitro:f(Format, [nitro:to_list(Id), nitro:to_list(Value), cookie_expire(Expire)])).
|
|
|
+ nitro:wire(?MODULE:f(Format, [?MODULE:to_list(Id), ?MODULE:to_list(Value), cookie_expire(Expire)])).
|
|
|
|
|
|
cookies() -> cowboy_req:parse_cookies((erlang:get(context))#cx.req).
|
|
|
|