221V 1 год назад
Родитель
Сommit
5ae6d26a65
5 измененных файлов с 22 добавлено и 128 удалено
  1. 1 0
      CHANGELOG.md
  2. 1 1
      src/elements/interactive/element_upload.erl
  3. 19 21
      src/nitro.erl
  4. 0 105
      src/nitro_conv.erl
  5. 1 1
      src/nitro_n2o.erl

+ 1 - 0
CHANGELOG.md

@@ -4,6 +4,7 @@
 
 ##### next version
 * unwrap nitro:jse -> nitro:js_escape  
+* unwrap nitro:hte -> nitro:html_encode  
 
 ##### 6.6.1-erl19
 * update to 6.6.1 tag by [@5HT Maksym Sokhatskyi/Namdak Tönpa](https://github.com/5HT)  

+ 1 - 1
src/elements/interactive/element_upload.erl

@@ -19,7 +19,7 @@ render_element(#upload{id=Id}) ->
   
   wf:wire("ftp_file=undefined;"),
   %% wf:wire( #bind{target = Control, type = Event, postback = Code} )
-  wf:wire( #bind{target = ftp_open, type = click, postback = wf:f("qi('~s').click();event.preventDefault();", [ wf:to_list(Uid) ] ) } ),
+  wf:wire( #bind{target = ftp_open, type = click, postback = wf:f("qi('~s').click();event.preventDefault();", [ nitro:to_list(Uid) ] ) } ),
   wf:wire( #bind{target = ftp_start, type = click, postback = "ftp.start(ftp_file);"} ),
   wf:wire( #bind{target = ftp_stop, type = click, postback = "ftp.stop(ftp_file);"} ),
   wf:wire( #bind{target = nitro:to_atom(Uid), type = change, postback = "ftp_file=ftp.init(this.files[0]);"} ),

+ 19 - 21
src/nitro.erl

@@ -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 &#7534;
-      [$&, $# | 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).
 

+ 0 - 105
src/nitro_conv.erl

@@ -6,111 +6,6 @@
 -compile(export_all).
 -include_lib("nitro/include/nitro.hrl").
 
-% WF to_list to_atom to_binary to_integer
-
--define(IS_STRING(Term),
-  (erlang:is_list(Term) andalso Term /= [] andalso erlang:is_integer(hd(Term)))).
-
--ifndef(N2O_JSON).
--define(N2O_JSON, (application:get_env(n2o,json,jsone))).
--endif.
-
-
-to_list(L) when ?IS_STRING(L) -> L;
-to_list(L) when erlang:is_list(L) ->
-  SubLists = [inner_to_list(X) || X <- L],
-  lists:flatten(SubLists);
-to_list(A) -> inner_to_list(A).
-
-inner_to_list(A) when erlang:is_atom(A) -> erlang:atom_to_list(A);
-inner_to_list(B) when erlang:is_binary(B) -> erlang:binary_to_list(B);
-inner_to_list(I) when erlang:is_integer(I) -> erlang:integer_to_list(I);
-inner_to_list(L) when erlang:is_tuple(L) -> lists:flatten(io_lib:format("~p", [L]));
-inner_to_list(L) when erlang:is_list(L) -> L;
-inner_to_list(F) when erlang:is_float(F) -> erlang:float_to_list(F, [{decimals, 9}, compact]).
-
-to_atom(A) when erlang:is_atom(A) -> A;
-to_atom(B) when erlang:is_binary(B) -> erlang:binary_to_atom(B);
-to_atom(I) when erlang:is_integer(I) -> to_atom(erlang:integer_to_list(I));
-to_atom(F) when erlang:is_float(F) -> to_atom(erlang:float_to_list(F, [{decimals, 9}, compact]));
-to_atom(L) when erlang:is_list(L) -> erlang:list_to_atom(L).
-
-to_binary(A) when erlang:is_atom(A) -> erlang:atom_to_binary(A, latin1);
-to_binary(B) when erlang:is_binary(B) -> B;
-to_binary(I) when erlang:is_integer(I) -> erlang:integer_to_binary(I);
-to_binary(F) when erlang:is_float(F) -> erlang:float_to_binary(F, [{decimals, 9}, compact]);
-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(I) when erlang:is_integer(I) -> I;
-to_integer([]) -> 0;
-to_integer(L) when erlang:is_list(L) -> erlang:list_to_integer(L);
-to_integer(F) when erlang:is_float(F) -> erlang:round(F).
-
-
-%% HTML encode/decode
-
-%% html_encode(B, normal)
-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(L, EncType) when erlang:is_integer(L) ->
-  html_encode(erlang:integer_to_list(L), EncType);
-html_encode(L, EncType) when erlang:is_float(L) ->
-  html_encode(erlang:float_to_list(L, [{decimals, 9}, compact]), EncType);
-html_encode(L, false) ->
-  L;
-html_encode(L, true) ->
-  L;
-html_encode(L, whites) ->
-  html_encode_whites(nitro:to_list(lists:flatten([L]))).
-
-html_encode(<<>>) ->
-  [];
-html_encode([]) ->
-  [];
-html_encode(B) when is_binary(B) ->
-  nitro:to_binary(
-    html_encode(erlang:binary_to_list(B))
-  );
-html_encode([$\n |T]) ->
-  "<br>" ++ html_encode(T);
-html_encode([H|T]) ->
-  case H of
-    $< -> "&lt;" ++ html_encode(T);
-    $> -> "&gt;" ++ html_encode(T);
-    $" -> "&quot;" ++ html_encode(T);
-    $' -> "&#39;" ++ html_encode(T);
-    $& -> "&amp;" ++ html_encode(T);
-    $\\ -> "&#92;" ++ html_encode(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 &#7534;
-      [$&, $# | nitro:to_list(BigNum)] ++ ";" ++ html_encode(T);
-    Tup when erlang:is_tuple(Tup) ->
-      erlang:throw({html_encode, encountered_tuple, Tup});
-    _ ->
-      [H|html_encode(T)]
-  end.
-
-html_encode_whites([]) -> [];
-html_encode_whites([H|T]) ->
-  case H of
-    $\s -> "&nbsp;" ++ html_encode_whites(T);
-    $\t -> "&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;" ++ html_encode_whites(T);
-    $< -> "&lt;" ++ html_encode_whites(T);
-    $> -> "&gt;" ++ html_encode_whites(T);
-    $" -> "&quot;" ++ html_encode_whites(T);
-    $' -> "&#39;" ++ html_encode_whites(T);
-    $& -> "&amp;" ++ html_encode_whites(T);
-    $\n -> "<br>" ++ html_encode_whites(T);
-    $\\ -> "&#92;" ++ html_encode_whites(T);
-    _ -> [H|html_encode_whites(T)]
-  end.
-
 
 %% URL encode/decode
 

+ 1 - 1
src/nitro_n2o.erl

@@ -63,7 +63,7 @@ render_actions(Actions) ->
   First  = nitro:render(Actions),
   Second = nitro:render(nitro:actions()),
   nitro:actions([]),
-  nitro:to_binary([First,Second]).
+  nitro:to_binary([First, Second]).
 
 
 %% n2o events