styxie 0.0.4 → 0.0.5

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
  SHA1:
3
- metadata.gz: d6544120d5ab6bae640de6ea3daa9c084aca872d
4
- data.tar.gz: b2dc50ecec73907c0b77e01dcb5c1e40ac69da4c
3
+ metadata.gz: 90c7ee17c29d4526e2795924b267d7c681ce6dce
4
+ data.tar.gz: febe54bbe560e25049c0f754d891a81392462bd5
5
5
  SHA512:
6
- metadata.gz: ef3ce1b35d08cc70bca59dba9a89147bcf1ce53c8b24073b4f5a832a552de55c3c24ef04a988d6117ee969240737cb074061367a190ad141e2444a6a210a7e5f
7
- data.tar.gz: cc17cab622ae5ccd74ff07853770f5e639d9880895a7ccad7d586fdbfa5717706996b9a3ce20fa8b5a8ef67ba981ba81b4291b57f8cc21155b7f435908a93b2c
6
+ metadata.gz: ddb19ea59efb9ea4f3be9e733d9ae2cdfe6a3f0f6ab9d272ecee7630366d2138572aef9f6a171a4d0e9b8ed9c21c90bf5bc02d2e180a8912479ce5e128d753bf
7
+ data.tar.gz: 4a5e0820045fa111a4d94bf11297ad60214672a72c29bcb97142db57f289a75a00d79ca1874b920fb47d676d537c64f79a10184808bc8e24cb443844a91d6afd
@@ -1,3 +1,21 @@
1
- @Styxie = {
2
- Initializers: {}
3
- }
1
+ @Styxie ?= {}
2
+
3
+ @Styxie.Initializers = {}
4
+ @Styxie.initQueue ?= []
5
+
6
+ @Styxie.applyInitializer = (klass, method, json) ->
7
+ initializer = @Initializers[klass]
8
+ return unless initializer
9
+
10
+ if initializer.initialize
11
+ initializer.initialize(json)
12
+
13
+ if initializer[method]
14
+ initializer[method](json)
15
+
16
+ @Styxie.deferredInit = ->
17
+ @applyInitializer.apply(this, args) for args in @initQueue
18
+ @initQueue = []
19
+
20
+ @initStyxie = =>
21
+ @Styxie.deferredInit()
@@ -5,23 +5,22 @@ module Styxie
5
5
  cfg.merge! data
6
6
  end
7
7
 
8
- def styxie_initialize(klass: styxie_class, method: action_name, data: styxie_configuration, autorun: true)
8
+ def styxie_initialize(klass: styxie_class, method: action_name, data: styxie_configuration)
9
9
  json = data.to_json
10
- init_call = autorun ? 'initStyxie();' : ''
11
10
  result = <<-CODE
12
11
  <script type="text/javascript">
13
12
  //<![CDATA[
14
- function initStyxie() {
15
- if (Styxie.Initializers.#{klass} && Styxie.Initializers.#{klass}.initialize)
16
- {
17
- Styxie.Initializers.#{klass}.initialize(#{json});
13
+ if (typeof Styxie === 'undefined' || Styxie === null) {
14
+ Styxie = {}
15
+ }
16
+ if (Styxie.applyInitializer) {
17
+ Styxie.applyInitializer('#{klass}', '#{method}', #{json});
18
+ } else {
19
+ if (Styxie.initQueue == null) {
20
+ Styxie.initQueue = []
18
21
  }
19
- if (Styxie.Initializers.#{klass} && Styxie.Initializers.#{klass}['#{method}'])
20
- {
21
- Styxie.Initializers.#{klass}['#{method}'](#{json});
22
- }
23
- };
24
- #{init_call}
22
+ Styxie.initQueue.push(['#{klass}', '#{method}', #{json}]);
23
+ }
25
24
  //]]>
26
25
  </script>
27
26
  CODE
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Styxie
4
- VERSION = '0.0.4'.freeze
4
+ VERSION = '0.0.5'.freeze
5
5
  end
@@ -6,7 +6,6 @@ describe TestsController, type: :controller do
6
6
 
7
7
  it 'index' do
8
8
  get :index
9
- response.body.should have_content('Styxie.Initializers.Tests.initialize({"data":"test"})')
10
- response.body.should have_content('Styxie.Initializers.Tests[\'index\']({"data":"test"})')
9
+ response.body.should have_content("Styxie.applyInitializer('Tests', 'index', {\"data\":\"test\"})")
11
10
  end
12
11
  end
@@ -21,8 +21,7 @@ describe Styxie::Initializer do
21
21
  controller.stub(controller_path: 'module/tests')
22
22
  controller.stub(action_name: 'index')
23
23
  result = controller.styxie_initialize
24
- expect(result).to include "Styxie.Initializers.ModuleTests['index']({});"
25
- expect(result).to include "initStyxie();"
24
+ expect(result).to include "Styxie.applyInitializer('ModuleTests', 'index', {});"
26
25
  expect(result.html_safe?).to be_truthy
27
26
  end
28
27
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: styxie
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.4
4
+ version: 0.0.5
5
5
  platform: ruby
6
6
  authors:
7
7
  - Yury Kotov
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2016-10-20 00:00:00.000000000 Z
12
+ date: 2016-10-24 00:00:00.000000000 Z
13
13
  dependencies: []
14
14
  description: Set of helpers to maintain bridge between Server side and Client (JS)
15
15
  side