nitro.htm 8.3 KB

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