async_futurize 0.1.7 → 0.1.12

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: ed68ea702cd2b3ca432fe496726747ffc52c1314d800e5998967ddf5c9325599
4
- data.tar.gz: 0c522ef619df3f448e070d97c9490ef34cb0df5abf09c9ae5efbf45a8d71e9d6
3
+ metadata.gz: d7f5e15a17cef1b822e92f47ff954c16dbaa3dee334dc71f814d6106a31e6427
4
+ data.tar.gz: 0e41f1295ce58e1545f26b8dbfd996cc2a1a51b585d763a6ee3665ed8045aec7
5
5
  SHA512:
6
- metadata.gz: 66071ab109ce2b949ceef4f616344507506682f30c81399caf643360adc65a12a6eb96d886d240ac3151a51b344152ebc31b7469ea6f387824f2400a0e9ba927
7
- data.tar.gz: 344032c74b582e203e13c9f0b3cb8014fa187454af4b4c15ad0e4d72bc1ad8ea4e713a71f3b8a07821d7c1994c9b629f45b8a18459ab3c7ed8e71acda9f4c382
6
+ metadata.gz: '054998df99628b7c151251a67b0d20f3a67eede2a7ca0e2445a5a16e735c829adc9fe34eefe5315e6f0bd49ab290985b574941bebf414a3f3ddb9527356d16a3'
7
+ data.tar.gz: 1fc6880c905aa36665003d03196814a604eaab54bdf6f7708b857ec30a8c2bd95dc9624a68ca31b30573440a5b62b4b206dc68cad416eec94dc78d26afe72bf9
@@ -0,0 +1,2 @@
1
+ class ApplicationController < ActionController::Base
2
+ end
@@ -1,4 +1,4 @@
1
- module async_futurize
1
+ module AsyncFuturize
2
2
  class FuturizeController < ApplicationController
3
3
  def loadComponent
4
4
  locals = { component: params[:component_to_load], component_params: params[:component_params] }
@@ -2,8 +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/futurize_controller.rb'
6
- require_relative '../app/javascript/packs/futurize.js'
5
+ require_relative '../app/controllers/async_futurize/futurize_controller.rb'
7
6
 
8
7
  module AsyncFuturize
9
8
  class Base
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module AsyncFuturize
4
- VERSION = "0.1.7"
4
+ VERSION = "0.1.12"
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.7
4
+ version: 0.1.12
5
5
  platform: ruby
6
6
  authors:
7
7
  - Ashesh Tuladhar
@@ -24,6 +24,7 @@ files:
24
24
  - LICENSE.txt
25
25
  - README.md
26
26
  - Rakefile
27
+ - app/controllers/applicaton_controller.rb
27
28
  - app/controllers/async_futurize/futurize_controller.rb
28
29
  - app/helpers/futurize_helper.rb
29
30
  - app/javascript/packs/futurize.js
@@ -35,6 +36,7 @@ files:
35
36
  - lib/async_futurize.rb
36
37
  - lib/async_futurize/engine.rb
37
38
  - lib/async_futurize/version.rb
39
+ - vendor/assets/javascripts/futurize.js
38
40
  homepage: https://gitlab.com/asheshtuldhar/async_futurize
39
41
  licenses:
40
42
  - MIT