htmx-rails 0.0.0 → 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 2a727a1cc17042ff04c774edbc378d03f29c62c01e33733373ca6d7b7996b50c
4
- data.tar.gz: 978d16e758ed45c884e3b27e373722b92869aac1c693dcc666aabdad9b8cdac3
3
+ metadata.gz: 972f0b824831a04ea3f18e0021e091206f61b1a1c3951780601137ca59c89cd1
4
+ data.tar.gz: ff795bc5f41e4e1bed9382007007f2e59ba32ad46742f9920fe8f9f814d531e2
5
5
  SHA512:
6
- metadata.gz: c937bd74e7f9303f0f98eaba4ade8e44054d9ce66e629c62d90265ba55ab6873be34ee74f4e863e7eed68b599e8e34c7d3aac3900e1cf32034622de49e1c0bee
7
- data.tar.gz: 9fe86b33faf3c0b642102e327757f88323825df6b125a69e049ddabd632ba1b76732910bc46e57041017e6c043328ad3372f7d6f470ffa064cc68e8f122843f7
6
+ metadata.gz: bb8ceff768b6c0b4bfc4a52d3dd30f364fcb79fe8b23405fd815e4f50b4c59990bce3df9838cbaeeb01bf0b6956450f08c5a040ff0bdf4c63b3fea326fa258c5
7
+ data.tar.gz: 73dcdf6a9fb796a809c8092c599bfd2e8fe39dfb070629d3b3c9e7f7212746d6343313cf26662affef799ff22a7cd790f30885b917b2a652b9132d4e89a63b29
data/README.md CHANGED
@@ -1,12 +1,10 @@
1
1
  # Htmx::Rails
2
2
 
