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. <a name="q"></a>
  37. <p>The basic Rusty's idea was to stream small pieces of JavaScript
  38. to the thin client that performs simple <b>eval</b>. This is
  39. server side rendering framework with SDK for creating rich and complex
  40. control elements such as virtual grid or file upload element.</p>
  41. <a name="jse"></a>
  42. <h4>q(atom()) -> term().</h4>
  43. <p>Retrieves from process dictionary by atom-key the value of client DOM element
  44. passed by over the network in <b>#ev</b> record as a part of <b>#pickle</b> message.</p>
  45. <figure><code> event(click) -> io:format("~p~n",[nitro:q(:name)]);</code></figure>
  46. <a name="hte"></a>
  47. <h4>jse([] | binary()) -> [] | binary().</h4>
  48. <p>Performs JavaScript escaping that is safe to eval and <b>&lt;script&gt;</b> injection. See more about
  49. <a href="https://cheatsheetseries.owasp.org/cheatsheets/Cross_Site_Scripting_Prevention_Cheat_Sheet.html">XSS</a>.</p>
  50. <figure><code> > nitro:jse(&lt;&lt;"Ім'я"/utf8&gt;&gt;).
  51. &lt;&lt;"Ім\\'я"/utf8&gt;&gt;</code></figure>
  52. <a name="wire"></a>
  53. <h4>hte([] | binary()) -> [] | binary().</h4>
  54. <p>Performs HTML escaping that is safe to display as a text on a page.</p>
  55. <figure><code> > nitro:hte(&lt;&lt;"<a></a>"&gt;&gt;).
  56. "&#38;lt;a&#38;gt;&lt;/a&#38;gt;"</code></figure>
  57. <a name="render"></a>
  58. <h4>wire(list(#action{})) -> [].</h4>
  59. <p>Updates the process dictionary <b>actions</b> variable with the new list of records inhereted from <b>#action</b>.
  60. This process dictionary variable is a way data is passed from your <b>event</b> handlers into the output rendering pipeline.
  61. This is fixed by Nitrogen Web Framework API.</p>
  62. <figure><code> > nitro:wire([#alert{text="hello"}]).
  63. []
  64. > get(actions).
  65. [#wire{ancestor = action,
  66. trigger = [],
  67. target = [],
  68. module = action_wire,
  69. actions = [#alert{ancestor = action,
  70. trigger = [],
  71. target = [],
  72. module = action_alert,
  73. actions = [],
  74. source = [],
  75. text = "hello"}],
  76. source = []}]</code></figure>
  77. <a name="insert_top"></a>
  78. <h4>render(list(#action{} | #element{})) -> binary().</h4>
  79. <p>Renders HTML5 binary string by the record inhereted from <b>#element</b>.</p>
  80. <figure><code> > rr(nitro).
  81. [abbr,action,address,alert,api,area,article,aside,audio,
  82. author,b,base,bdi,bdo,bind,blockquote,body,br,button,
  83. calendar,canvas,caption,checkbox,cite,code,col,colgroup,
  84. color,command|...]
  85. &gt; #element{}.
  86. #element{ancestor = element,id = [],module = undefined,
  87. delegate = [],validation = [],validate = [],actions = [],
  88. class = [],style = [],source = [],onmouseover = [],
  89. onkeypress = [],onchange = [],onkeyup = [],onkeydown = [],
  90. onclick = [],data_fields = [],aria_states = [],body = [],
  91. role = [],tabindex = [],show_if = true,html_tag = [],
  92. title = [],postback = [],accesskey = [],
  93. contenteditable = [],contextmenu = [],...}
  94. &lt; nitro:render(#alert{text="hello"}).
  95. ["alert(\"","hello","\");"]
  96. &gt; nitro:render(#element{}).
  97. [&lt;&lt;"&lt;"&gt;&gt;,&lt;&lt;"element"&gt;&gt;,
  98. [[],[],[],[],[],[],[],[],[],[],[],[],[],[],[],[]],
  99. &lt;&lt;"&gt;"&gt;&gt;,&lt;&lt;&gt;&gt;,&lt;&lt;"&lt;/"&gt;&gt;,&lt;&lt;"element"&gt;&gt;,&lt;&lt;"&gt;"&gt;&gt;]
  100. &gt; iolist_to_binary(nitro:render(#element{})).
  101. &lt;&lt;"&lt;element&gt;&lt;/element&gt;"&gt;&gt;
  102. &gt; iolist_to_binary(nitro:render(setelement(1,#element{},tag))).
  103. &lt;&lt;"&lt;tag&gt;&lt;/tag&gt;"&gt;&gt;</code></figure>
  104. <a name="insert_bottom"></a>
  105. <h4>insert_top(atom(), list(#element{})) -> [].</h4>
  106. <p>Wires a JavaScript for adding the NITRO element as a first child of a given DOM id at the client.</p>
  107. <figure><code> > nitro:insert_top(panel,#button{}).
  108. []
  109. > nitro:actions().
  110. [#wire{ancestor = action,trigger = [],target = [],
  111. module = action_wire,
  112. actions = "qi('panel').insertBefore((function(){var div = qn('div');
  113. div.innerHTML = '&lt;button type=\"button\"&gt;&lt;/button&gt;';
  114. return div.firstChild; })(),qi('panel').firstChild);",
  115. source = []}]
  116. > rp(iolist_to_binary(nitro:render(nitro:actions()))).
  117. &lt;&lt;"qi('panel').insertBefore((function(){var div
  118. = qn('div'); div.innerHTML = '&lt;button type=\"button\"&gt;&lt;/button&gt;';
  119. return div.firstChild; })(),qi('panel').firstChild);"&gt;&gt;
  120. ok</code></figure>
  121. <a name="insert_adjustment"></a>
  122. <h4>insert_bottom(atom(), list(#element{})) -> [].</h4>
  123. <p>Wires a JavaScript for adding the NITRO element as a last child of a given DOM id at the client.</p>
  124. <figure><code> > nitro:insert_bottom(panel,#button{}).
  125. > rp(iolist_to_binary(nitro:render(nitro:actions()))).
  126. &lt;&lt;"(function(){ var div = qn('div'); div.innerHTML =
  127. '&lt;button type=\"button\"&gt;&lt;/button&gt;';qi('panel')
  128. .appendChild(div.firstChild); })();"&gt;&gt;
  129. ok</code></figure>
  130. <a name="update"></a>
  131. <h4>insert_adjustment(beforebegin | afterbegin
  132. | beforeend | afterend, atom(), list(#element{})) -> [].</h4>
  133. <p>Wires a JavaScript for different
  134. <a href="https://developer.mozilla.org/en-US/docs/Web/API/Element/insertAdjacentHTML">adjustment</a> modes.</p>
  135. <figure><code> > nitro:insert_adjacent(beforebegin, panel, #button{}).
  136. []
  137. > rp(iolist_to_binary(nitro:render(nitro:actions()))).
  138. &lt;&lt;"qi('panel').insertAdjacentHTML('beforebegin',
  139. '&lt;button type=\"button\"&gt;&lt;/button&gt;');"&gt;&gt;
  140. ok</code></figure>
  141. <a name="clear"></a>
  142. <h4>update(atom(), list(#element{})) -> [].</h4>
  143. <p>Wires a JavaScript for updating the DOM element at the client by the render of a given NITRO element.</p>
  144. <figure><code> > nitro:update(panel,#button{}).
  145. []
  146. > rp(iolist_to_binary(nitro:render(nitro:actions()))).
  147. &lt;&lt;"qi('panel').outerHTML='&lt;button type=\"button\"&lt;&gt;/button>';"&gt;&gt;
  148. ok</code></figure>
  149. <h4>remove(atom()) -> [].</h4>
  150. <h4>clear(atom()) -> [].</h4>
  151. <p>Wires a JavaScript that clear at the client all the children of a given DOM element id.</p>
  152. <figure><code> > nitro:clear(panel).
  153. []
  154. > rp(iolist_to_binary(nitro:render(nitro:actions()))).
  155. &lt;&lt;"var x = qi('panel'); while (x.firstChild) x.removeChild(x.firstChild);""&gt;&gt;
  156. ok</code></figure>
  157. <a name="display"></a>
  158. <a name="remove"></a>
  159. <p>Wires a JavaScript that remove particular DOM element from the tree at the client.</p>
  160. <figure><code> > nitro:remove(panel).
  161. []
  162. > rp(iolist_to_binary(nitro:render(nitro:actions()))).
  163. &lt;&lt;"var x=qi('panel'); x && x.parentNode.removeChild(x);"&gt;&gt;
  164. ok</code></figure>
  165. <a name="compact"></a>
  166. <h4>display(atom(),atom()) -> [].</h4>
  167. <p>Wires a JavaScript that remove particular DOM element from the tree at the client.</p>
  168. <figure><code> > nitro:display(panel,none).
  169. []
  170. > rp(iolist_to_binary(nitro:render(nitro:actions()))).
  171. &lt;&lt;"{ var x = qi('panel'); if (x) x.style.display = 'none'; }"&gt;&gt;
  172. ok</code></figure>
  173. <p>Wires a JavaScript that manipulate <b>style</b> field of a given DOM element.</p>
  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>