async_futurize 0.1.6 → 0.1.11

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: cd71a8d83c8a3ab22bb892708acb06efe71e6683eee5ad1c06cb1d9446f250c9
4
- data.tar.gz: 6e969d0882d5238221a051789563ffa638748eb1633e7989eb0d1fe57a24e6cb
3
+ metadata.gz: 86b609afd7ae960588a5e6abfe7726a4d1fe49167775e751f1dbcb5abfced1a9
4
+ data.tar.gz: 847b036f3275fb1b177c0e8113b34c81e12d2498f5109524cd74f561e478ebdf
5
5
  SHA512:
6
- metadata.gz: 276ac0e512ee0382b5701c663e285efb34cb988ef283e3d065ca71386d71a7b0341c116560fb1ef907ba2dd02dba2adbf00b4c71b4412eb347a3429141b087c2
7
- data.tar.gz: 485e0325bdbf0c381d09bbab2d0a79766013727996c6310430039de1e6863c1815be9e640795bfc869934d240f421144f3609909d701878efac45986085fe0f5
6
+ metadata.gz: 128fce6cbde1c4608d55379de82c1539cb2c00defd904741b46efd5697a4fadd1cbfcd7e057864a1c4bf3b24d3d44434abdc2e1ca05dee4d61de22dc2da1d90b
7
+ data.tar.gz: d2c0867acfd3f32114633d64be844c58f729cf0bded44ea40ebf48a4eea658004836ac0e69b2fdeeaae26545122ad1614b832523337622342a06c14ceb7b1dc8
@@ -1,9 +1,7 @@
1
- module async_futurize
2
- class FuturizeController < ApplicationController
3
- def loadComponent
4
- locals = { component: params[:component_to_load], component_params: params[:component_params] }
5
- render json: { component: params[:component_to_load], html: render_to_string(partial: './futurize_component_ajax', locals: locals) }
6
- end
7
- end
1
+ class FuturizeController < ApplicationController
2
+ def loadComponent
3
+ locals = { component: params[:component_to_load], component_params: params[:component_params] }
4
+ render json: { component: params[:component_to_load], html: render_to_string(partial: './futurize_component_ajax', locals: locals) }
5
+ end
8
6
  end
9
7
 
@@ -2,6 +2,7 @@
2
2
 
3
3
  require_relative "async_futurize/version"
4
4
  require_relative '../app/helpers/futurize_helper.rb'
5
+ require_relative '../app/controllers/async_futurize/futurize_controller.rb'
5
6
 
6
7
  module AsyncFuturize
7
8
  class Base
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module AsyncFuturize
4
- VERSION = "0.1.6"
4
+ VERSION = "0.1.11"
5
5
  end
@@ -0,0 +1,50 @@
1
+ global.FuturizeComponent = {
2
+ init: function (css_selector) {
3
+ var obj = document.querySelectorAll(css_selector);
4
+ for (var i in obj) {
5
+ if (obj.hasOwnProperty(i)) {
6
+ //console.log(obj[i].getAttribute('data-futurize-component'));
7
+ this.load_component(obj[i])
8
+ }
9
+ }
10
+ },
11
+
12
+ reload: function(css_selector) {
13
+ document.querySelectorAll(css_selector).forEach(function(o) {
14
+ o.innerHTML = ""
15
+ })
16
+ },
17
+
18
+ load_component: function (obj) {
19
+ var component_name = obj.getAttribute('data-futurize-component'),
20
+ component_params = obj.getAttribute('data-futurize-params');
21
+
22
+ if (obj.innerHTML.trim().length <= 0) {
23
+ obj.innerHTML = 'Loading....';
24
+ }
25
+
26
+ var AUTH_TOKEN = document.querySelector('meta[name=csrf-token]').getAttribute('content');
27
+ fetch('/home/loadComponent', {
28
+ mode: 'same-origin',
29
+ method: 'POST',
30
+ dataType: 'json',
31
+ body : JSON.stringify({ component_to_load: component_name, component_params: component_params }),
32
+ headers: {
33
+ 'Content-Type': 'application/json',
34
+ 'X-CSRF-Token' : AUTH_TOKEN,
35
+ },
36
+ })
37
+ .then(response => response.json())
38
+ .then(data => {
39
+ obj.innerHTML = data.html
40
+ obj.querySelectorAll("script").forEach(function(o) {
41
+ eval(o.innerHTML)
42
+ })
43
+ }).catch((error) => {
44
+ console.error('Error:', error);
45
+ });
46
+ }
47
+ }
48
+ document.addEventListener('DOMContentLoaded', function () {
49
+ FuturizeComponent.init('[data-futurize-component]');
50
+ })
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: async_futurize
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.6
4
+ version: 0.1.11
5
5
  platform: ruby
6
6
  authors:
7
7
  - Ashesh Tuladhar
@@ -35,6 +35,7 @@ files:
35
35
  - lib/async_futurize.rb
36
36
  - lib/async_futurize/engine.rb
37
37
  - lib/async_futurize/version.rb
38
+ - vendor/assets/javascripts/futurize.js
38
39
  homepage: https://gitlab.com/asheshtuldhar/async_futurize
39
40
  licenses:
40
41
  - MIT