js_hooks 0.0.3 → 0.0.4

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: ed796bb1ef7a3195e6dfe768399a0e485f72a948
4
- data.tar.gz: 743199649e19c1e99cad4553d8f5b415b891b121
3
+ metadata.gz: e44f33d61860583889ff81d254d23e6f704b9dd5
4
+ data.tar.gz: 2530881e8a52aad465ea7be1d552ce8ee3c80632
5
5
  SHA512:
6
- metadata.gz: 5a8d8b4bcc27f55bf1d1fdfba0b11b9ec1eade13fb835a0278de4e2552622215feaa263fdd84e1f6173fea5c3886062dd5e0017d03c45fe8ad78463a9dfbdb15
7
- data.tar.gz: 2b2bc1abc59cd77487dc5db8473660680c10c46516a85edae0f915a18bc400e58c8ecb6d552cfe89ff8c8d51e42c81f47ebadeb76bf9b7a45cdff44b471b2895
6
+ metadata.gz: 3093586057e1e0f15f6d4d716ff63ca3976abf8e8087c4d2b923fe102911a4c92f5084572cb4037be697dde6430b0aaee0f7eecad76c7f00a05c772f89ee736b
7
+ data.tar.gz: d2443eb2d2748f75a5c1c781be278ec1fe75b4b00b6b858927012d5f066c3cf25ec097c354c026fc1dcf53317ad84d1a360c38973056e4859dfa223fe3777009
@@ -11,7 +11,7 @@ module JsHooks
11
11
 
12
12
  include JsHooks::Controller::LocalInstanceMethods
13
13
 
14
- helper_method :js_hooks, :add_js_hook
14
+ helper_method :js_hooks, :add_js_hook, :js_hooks_initializers, :add_js_hook_initializer
15
15
  end
16
16
  end
17
17
 
@@ -21,6 +21,10 @@ module JsHooks
21
21
  @js_hooks ||= {}
22
22
  end
23
23
 
24
+ def js_hooks_initializers
25
+ @js_hooks_initializers ||= []
26
+ end
27
+
24
28
  # Add javascript components to execute inside a document ready jquery closure before the body close tag in your
25
29
  # templates. For each hook added, an object with the same name is searched and the init method is called.
26
30
  # A suffix can be used with the init method to refine the initialization process:
@@ -73,6 +77,15 @@ module JsHooks
73
77
  end
74
78
  end
75
79
 
80
+ # Adds JS code to execute after all hooks are defined but before they are initialized.
81
+ #
82
+ # <% add_js_hook_initializer do %>
83
+ # window.JsHooks.Users.myInitMethod();
84
+ # <% end %>
85
+ def add_js_hook_initializer(initializer)
86
+ self.js_hooks_initializers << initializer if initializer
87
+ end
88
+
76
89
  private
77
90
  def add_default_js_hooks
78
91
  add_js_hook :application
@@ -6,6 +6,7 @@ module JsHooks
6
6
  window.JsHooks = window.JsHooks || {};
7
7
  window.JsHooks.namespace = '.#{Rails.application.class.to_s.split('::').first}';
8
8
  window.JsHooks.hooks = #{js_hooks.to_json};
9
+ #{js_hooks_initializers.join(";\n")}
9
10
  JS
10
11
  end
11
12
  end
@@ -1,3 +1,3 @@
1
1
  module Jshooks
2
- VERSION = '0.0.3'
2
+ VERSION = '0.0.4'
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: js_hooks
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.3
4
+ version: 0.0.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - Francisco R. Santos
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-03-24 00:00:00.000000000 Z
11
+ date: 2014-05-22 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rails