nitro.htm 8.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187
  1. <html>
  2. <head>
  3. <meta charset="utf-8" />
  4. <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
  5. <meta name="viewport" content="width=device-width, initial-scale=1.0" />
  6. <meta name="description" content="" />
  7. <meta name="author" content="Maxim Sokhatsky" />
  8. <title>NITRO</title>
  9. <link rel="stylesheet" href="https://n2o.dev/blank.css" />
  10. <link rel="stylesheet" href="https://n2o.dev/zima.css" />
  11. </head>
  12. <body>
  13. <nav>
  14. <a href="https://n2o.dev">DEV</a>
  15. <a href="https://nitro.n2o.space">NITRO</a>
  16. <a href="#" style="background:#ededed;">API</a>
  17. <div class="dropdown">
  18. <a onclick="drop()" class="dropbtn">EN</a>
  19. <div id="dropdown" class="dropdown-content">
  20. <a href="https://n2o.dev/deps/nitro/man/ua/nitro.htm">UA</a>
  21. <a href="#">EN</a>
  22. </div>
  23. </div>
  24. </nav>
  25. <header>
  26. <a href="../index.html"><img src="https://n2o.space/img/Synrc Neo.svg" /></a>
  27. <h1>NITRO</h1>
  28. </header>
  29. <main>
  30. <section>
  31. <h3>INTRO</h3>
  32. <p>The refined SYNRC API of the Nitrogen Web Framework brought to us by Rusty Klophaus.</p>
  33. </section>
  34. <section>
  35. <h3>API</h3>
  36. <p>The basic Rusty's idea was to stream small pieces of JavaScript
  37. to the thin client that performs simple <b>eval</b>. This is
  38. server side rendering framework with SDK for creating rich and complex
  39. control elements such as virtual grid or file upload element.</p>
  40. <a name="q"></a>
  41. <h4>q(atom()) -> term().</h4>
  42. <p>Retrieves from process dictionary by atom-key the value of client DOM element
  43. passed by over the network in <b>#ev</b> record as a part of <b>#pickle</b> message.</p>
  44. <figure><code> event(click) -> io:format("~p~n",[nitro:q(:name)]);</code></figure>
  45. <a name="jse"></a>
  46. <h4>jse([] | binary()) -> [] | binary().</h4>
  47. <p>Performs JavaScript escaping that is safe to eval and <b>&lt;script&gt;</b> injection. See more about
  48. <a href="https://cheatsheetseries.owasp.org/cheatsheets/Cross_Site_Scripting_Prevention_Cheat_Sheet.html">XSS</a>.</p>
  49. <figure><code> > nitro:jse(&lt;&lt;"Ім'я"/utf8&gt;&gt;).
  50. &lt;&lt;"Ім\\'я"/utf8&gt;&gt;</code></figure>
  51. <a name="hte"></a>
  52. <h4>hte([] | binary()) -> [] | binary().</h4>
  53. <p>Performs HTML escaping that is safe to display as a text on a page.</p>
  54. <figure><code> > nitro:hte(&lt;&lt;"<a></a>"&gt;&gt;).
  55. "&#38;lt;a&#38;gt;&lt;/a&#38;gt;"</code></figure>
  56. <a name="wire"></a>
  57. <h4>wire(list(#action{})) -> [].</h4>
  58. <p>Updates the process dictionary <b>actions</b> variable with the new list of records inhereted from <b>#action</b>.
  59. This process dictionary variable is a way data is passed from your <b>event</b> handlers into the output rendering pipeline.
  60. This is fixed by Nitrogen Web Framework API.</p>
  61. <figure><code> > nitro:wire([#alert{text="hello"}]).
  62. []
  63. > get(actions).
  64. [#wire{ancestor = action,
  65. trigger = [],
  66. target = [],
  67. module = action_wire,
  68. actions = [#alert{ancestor = action,
  69. trigger = [],
  70. target = [],
  71. module = action_alert,
  72. actions = [],
  73. source = [],
  74. text = "hello"}],
  75. source = []}]</code></figure>
  76. <a name="render"></a>
  77. <h4>render(list(#action{} | #element{})) -> binary().</h4>
  78. <p>Renders HTML5 binary string by the record inhereted from <b>#element</b>.</p>
  79. <figure><code> > rr(nitro).
  80. [abbr,action,address,alert,api,area,article,aside,audio,
  81. author,b,base,bdi,bdo,bind,blockquote,body,br,button,
  82. calendar,canvas,caption,checkbox,cite,code,col,colgroup,
  83. color,command|...]
  84. &gt; #element{}.
  85. #element{ancestor = element,id = [],module = undefined,
  86. delegate = [],validation = [],validate = [],actions = [],
  87. class = [],style = [],source = [],onmouseover = [],
  88. onkeypress = [],onchange = [],onkeyup = [],onkeydown = [],
  89. onclick = [],data_fields = [],aria_states = [],body = [],
  90. role = [],tabindex = [],show_if = true,html_tag = [],
  91. title = [],postback = [],accesskey = [],
  92. contenteditable = [],contextmenu = [],...}
  93. &lt; nitro:render(#alert{text="hello"}).
  94. ["alert(\"","hello","\");"]
  95. &gt; nitro:render(#element{}).
  96. [&lt;&lt;"&lt;"&gt;&gt;,&lt;&lt;"element"&gt;&gt;,
  97. [[],[],[],[],[],[],[],[],[],[],[],[],[],[],[],[]],
  98. &lt;&lt;"&gt;"&gt;&gt;,&lt;&lt;&gt;&gt;,&lt;&lt;"&lt;/"&gt;&gt;,&lt;&lt;"element"&gt;&gt;,&lt;&lt;"&gt;"&gt;&gt;]
  99. &gt; iolist_to_binary(nitro:render(#element{})).
  100. &lt;&lt;"&lt;element&gt;&lt;/element&gt;"&gt;&gt;
  101. &gt; iolist_to_binary(nitro:render(setelement(1,#element{},tag))).
  102. &lt;&lt;"&lt;tag&gt;&lt;/tag&gt;"&gt;&gt;</code></figure>
  103. <a name="insert_top"></a>
  104. <h4>insert_top(atom(), list(#element{})) -> [].</h4>
  105. <p>Wires a JavaScript for adding the NITRO element as a first child of a given DOM id at the client.</p>
  106. <figure><code> > nitro:insert_top(panel,#button{}).
  107. []
  108. > nitro:actions().
  109. [#wire{ancestor = action,trigger = [],target = [],
  110. module = action_wire,
  111. actions = "qi('panel').insertBefore((function(){var div = qn('div');
  112. div.innerHTML = '&lt;button type=\"button\"&gt;&lt;/button&gt;';
  113. return div.firstChild; })(),qi('panel').firstChild);",
  114. source = []}]
  115. > rp(iolist_to_binary(nitro:render(nitro:actions()))).
  116. &lt;&lt;"qi('panel').insertBefore((function(){var div
  117. = qn('div'); div.innerHTML = '&lt;button type=\"button\"&gt;&lt;/button&gt;';
  118. return div.firstChild; })(),qi('panel').firstChild);"&gt;&gt;
  119. ok</code></figure>
  120. <a name="insert_bottom"></a>
  121. <h4>insert_bottom(atom(), list(#element{})) -> [].</h4>
  122. <p>Wires a JavaScript for adding the NITRO element as a last child of a given DOM id at the client.</p>
  123. <figure><code> > nitro:insert_bottom(panel,#button{}).
  124. > rp(iolist_to_binary(nitro:render(nitro:actions()))).
  125. &lt;&lt;"(function(){ var div = qn('div'); div.innerHTML =
  126. '&lt;button type=\"button\"&gt;&lt;/button&gt;';qi('panel')
  127. .appendChild(div.firstChild); })();"&gt;&gt;
  128. ok</code></figure>
  129. <a name="insert_adjustment"></a>
  130. <h4>insert_adjustment(beforebegin | afterbegin
  131. | beforeend | afterend, atom(), list(#element{})) -> [].</h4>
  132. <p>Wires a JavaScript for different
  133. <a href="https://developer.mozilla.org/en-US/docs/Web/API/Element/insertAdjacentHTML">adjustment</a> modes.</p>
  134. <figure><code> > nitro:insert_adjacent(beforebegin, panel, #button{}).
  135. []
  136. > rp(iolist_to_binary(nitro:render(nitro:actions()))).
  137. &lt;&lt;"qi('panel').insertAdjacentHTML('beforebegin',
  138. '&lt;button type=\"button\"&gt;&lt;/button&gt;');"&gt;&gt;
  139. ok</code></figure>
  140. <a name="update"></a>
  141. <h4>update(atom(), list(#element{})) -> [].</h4>
  142. <p>Wires a JavaScript for updating the DOM element at the client by the render of a given NITRO element.</p>
  143. <figure><code> > nitro:update(panel,#button{}).
  144. []
  145. > rp(iolist_to_binary(nitro:render(nitro:actions()))).
  146. &lt;&lt;"qi('panel').outerHTML='&lt;button type=\"button\"&lt;&gt;/button>';"&gt;&gt;
  147. ok</code></figure>
  148. <a name="clear"></a>
  149. <h4>clear(atom()) -> [].</h4>
  150. <p>Wires a JavaScript that clear at the client all the children of a given DOM element id.</p>
  151. <figure><code> > nitro:clear(panel).
  152. []
  153. > rp(iolist_to_binary(nitro:render(nitro:actions()))).
  154. &lt;&lt;"var x = qi('panel'); while (x.firstChild) x.removeChild(x.firstChild);""&gt;&gt;
  155. ok</code></figure>
  156. <a name="remove"></a>
  157. <h4>remove(atom()) -> [].</h4>
  158. <p>Wires a JavaScript that remove particular DOM element from the tree at the client.</p>
  159. <figure><code> > nitro:remove(panel).
  160. []
  161. > rp(iolist_to_binary(nitro:render(nitro:actions()))).
  162. &lt;&lt;"var x=qi('panel'); x && x.parentNode.removeChild(x);"&gt;&gt;
  163. ok</code></figure>
  164. <a name="display"></a>
  165. <h4>display(atom(),atom()) -> [].</h4>
  166. <p>Wires a JavaScript that remove particular DOM element from the tree at the client.</p>
  167. <figure><code> > nitro:display(panel,none).
  168. []
  169. > rp(iolist_to_binary(nitro:render(nitro:actions()))).
  170. &lt;&lt;"{ var x = qi('panel'); if (x) x.style.display = 'none'; }"&gt;&gt;
  171. ok</code></figure>
  172. <p>Wires a JavaScript that manipulate <b>style</b> field of a given DOM element.</p>
  173. <a name="compact"></a>
  174. <h4>compact(term()) -> binary().</h4>
  175. <p>Pretty-prints the term into more compact format to display by a recursive cut
  176. the tuples with no more that 9 elements width.</p>
  177. <figure><code> &gt; iolist_to_binary(nitro:compact({1,2,3,4,5,{1,2,3,4},7,8,9,10,11})).
  178. &lt;&lt;"{1,2,3,4,5,{1,2,3,4},7,8,9}"&gt;&gt;</code>
  179. <br/>
  180. <br/>
  181. </section>
  182. </main>
  183. <footer> 2005—2019 © Synrc Research Center </footer>
  184. <script>function drop(){document.getElementById("dropdown").classList.toggle("show");}</script>
  185. </body>
  186. </html>