3
- Welcome to your new gem! In this directory, you'll find the files you need to be able to package up your Ruby library into a gem. Put your Ruby code in the file `lib/htmx/rails`. To experiment with that code, run `bin/console` for an interactive prompt.
4
-
5
- TODO: Delete this and the text above, and describe your gem
3
+ [HTMX](https://htmx.org/) ruby gem for Ruby on Rails.
6
4
 
7
5
  ## Installation
8
6
 
9
- Add this line to your application's Gemfile:
7
+ Add `htmx-rails` to your `Gemfile`:
10
8
 
11
9
  ```ruby
12
10
  gem 'htmx-rails'
@@ -20,9 +18,21 @@ Or install it yourself as:
20
18
 
21
19
  $ gem install htmx-rails
22
20
 
21
+ After installing the gem, run the installer:
22
+
23
+ $ rails g htmx:install
24
+
23
25
  ## Usage
24
26
 
25
- TODO: Write usage instructions here
27
+
28
+ ```HTML
29
+ <!-- have a button POST via AJAX -->
30
+ <button hx-post="/clicked" hx-swap="outerHTML">
31
+ Click Me
32
+ </button>
33
+ ```
34
+
35
+ ### Read the [docs](https://htmx.org/docs/) for a more in-depth introduction.
26
36
 
27
37
  ## Development
28
38
 
@@ -32,7 +42,7 @@ To install this gem onto your local machine, run `bundle exec rake install`. To
32
42
 
33
43
  ## Contributing
34
44
 
35
- Bug reports and pull requests are welcome on GitHub at https://github.com/[USERNAME]/htmx-rails. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [code of conduct](https://github.com/[USERNAME]/htmx-rails/blob/master/CODE_OF_CONDUCT.md).
45
+ Bug reports and pull requests are welcome on GitHub at https://github.com/rootstrap/htmx-rails. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [code of conduct](https://github.com/rootstrap/htmx-rails/blob/master/CODE_OF_CONDUCT.md).
36
46
 
37
47
 
38
48
  ## License
@@ -41,4 +51,4 @@ The gem is available as open source under the terms of the [MIT License](https:/
41
51
 
42
52
  ## Code of Conduct
43
53
 
44
- Everyone interacting in the Htmx::Rails project's codebases, issue trackers, chat rooms and mailing lists is expected to follow the [code of conduct](https://github.com/[USERNAME]/htmx-rails/blob/master/CODE_OF_CONDUCT.md).
54
+ Everyone interacting in the Htmx::Rails project's codebases, issue trackers, chat rooms and mailing lists is expected to follow the [code of conduct](https://github.com/rootstrap/htmx-rails/blob/master/CODE_OF_CONDUCT.md).
@@ -0,0 +1 @@
1
+ (function(e,t){if(typeof define==="function"&&define.amd){define([],t)}else{e.htmx=t()}})(typeof self!=="undefined"?self:this,function(){return function(){"use strict";var T={onLoad:x,process:Ze,on:P,off:U,trigger:rt,find:w,findAll:S,closest:I,remove:E,addClass:C,removeClass:A,toggleClass:L,takeClass:O,defineExtension:Vt,removeExtension:_t,logAll:b,logger:null,config:{historyEnabled:true,historyCacheSize:10,defaultSwapStyle:"innerHTML",defaultSwapDelay:0,defaultSettleDelay:100,includeIndicatorStyles:true,indicatorClass:"htmx-indicator",requestClass:"htmx-request",settlingClass:"htmx-settling",swappingClass:"htmx-swapping",attributesToSettle:["class","style","width","height"]},parseInterval:f,_:e,createEventSource:function(e){return new EventSource(e,{withCredentials:true})},createWebSocket:function(e){return new WebSocket(e,[])}};var t=["get","post","put","delete","patch"];var n=t.map(function(e){return"[hx-"+e+"], [data-hx-"+e+"]"}).join(", ");function f(e){if(e==null||e==="null"||e==="false"||e===""){return null}else if(e.lastIndexOf("ms")===e.length-2){return parseFloat(e.substr(0,e.length-2))}else if(e.lastIndexOf("s")===e.length-1){return parseFloat(e.substr(0,e.length-1))*1e3}else{return parseFloat(e)}}function s(e,t){return e.getAttribute&&e.getAttribute(t)}function o(e,t){return e.hasAttribute&&(e.hasAttribute(t)||e.hasAttribute("data-"+t))}function R(e,t){return s(e,t)||s(e,"data-"+t)}function l(e){return e.parentElement}function q(){return document}function c(e,t){if(t(e)){return e}else if(l(e)){return c(l(e),t)}else{return null}}function H(e,t){var r=null;c(e,function(e){return r=R(e,t)});return r}function v(e,t){var r=e.matches||e.matchesSelector||e.msMatchesSelector||e.mozMatchesSelector||e.webkitMatchesSelector||e.oMatchesSelector;return r&&r.call(e,t)}function r(e){var t=/<([a-z][^\/\0>\x20\t\r\n\f]*)/i;var r=t.exec(e);if(r){return r[1].toLowerCase()}else{return""}}function i(e,t){var r=new DOMParser;var n=r.parseFromString(e,"text/html");var i=n.body;while(t>0){t--;i=i.firstChild}if(i==null){i=q().createDocumentFragment()}return i}function h(e){var t=r(e);switch(t){case"thead":case"tbody":case"tfoot":case"colgroup":case"caption":return i("<table>"+e+"</table>",1);case"col":return i("<table><colgroup>"+e+"</colgroup></table>",2);case"tr":return i("<table><tbody>"+e+"</tbody></table>",2);case"td":case"th":return i("<table><tbody><tr>"+e+"</tr></tbody></table>",3);case"script":return i("<div>"+e+"</div>",1);default:return i(e,0)}}function a(e,t){return Object.prototype.toString.call(e)==="[object "+t+"]"}function u(e){return a(e,"Function")}function d(e){return a(e,"Object")}function N(e){var t="htmx-internal-data";var r=e[t];if(!r){r=e[t]={}}return r}function g(e){var t=[];if(e){for(var r=0;r<e.length;r++){t.push(e[r])}}return t}function k(e,t){if(e){for(var r=0;r<e.length;r++){t(e[r])}}}function m(e){var t=e.getBoundingClientRect();var r=t.top;var n=t.bottom;return r<window.innerHeight&&n>=0}function M(e){return q().body.contains(e)}function p(e){return e.trim().split(/\s+/)}function D(e,t){for(var r in t){if(t.hasOwnProperty(r)){e[r]=t[r]}}return e}function y(e){try{return JSON.parse(e)}catch(e){tt(e);return null}}function e(e){return eval(e)}function x(t){var e=T.on("htmx:load",function(e){t(e.detail.elt)});return e}function b(){T.logger=function(e,t,r){if(console){console.log(t,e,r)}}}function w(e,t){if(t){return e.querySelector(t)}else{return w(q(),e)}}function S(e,t){if(t){return e.querySelectorAll(t)}else{return S(q(),e)}}function E(e,t){e=X(e);if(t){setTimeout(function(){E(e)},t)}else{e.parentElement.removeChild(e)}}function C(e,t,r){e=X(e);if(r){setTimeout(function(){C(e,t)},r)}else{e.classList.add(t)}}function A(e,t,r){e=X(e);if(r){setTimeout(function(){A(e,t)},r)}else{e.classList.remove(t)}}function L(e,t){e=X(e);e.classList.toggle(t)}function O(e,t){e=X(e);k(e.parentElement.children,function(e){A(e,t)});C(e,t)}function I(e,t){e=X(e);do{if(e==null||v(e,t))return e}while(e=e&&l(e))}function X(e){if(a(e,"String")){return w(e)}else{return e}}function F(e,t,r){if(u(t)){return{target:q().body,event:e,listener:t}}else{return{target:X(e),event:t,listener:r}}}function P(t,r,n){Wt(function(){var e=F(t,r,n);e.target.addEventListener(e.event,e.listener)});var e=u(r);return e?r:n}function U(t,r,n){Wt(function(){var e=F(t,r,n);e.target.removeEventListener(e.event,e.listener)});return u(r)?r:n}function z(e){var t=c(e,function(e){return R(e,"hx-target")!==null});if(t){var r=R(t,"hx-target");if(r==="this"){return t}else if(r.indexOf("closest ")===0){return I(e,r.substr(8))}else if(r.indexOf("find ")===0){return w(e,r.substr(5))}else{return q().querySelector(r)}}else{var n=N(e);if(n.boosted){return q().body}else{return e}}}function V(e){var t=T.config.attributesToSettle;for(var r=0;r<t.length;r++){if(e===t[r]){return true}}return false}function _(t,r){k(t.attributes,function(e){if(!r.hasAttribute(e.name)&&V(e.name)){t.removeAttribute(e.name)}});k(r.attributes,function(e){if(V(e.name)){t.setAttribute(e.name,e.value)}})}function j(e,t){var r=jt(t);for(var n=0;n<r.length;n++){var i=r[n];try{if(i.isInlineSwap(e)){return true}}catch(e){tt(e)}}return e==="outerHTML"}function W(e,t,r){var n="#"+t.id;var i="outerHTML";if(e==="true"){}else if(e.indexOf(":")>0){i=e.substr(0,e.indexOf(":"));n=e.substr(e.indexOf(":")+1,e.length)}else{i=e}var a=q().querySelector(n);if(a){var o;o=q().createDocumentFragment();o.appendChild(t);if(!j(i,a)){o=t}ae(i,a,a,o,r)}else{t.parentNode.removeChild(t);Ke(q().body,"htmx:oobErrorNoTarget",{content:t})}return e}function B(e,r){k(S(e,"[hx-swap-oob], [data-hx-swap-oob]"),function(e){var t=R(e,"hx-swap-oob");if(t!=null){W(t,e,r)}})}function $(n,e,i){k(e.querySelectorAll("[id]"),function(e){if(e.id&&e.id.length>0){var t=n.querySelector(e.tagName+"[id='"+e.id+"']");if(t&&t!==n){var r=e.cloneNode();_(e,t);i.tasks.push(function(){_(e,r)})}}})}function J(e){return function(){Ze(e);We(e);Z(e);rt(e,"htmx:load")}}function Z(e){var t="[autofocus]";var r=v(e,t)?e:e.querySelector(t);if(r!=null){r.focus()}}function G(e,t,r,n){$(e,r,n);while(r.childNodes.length>0){var i=r.firstChild;e.insertBefore(i,t);if(i.nodeType!==Node.TEXT_NODE&&i.nodeType!==Node.COMMENT_NODE){n.tasks.push(J(i))}}}function Y(e){var t=N(e);if(t.webSocket){t.webSocket.close()}if(t.sseEventSource){t.sseEventSource.close()}if(e.children){k(e.children,function(e){Y(e)})}}function K(e,t,r){if(e.tagName==="BODY"){return ne(e,t)}else{var n=e.previousSibling;G(l(e),e,t,r);if(n==null){var i=l(e).firstChild}else{var i=n.nextSibling}N(e).replacedWith=i;while(i&&i!==e){if(i.nodeType===Node.ELEMENT_NODE){r.elts.push(i)}i=i.nextElementSibling}Y(e);l(e).removeChild(e)}}function Q(e,t,r){return G(e,e.firstChild,t,r)}function ee(e,t,r){return G(l(e),e,t,r)}function te(e,t,r){return G(e,null,t,r)}function re(e,t,r){return G(l(e),e.nextSibling,t,r)}function ne(e,t,r){var n=e.firstChild;G(e,n,t,r);if(n){while(n.nextSibling){Y(n.nextSibling);e.removeChild(n.nextSibling)}Y(n);e.removeChild(n)}}function ie(e,t){var r=H(e,"hx-select");if(r){var n=q().createDocumentFragment();k(t.querySelectorAll(r),function(e){n.appendChild(e)});t=n}return t}function ae(e,t,r,n,i){switch(e){case"none":return;case"outerHTML":K(r,n,i);return;case"afterbegin":Q(r,n,i);return;case"beforebegin":ee(r,n,i);return;case"beforeend":te(r,n,i);return;case"afterend":re(r,n,i);return;default:var a=jt(t);for(var o=0;o<a.length;o++){var u=a[o];try{var s=u.handleSwap(e,r,n,i);if(s){if(typeof s.length!=="undefined"){for(var l=0;l<s.length;l++){var f=s[l];if(f.nodeType!==Node.TEXT_NODE&&f.nodeType!==Node.COMMENT_NODE){i.tasks.push(J(f))}}}return}}catch(e){tt(e)}}ne(r,n,i)}}var oe=/<title>([\s\S]+?)<\/title>/im;function ue(e){var t=oe.exec(e);if(t){return t[1]}}function se(e,t,r,n,i){var a=ue(n);if(a){var o=w("title");if(o){o.innerHTML=a}else{window.document.title=a}}var u=h(n);if(u){B(u,i);u=ie(r,u);return ae(e,r,t,u,i)}}function le(e,t,r){var n=e.getResponseHeader(t);if(n.indexOf("{")===0){var i=y(n);for(var a in i){if(i.hasOwnProperty(a)){var o=i[a];if(!d(o)){o={value:o}}rt(r,a,o)}}}else{rt(r,n,[])}}var fe=/\s/;var ce=/[_$a-zA-Z]/;var ve=/[_$a-zA-Z0-9]/;var he=['"',"'","/"];var de=/[^\s]/;function ge(e){var t=[];var r=0;while(r<e.length){if(ce.exec(e.charAt(r))){var n=r;r++;while(ve.exec(e.charAt(r+1))){r++}t.push(e.substr(n,r-n+1))}else if(he.indexOf(e.charAt(r))!==-1){var i=e.charAt(r);var n=r;r++;while(r<e.length&&e.charAt(r)!==i){if(e.charAt(r)==="\\"){r++}r++}t.push(e.substr(n,r-n+1))}else{var a=e.charAt(r);t.push(a)}r++}return t}function me(e,t,r){return ce.exec(e.charAt(0))&&e!=="true"&&e!=="false"&&e!=="this"&&e!==r&&t!=="."}function pe(e,t){if(e[0]==="["){e.shift();var r=1;var n=" return (function("+t+"){ return (";var i=null;while(e.length>0){var a=e[0];if(a==="]"){r--;if(r===0){if(i===null){n=n+"true"}e.shift();n+=")})";try{var o=Function(n)();o.source=n;return o}catch(e){Ke(q().body,"htmx:syntax:error",{error:e,source:n});return null}}}else if(a==="["){r++}if(me(a,i,t)){n+="(("+t+"."+a+") ? ("+t+"."+a+") : (window."+a+"))"}else{n=n+a}i=e.shift()}}}function ye(e,t){var r="";while(e.length>0&&!e[0].match(t)){r+=e.shift()}return r}function xe(e){var t=R(e,"hx-trigger");var r=[];if(t){var n=ge(t);do{ye(n,de);var i=n.length;var a=ye(n,/[,\[\s]/);if(a!==""){if(a==="every"){var o={trigger:"every"};ye(n,de);o.pollInterval=f(ye(n,fe));r.push(o)}else if(a.indexOf("sse:")===0){r.push({trigger:"sse",sseEvent:a.substr(4)})}else{var u={trigger:a};var s=pe(n,"event");if(s){u.eventFilter=s}while(n.length>0&&n[0]!==","){ye(n,de);var l=n.shift();if(l==="changed"){u.changed=true}else if(l==="once"){u.once=true}else if(l==="delay"&&n[0]===":"){n.shift();u.delay=f(ye(n,fe))}else if(l==="throttle"&&n[0]===":"){n.shift();u.throttle=f(ye(n,fe))}else{Ke(e,"htmx:syntax:error",{token:n.shift()})}}r.push(u)}}if(n.length===i){Ke(e,"htmx:syntax:error",{token:n.shift()})}ye(n,de)}while(n[0]===","&&n.shift())}if(r.length>0){return r}else if(v(e,"form")){return[{trigger:"submit"}]}else if(v(e,"input, textarea, select")){return[{trigger:"change"}]}else{return[{trigger:"click"}]}}function be(e){N(e).cancelled=true}function we(e,t,r,n){var i=N(e);i.timeout=setTimeout(function(){if(M(e)&&i.cancelled!==true){Pt(e,t,r);we(e,t,R(e,"hx-"+t),n)}},n)}function Se(e){return location.hostname===e.hostname&&s(e,"href")&&s(e,"href").indexOf("#")!==0}function Ee(t,r,e){if(t.tagName==="A"&&Se(t)||t.tagName==="FORM"){r.boosted=true;var n,i;if(t.tagName==="A"){n="get";i=s(t,"href")}else{var a=s(t,"method");n=a?a.toLowerCase():"get";i=s(t,"action")}e.forEach(function(e){Oe(t,n,i,r,e,true)})}}function Ce(e){return e.tagName==="FORM"||v(e,'input[type="submit"], button')&&I(e,"form")!==null||e.tagName==="A"&&e.href&&e.href.indexOf("#")!==0}function Ae(e,t){return N(e).boosted&&e.tagName==="A"&&t.type==="click"&&t.ctrlKey}function Le(e,t){var r=e.eventFilter;if(r){try{return r(t)!==true}catch(e){Ke(q().body,"htmx:eventFilter:error",{error:e,source:r.source});return true}}return false}function Oe(n,i,a,e,o,u){var t=function(e){if(Le(o,e)){return}if(Ae(n,e)){return}if(u||Ce(n)){e.preventDefault()}var t=N(e);var r=N(n);if(!t.handled){t.handled=true;if(o.once){if(r.triggeredOnce){return}else{r.triggeredOnce=true}}if(o.changed){if(r.lastValue===n.value){return}else{r.lastValue=n.value}}if(r.delayed){clearTimeout(r.delayed)}if(r.throttle){return}if(o.throttle){r.throttle=setTimeout(function(){Pt(n,i,a,e.target,e);r.throttle=null},o.throttle)}else if(o.delay){r.delayed=setTimeout(function(){Pt(n,i,a,e.target,e)},o.delay)}else{Pt(n,i,a,e.target,e)}}};e.trigger=o.trigger;e.eventListener=t;n.addEventListener(o.trigger,t)}var Te=false;var Re=null;function qe(){if(!Re){Re=function(){Te=true};window.addEventListener("scroll",Re);setInterval(function(){if(Te){Te=false;k(q().querySelectorAll("[hx-trigger='revealed'],[data-hx-trigger='revealed']"),function(e){He(e)})}},200)}}function He(e){var t=N(e);if(!t.revealed&&m(e)){t.revealed=true;Pt(e,t.verb,t.path)}}function Ne(e,t,r){var n=p(r);for(var i=0;i<n.length;i++){var a=n[i].split(/:(.+)/);if(a[0]==="connect"){ke(e,a[1])}if(a[0]==="send"){De(e)}}}function ke(u,e){if(e.indexOf("ws:")!==0&&e.indexOf("wss:")!==0){e="wss:"+e}var t=T.createWebSocket(e);t.onerror=function(e){Ke(u,"htmx:wsError",{error:e,socket:t});Me(u)};N(u).webSocket=t;t.addEventListener("message",function(e){if(Me(u)){return}var t=e.data;et(u,function(e){t=e.transformResponse(t,null,u)});var r=qt(u);var n=h(t);var i=g(n.children);for(var a=0;a<i.length;a++){var o=i[a];W(R(o,"hx-swap-oob")||"true",o,r)}ft(r.tasks)})}function Me(e){if(!M(e)){N(e).webSocket.close();return true}}function De(s){var l=c(s,function(e){return N(e).webSocket!=null});if(l){var f=N(l).webSocket;s.addEventListener(xe(s)[0].trigger,function(e){var t=Lt(s,l,null,s);var r=St(s,"post");var n=r.errors;var i=r.values;var a=Dt(s);var o=D(i,a);var u=Ot(o,s);u["HEADERS"]=t;if(n&&n.length>0){rt(s,"htmx:validation:halted",n);return}f.send(JSON.stringify(u));if(Ce(s)){e.preventDefault()}})}else{Ke(s,"htmx:noWebSocketSourceError")}}function Ie(e,t,r){var n=p(r);for(var i=0;i<n.length;i++){var a=n[i].split(/:(.+)/);if(a[0]==="connect"){Xe(e,a[1])}if(a[0]==="swap"){Fe(e,a[1])}}}function Xe(t,e){var r=T.createEventSource(e);r.onerror=function(e){Ke(t,"htmx:sseError",{error:e,source:r});Ue(t)};N(t).sseEventSource=r}function Fe(a,o){var u=c(a,ze);if(u){var s=N(u).sseEventSource;var l=function(e){if(Ue(u)){s.removeEventListener(o,l);return}var t=e.data;et(a,function(e){t=e.transformResponse(t,null,a)});var r=Tt(a);var n=z(a);var i=qt(a);se(r.swapStyle,a,n,t,i);rt(a,"htmx:sseMessage",e)};N(a).sseListener=l;s.addEventListener(o,l)}else{Ke(a,"htmx:noSSESourceError")}}function Pe(e,t,r,n){var i=c(e,ze);if(i){var a=N(i).sseEventSource;var o=function(){if(!Ue(i)){if(M(e)){Pt(e,t,r)}else{a.removeEventListener(n,o)}}};N(e).sseListener=o;a.addEventListener(n,o)}else{Ke(e,"htmx:noSSESourceError")}}function Ue(e){if(!M(e)){N(e).sseEventSource.close();return true}}function ze(e){return N(e).sseEventSource!=null}function Ve(e,t,r,n,i){var a=function(){if(!n.loaded){n.loaded=true;Pt(e,t,r)}};if(i){setTimeout(a,i)}else{a()}}function _e(n,i,e){var a=false;k(t,function(t){if(o(n,"hx-"+t)){var r=R(n,"hx-"+t);a=true;i.path=r;i.verb=t;e.forEach(function(e){if(e.sseEvent){Pe(n,t,r,e.sseEvent)}else if(e.trigger==="revealed"){qe();He(n)}else if(e.trigger==="load"){Ve(n,t,r,i,e.delay)}else if(e.pollInterval){i.polling=true;we(n,t,r,e.pollInterval)}else{Oe(n,t,r,i,e)}})}});return a}function je(e){if(e.type==="text/javascript"||e.type===""){try{Function(e.innerText)()}catch(e){tt(e)}}}function We(e){if(v(e,"script")){je(e)}k(S(e,"script"),function(e){je(e)})}function Be(){return document.querySelector("[hx-boost], [data-hx-boost]")}function $e(e){if(e.querySelectorAll){var t=Be()?", a, form":"";var r=e.querySelectorAll(n+t+", [hx-sse], [data-hx-sse], [hx-ws],"+" [data-hx-ws]");return r}else{return[]}}function Je(e){var t=N(e);if(!t.initialized){t.initialized=true;if(e.value){t.lastValue=e.value}var r=xe(e);var n=_e(e,t,r);if(!n&&H(e,"hx-boost")==="true"){Ee(e,t,r)}var i=R(e,"hx-sse");if(i){Ie(e,t,i)}var a=R(e,"hx-ws");if(a){Ne(e,t,a)}rt(e,"htmx:processedNode")}}function Ze(e){e=X(e);Je(e);k($e(e),function(e){Je(e)})}function Ge(e){return e.replace(/([a-z0-9])([A-Z])/g,"$1-$2").toLowerCase()}function Ye(e,t){var r;if(window.CustomEvent&&typeof window.CustomEvent==="function"){r=new CustomEvent(e,{bubbles:true,cancelable:true,detail:t})}else{r=q().createEvent("CustomEvent");r.initCustomEvent(e,true,true,t)}return r}function Ke(e,t,r){rt(e,t,D({error:t},r))}function Qe(e){return e==="htmx:processedNode"}function et(e,t){k(jt(e),function(e){try{t(e)}catch(e){tt(e)}})}function tt(e){if(console.error){console.error(e)}else if(console.log){console.log("ERROR: ",e)}}function rt(e,t,r){e=X(e);if(r==null){r={}}r["elt"]=e;var n=Ye(t,r);if(T.logger&&!Qe(t)){T.logger(e,t,r)}if(r.error){tt(r.error);rt(e,"htmx:error",{errorInfo:r})}var i=e.dispatchEvent(n);var a=Ge(t);if(i&&a!==t){var o=Ye(a,n.detail);i=i&&e.dispatchEvent(o)}et(e,function(e){i=i&&e.onEvent(t,n)!==false});return i}var nt=null;function it(){var e=q().querySelector("[hx-history-elt],[data-hx-history-elt]");return e||q().body}function at(e,t,r,n){var i=y(localStorage.getItem("htmx-history-cache"))||[];for(var a=0;a<i.length;a++){if(i[a].url===e){i=i.slice(a,1);break}}i.push({url:e,content:t,title:r,scroll:n});while(i.length>T.config.historyCacheSize){i.shift()}try{localStorage.setItem("htmx-history-cache",JSON.stringify(i))}catch(e){Ke(q().body,"htmx:historyCacheError",{cause:e})}}function ot(e){var t=y(localStorage.getItem("htmx-history-cache"))||[];for(var r=0;r<t.length;r++){if(t[r].url===e){return t[r]}}return null}function ut(e){var t=T.config.requestClass;var r=e.cloneNode(true);k(S(r,"."+t),function(e){A(e,t)});return r.innerHTML}function st(){var e=it();var t=nt||location.pathname+location.search;rt(q().body,"htmx:beforeHistorySave",{path:t,historyElt:e});if(T.config.historyEnabled)history.replaceState({htmx:true},q().title,window.location.href);at(t,ut(e),q().title,window.scrollY)}function lt(e){if(T.config.historyEnabled)history.pushState({htmx:true},"",e);nt=e}function ft(e){k(e,function(e){e.call()})}function ct(n){var e=new XMLHttpRequest;var i={path:n,xhr:e};rt(q().body,"htmx:historyCacheMiss",i);e.open("GET",n,true);e.onload=function(){if(this.status>=200&&this.status<400){rt(q().body,"htmx:historyCacheMissLoad",i);var e=h(this.response);e=e.querySelector("[hx-history-elt],[data-hx-history-elt]")||e;var t=it();var r=qt(t);ne(t,e,r);ft(r.tasks);nt=n}else{Ke(q().body,"htmx:historyCacheMissLoadError",i)}};e.send()}function vt(e){st(nt);e=e||location.pathname+location.search;rt(q().body,"htmx:historyRestore",{path:e});var t=ot(e);if(t){var r=h(t.content);var n=it();var i=qt(n);ne(n,r,i);ft(i.tasks);document.title=t.title;window.scrollTo(0,t.scroll);nt=e}else{ct(e)}}function ht(e){var t=H(e,"hx-push-url");return t&&t!=="false"||e.tagName==="A"&&N(e).boosted}function dt(e){var t=H(e,"hx-push-url");return t==="true"||t==="false"?null:t}function gt(e){pt(e,"add")}function mt(e){pt(e,"remove")}function pt(e,t){var r=H(e,"hx-indicator");if(r){var n=q().querySelectorAll(r)}else{n=[e]}k(n,function(e){e.classList[t].call(e.classList,T.config.requestClass)})}function yt(e,t){for(var r=0;r<e.length;r++){var n=e[r];if(n.isSameNode(t)){return true}}return false}function xt(e){if(e.name===""||e.name==null||e.disabled){return false}if(e.type==="button"||e.type==="submit"||e.tagName==="image"||e.tagName==="reset"||e.tagName==="file"){return false}if(e.type==="checkbox"||e.type==="radio"){return e.checked}return true}function bt(t,r,n,e){if(e==null||yt(t,e)){return}else{t.push(e)}if(xt(e)){var i=s(e,"name");var a=e.value;if(e.multiple){a=g(e.querySelectorAll("option:checked")).map(function(e){return e.value})}if(e.files){a=g(e.files)}if(i!=null&&a!=null){var o=r[i];if(o){if(Array.isArray(o)){if(Array.isArray(a)){r[i]=o.concat(a)}else{o.push(a)}}else{if(Array.isArray(a)){r[i]=[o].concat(a)}else{r[i]=[o,a]}}}else{r[i]=a}}wt(e,n)}if(v(e,"form")){var u=e.elements;k(u,function(e){bt(t,r,n,e)})}}function wt(e,t){if(e.willValidate){rt(e,"htmx:validation:validate");if(!e.checkValidity()){t.push({elt:e,message:e.validationMessage,validity:e.validity});rt(e,"htmx:validation:failed",{message:e.validationMessage,validity:e.validity})}}}function St(e,t){var r=[];var n={};var i=[];if(t!=="get"){bt(r,n,i,I(e,"form"))}bt(r,n,i,e);var a=H(e,"hx-include");if(a){var o=q().querySelectorAll(a);k(o,function(e){bt(r,n,i,e)})}return{errors:i,values:n}}function Et(e,t,r){if(e!==""){e+="&"}e+=encodeURIComponent(t)+"="+encodeURIComponent(r);return e}function Ct(e){var t="";for(var r in e){if(e.hasOwnProperty(r)){var n=e[r];if(Array.isArray(n)){k(n,function(e){t=Et(t,r,e)})}else{t=Et(t,r,n)}}}return t}function At(e){var t=new FormData;for(var r in e){if(e.hasOwnProperty(r)){var n=e[r];if(Array.isArray(n)){k(n,function(e){t.append(r,e)})}else{t.append(r,n)}}}return t}function Lt(e,t,r,n){var i={"HX-Request":"true","HX-Trigger":s(e,"id"),"HX-Trigger-Name":s(e,"name"),"HX-Target":R(t,"id"),"HX-Current-URL":q().location.href};if(r!==undefined){i["HX-Prompt"]=r}if(n){i["HX-Event-Target"]=s(n,"id")}if(q().activeElement){i["HX-Active-Element"]=s(q().activeElement,"id");i["HX-Active-Element-Name"]=s(q().activeElement,"name");if(q().activeElement.value){i["HX-Active-Element-Value"]=s(q().activeElement,"value")}}return i}function Ot(t,e){var r=H(e,"hx-params");if(r){if(r==="none"){return{}}else if(r==="*"){return t}else if(r.indexOf("not ")===0){k(r.substr(4).split(","),function(e){e=e.trim();delete t[e]});return t}else{var n={};k(r.split(","),function(e){e=e.trim();n[e]=t[e]});return n}}else{return t}}function Tt(e){var t=H(e,"hx-swap");var r={swapStyle:T.config.defaultSwapStyle,swapDelay:T.config.defaultSwapDelay,settleDelay:T.config.defaultSettleDelay};if(t){var n=p(t);if(n.length>0){r["swapStyle"]=n[0];for(var i=1;i<n.length;i++){var a=n[i];if(a.indexOf("swap:")===0){r["swapDelay"]=f(a.substr(5))}if(a.indexOf("settle:")===0){r["settleDelay"]=f(a.substr(7))}if(a.indexOf("scroll:")===0){r["scroll"]=a.substr(7)}if(a.indexOf("show:")===0){r["show"]=a.substr(5)}}}}return r}function Rt(t,r,n){var i=null;et(r,function(e){if(i==null){i=e.encodeParameters(t,n,r)}});if(i!=null){return i}else{if(H(r,"hx-encoding")==="multipart/form-data"){return At(n)}else{return Ct(n)}}}function qt(e){return{tasks:[],elts:[e]}}function Ht(e,t,r){if(r.scroll){if(r.scroll==="top"){e.scrollTop=0}if(r.scroll==="bottom"){e.scrollTop=e.scrollHeight}}if(r.show){if(r.show==="top"){e.scrollIntoView(true)}if(r.show==="bottom"){e.scrollIntoView(false)}}}function Nt(e,t,r,n){if(n==null){n={}}if(e==null){return n}var i=R(e,t);if(i){var a=i.trim();if(a.indexOf("{")!==0){a="{"+a+"}"}var o=r(a);for(var u in o){if(o.hasOwnProperty(u)){if(n[u]==null){n[u]=o[u]}}}}return Nt(l(e),t,r,n)}function kt(e,t){return Nt(e,"hx-vars",function(e){return Function("return ("+e+")")()},t)}function Mt(e,t){return Nt(e,"hx-vals",function(e){return y(e)},t)}function Dt(e){return D(kt(e),Mt(e))}function It(t,r,n){if(n!==null){try{t.setRequestHeader(r,n)}catch(e){t.setRequestHeader(r,encodeURIComponent(n));t.setRequestHeader(r+"-URI-AutoEncoded","true")}}}function Xt(t){if(t.responseURL&&typeof URL!=="undefined"){try{var e=new URL(t.responseURL);return e.pathname+e.search}catch(e){Ke(q().body,"htmx:badResponseUrl",{url:t.responseURL})}}}function Ft(e,t){return e.getAllResponseHeaders().match(t)}function Pt(l,e,f,t,r){if(!M(l)){console.log("Body does not contain",l);return}var c=z(l);if(c==null){Ke(l,"htmx:targetError",{target:R(l,"hx-target")});return}var n=N(l);if(n.requestInFlight){n.queuedRequest=function(){Pt(l,e,f,t,r)};return}else{n.requestInFlight=true}var i=function(){n.requestInFlight=false;var e=n.queuedRequest;n.queuedRequest=null;if(e){e()}};var a=H(l,"hx-prompt");if(a){var o=prompt(a);if(o===null||!rt(l,"htmx:prompt",{prompt:o,target:c}))return i()}var u=H(l,"hx-confirm");if(u){if(!confirm(u))return i()}var v=new XMLHttpRequest;var s=Lt(l,c,o,t);var h=St(l,e);var d=h.errors;var g=h.values;var m=Dt(l);var p=D(g,m);var y=Ot(p,l);if(e!=="get"&&H(l,"hx-encoding")==null){s["Content-Type"]="application/x-www-form-urlencoded; charset=UTF-8"}if(f==null||f===""){f=q().location.href}var x={parameters:y,unfilteredParameters:p,headers:s,target:c,verb:e,errors:d,path:f,triggeringEvent:r};if(!rt(l,"htmx:configRequest",x))return i();f=x.path;e=x.verb;s=x.headers;y=x.parameters;d=x.errors;if(d&&d.length>0){rt(l,"htmx:validation:halted",x);return i()}var b=f.split("#");var w=b[0];var S=b[1];if(e==="get"){var E=w;var C=Object.keys(y).length!==0;if(C){if(E.indexOf("?")<0){E+="?"}else{E+="&"}E+=Ct(y);if(S){E+="#"+S}}v.open("GET",E,true)}else{v.open(e.toUpperCase(),f,true)}v.overrideMimeType("text/html");for(var A in s){if(s.hasOwnProperty(A)){var L=s[A];It(v,A,L)}}var O={xhr:v,target:c,requestConfig:x};v.onload=function(){try{if(!rt(l,"htmx:beforeOnLoad",O))return;if(Ft(v,/HX-Trigger:/i)){le(v,"HX-Trigger",l)}if(Ft(v,/HX-Push:/i)){var a=v.getResponseHeader("HX-Push")}if(Ft(v,/HX-Redirect:/i)){window.location.href=v.getResponseHeader("HX-Redirect");return}if(Ft(v,/HX-Refresh:/i)){if("true"===v.getResponseHeader("HX-Refresh")){location.reload();return}}var o=ht(l)||a;if(this.status>=200&&this.status<400){if(this.status===286){be(l)}if(this.status!==204){if(!rt(c,"htmx:beforeSwap",O))return;var u=this.response;et(l,function(e){u=e.transformResponse(u,v,l)});if(o){st()}var s=Tt(l);c.classList.add(T.config.swappingClass);var e=function(){try{var e=document.activeElement;var t={elt:e,start:e?e.selectionStart:null,end:e?e.selectionEnd:null};var r=qt(c);se(s.swapStyle,c,l,u,r);if(t.elt&&!M(t.elt)&&t.elt.id){var n=document.getElementById(t.elt.id);if(n){if(t.start&&n.setSelectionRange){n.setSelectionRange(t.start,t.end)}n.focus()}}c.classList.remove(T.config.swappingClass);k(r.elts,function(e){if(e.classList){e.classList.add(T.config.settlingClass)}rt(e,"htmx:afterSwap",O)});if(S){location.hash=S}if(Ft(v,/HX-Trigger-After-Swap:/i)){le(v,"HX-Trigger-After-Swap",l)}var i=function(){k(r.tasks,function(e){e.call()});k(r.elts,function(e){if(e.classList){e.classList.remove(T.config.settlingClass)}rt(e,"htmx:afterSettle",O)});if(o){var e=a||dt(l)||Xt(v)||E||f;lt(e);rt(q().body,"htmx:pushedIntoHistory",{path:e})}Ht(c,r.elts,s);if(Ft(v,/HX-Trigger-After-Settle:/i)){le(v,"HX-Trigger-After-Settle",l)}};if(s.settleDelay>0){setTimeout(i,s.settleDelay)}else{i()}}catch(e){Ke(l,"htmx:swapError",O);throw e}};if(s.swapDelay>0){setTimeout(e,s.swapDelay)}else{e()}}}else{Ke(l,"htmx:responseError",D({error:"Response Status Error Code "+this.status+" from "+f},O))}}catch(e){Ke(l,"htmx:onLoadError",D({error:e},O));throw e}finally{mt(l);var t=N(l).replacedWith||l;rt(t,"htmx:afterRequest",O);rt(t,"htmx:afterOnLoad",O);i()}};v.onerror=function(){mt(l);Ke(l,"htmx:afterRequest",O);Ke(l,"htmx:sendError",O);i()};v.onabort=function(){mt(l);i()};if(!rt(l,"htmx:beforeRequest",O))return i();gt(l);k(["loadstart","loadend","progress","abort"],function(t){k([v,v.upload],function(e){e.addEventListener(t,function(e){rt(l,"htmx:xhr:"+t,{lengthComputable:e.lengthComputable,loaded:e.loaded,total:e.total})})})});v.send(e==="get"?null:Rt(v,l,y))}var Ut={};function zt(){return{onEvent:function(e,t){return true},transformResponse:function(e,t,r){return e},isInlineSwap:function(e){return false},handleSwap:function(e,t,r,n){return false},encodeParameters:function(e,t,r){return null}}}function Vt(e,t){Ut[e]=D(zt(),t)}function _t(e){delete Ut[e]}function jt(e,r){if(e==null){return r}if(r==null){r=[]}var t=R(e,"hx-ext");if(t){k(t.split(","),function(e){e=e.replace(/ /g,"");var t=Ut[e];if(t&&r.indexOf(t)<0){r.push(t)}})}return jt(l(e),r)}function Wt(e){if(q().readyState!=="loading"){e()}else{q().addEventListener("DOMContentLoaded",e)}}function Bt(){if(T.config.includeIndicatorStyles!==false){q().head.insertAdjacentHTML("beforeend","<style> ."+T.config.indicatorClass+"{opacity:0;transition: opacity 200ms ease-in;} ."+T.config.requestClass+" ."+T.config.indicatorClass+"{opacity:1} ."+T.config.requestClass+"."+T.config.indicatorClass+"{opacity:1} </style>")}}function $t(){var e=q().querySelector('meta[name="htmx-config"]');if(e){return y(e.content)}else{return null}}function Jt(){var e=$t();if(e){T.config=D(T.config,e)}}Wt(function(){Jt();Bt();var e=q().body;Ze(e);rt(e,"htmx:load",{});window.onpopstate=function(e){if(e.state&&e.state.htmx){vt()}}});return T}()});
@@ -0,0 +1,61 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Htmx
4
+ module Generators
5
+ class InstallGenerator < ::Rails::Generators::Base
6
+ WEBPACKER_SETUP = "require('htmx.org')\n"
7
+ SPROCKETS_SETUP = "//= require htmx\n"
8
+
9
+ desc 'Prep application.js to include HTMX installation for Webpacker or Sprockets'
10
+
11
+ # Setup HTMX
12
+ def setup
13
+ if webpacker?
14
+ setup_webpacker
15
+ else
16
+ setup_sprockets
17
+ end
18
+ end
19
+
20
+ private
21
+
22
+ def webpacker?
23
+ !!defined?(Webpacker)
24
+ end
25
+
26
+ def manifest(javascript_dir)
27
+ Pathname.new(destination_root).join(javascript_dir, 'application.js')
28
+ end
29
+
30
+ def setup_sprockets
31
+ manifest = manifest('app/assets/javascripts')
32
+
33
+ if manifest.exist?
34
+ append_file manifest, "\n#{SPROCKETS_SETUP}"
35
+ else
36
+ create_file manifest, SPROCKETS_SETUP
37
+ end
38
+ end
39
+
40
+ def setup_webpacker
41
+ `yarn add htmx.org`
42
+
43
+ manifest = manifest(webpack_source_path)
44
+
45
+ if manifest.exist?
46
+ append_file(manifest, "\n#{WEBPACKER_SETUP}")
47
+ else
48
+ create_file(manifest, WEBPACKER_SETUP)
49
+ end
50
+ end
51
+
52
+ def webpack_source_path
53
+ (Webpacker.try(:config).try(:source_entry_path) ||
54
+ Webpacker::Configuration.source_path.join(
55
+ Webpacker::Configuration.entry_path
56
+ )
57
+ ).relative_path_from(::Rails.root).to_s
58
+ end
59
+ end
60
+ end
61
+ end
@@ -0,0 +1,15 @@
1
+ # frozen_string_literal: true
2
+
3
+ # Rails Core
4
+ require 'active_support/core_ext/hash'
5
+ require 'rails/generators'
6
+
7
+ # Files
8
+ require 'generators/htmx/install_generator'
9
+ require 'htmx/rails/version'
10
+
11
+ module Htmx
12
+ module Rails
13
+ class Error < StandardError; end
14
+ end
15
+ end
@@ -1,5 +1,8 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module Htmx
2
4
  module Rails
3
- VERSION = '0.0.0'.freeze
5
+ VERSION = '0.1.0'
6
+ HTMX_VERSION = '1.0.2'
4
7
  end
5
8
  end
metadata CHANGED
@@ -1,15 +1,29 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: htmx-rails
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.0
4
+ version: 0.1.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Julian Pasquale
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2020-12-11 00:00:00.000000000 Z
11
+ date: 2021-01-11 00:00:00.000000000 Z
12
12
  dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: generator_spec
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ">="
18
+ - !ruby/object:Gem::Version
19
+ version: '0'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ">="
25
+ - !ruby/object:Gem::Version
26
+ version: '0'
13
27
  - !ruby/object:Gem::Dependency
14
28
  name: rake
15
29
  requirement: !ruby/object:Gem::Requirement
@@ -80,21 +94,26 @@ dependencies:
80
94
  - - "~>"
81
95
  - !ruby/object:Gem::Version
82
96
  version: 0.17.1
83
- description: ''
97
+ description: Ruby gem for use HTMX in Rails applications
84
98
  email:
85
- - julianagustin78@gmail.com
99
+ - julian.pasquale@rootstrap.com
86
100
  executables: []
87
101
  extensions: []
88
102
  extra_rdoc_files: []
89
103
  files:
90
104
  - LICENSE.txt
91
105
  - README.md
92
- - lib/htmx/rails.rb
106
+ - lib/assets/javascripts/htmx.js
107
+ - lib/generators/htmx/install_generator.rb
108
+ - lib/htmx-rails.rb
93
109
  - lib/htmx/rails/version.rb
94
- homepage: ''
110
+ homepage: https://github.com/rootstrap/htmx-rails
95
111
  licenses:
96
112
  - MIT
97
- metadata: {}
113
+ metadata:
114
+ homepage_uri: https://github.com/rootstrap/htmx-rails
115
+ source_code_uri: https://github.com/rootstrap/htmx-rails
116
+ changelog_uri: https://github.com/rootstrap/htmx-rails
98
117
  post_install_message:
99
118
  rdoc_options: []
100
119
  require_paths:
@@ -113,5 +132,5 @@ requirements: []
113
132
  rubygems_version: 3.1.2
114
133
  signing_key:
115
134
  specification_version: 4
116
- summary: ''
135
+ summary: Ruby gem for use HTMX in Rails applications
117
136
  test_files: []
@@ -1,8 +0,0 @@
1
- require 'htmx/rails/version'
2
-
3
- module Htmx
4
- module Rails
5
- class Error < StandardError; end
6
- # Your code goes here...
7
- end
8
- end