nitro.htm 8.9 KB

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