nitro.htm 8.7 KB

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