execjs-rails 0.2.0 → 0.2.2

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: 13baa96c905289df74bd792075fe68247cca449f
4
- data.tar.gz: e9f643027d317dc5ad2880b998f665a0168b2bde
3
+ metadata.gz: d4fb0466c220cc5c0bef04fcac4e682253cc6416
4
+ data.tar.gz: 0d4a84f8a5a1261447498ac767041b7574232507
5
5
  SHA512:
6
- metadata.gz: 1cae5c8f05eaabaadaca2fd5585f241f71277bf46692bb88f7e7896815ed1327d87efa09b12a8ea6e95711aa3f4dd68c9783baf753343030ca39022d78c53214
7
- data.tar.gz: aa48ece2645aa3ffa5a8c8b2aa2c0758fe188c9ba812ee7c56225391f35dadd2ac903e55ec892bd5b7502947c17bc45ca65b65383814799009cf1434b635b067
6
+ metadata.gz: bcd030d36fff24f40570e6b72f839a5fea1f351e14f377687d67b14e5267c4530e701064621595ad74c3f452ee27a849b5d470880e34917b53a6a87caaed95e3
7
+ data.tar.gz: c22f72115e27d4f701fa45adc018c9b8646af1f3c0dcaebbf38a426d012c22d84a1eeed9f6883e18c746d5f31ec7bb9996545a6f74b6bb1413e8e084b440098d
data/lib/execjs/rails.rb CHANGED
@@ -1,5 +1,6 @@
1
1
  require 'execjs/rails/engine'
2
2
  require 'execjs/rails/renderer'
3
+ require 'execjs/rails/runtime_support'
3
4
  require 'execjs/rails/view_helper'
4
5
  require 'execjs/rails/concern'
5
6
  require 'execjs/rails/template_resolver'
@@ -18,6 +18,22 @@ module ExecJS
18
18
  }).merge!(options.stringify_keys).to_json
19
19
  end
20
20
 
21
+ config.execjs_rails.debug_dump_prefix = <<-JS
22
+ /*
23
+ * Unwrap this if node-inspector attempts to put it in an extra module
24
+ * Note: other things that are wrapped in module should work the same.
25
+ * This only addresses the automatic wrapping of the global scope in an
26
+ * additional module by node-inspector.
27
+ */
28
+ if (typeof module != 'undefined') {
29
+ module = undefined;
30
+ if (typeof exports != 'undefined') {
31
+ exports = undefined;
32
+ }
33
+ arguments.callee.bind(global)(exports, require, module, __filename, __dirname)
34
+ }
35
+ JS
36
+
21
37
  initializer "execjs_rails.setup_view_helpers" do
22
38
  ActiveSupport.on_load(:action_view) do
23
39
  include ViewHelper
@@ -7,7 +7,6 @@ module ExecJS
7
7
 
8
8
  def self.setup!(config = {})
9
9
  @@config = config
10
- self.reset!
11
10
  end
12
11
 
13
12
  def self.config
@@ -18,18 +17,19 @@ module ExecJS
18
17
  unless @@config.memoize_context? && !@@context.nil?
19
18
  begin
20
19
  @@context = ExecJS.compile(@@config.build_source.call())
21
- rescue V8::Error => error
20
+ rescue ExecJS::Rails::RuntimeSupport.error_class => error
22
21
  @@config.on_error.call(error)
23
22
  end
24
23
  end
25
24
  end
26
25
 
27
26
  def self.call(function, *args)
27
+ self.reset! unless @@context
28
28
  @@context.call(function, *args)
29
29
  end
30
30
 
31
31
  def self.has_view(path)
32
- @@context.call(@@config.has_view_function_name, path)
32
+ self.call(@@config.has_view_function_name, path)
33
33
  end
34
34
 
35
35
  def self.render(path, opts = {})
@@ -38,6 +38,14 @@ module ExecJS
38
38
  output.html_safe
39
39
  end
40
40
 
41
+ def self.dump_render_context(path, assigns, options={})
42
+ source = @@config.debug_dump_prefix + @@config.build_source.call() + "; #{ @@config.handler_function_name }('#{ path }', '#{ options }');"
43
+ file = File.open(assigns['__execjs_rails_dump_file'], 'w')
44
+ file.write(source)
45
+ file.close()
46
+ puts "Wrote render context dump to #{ file.path }. If you have node-inspector installed, you can debug it with: "
47
+ puts "node-debug #{ file.path }"
48
+ end
41
49
  end
42
50
  end
43
51
  end
@@ -0,0 +1,32 @@
1
+ require 'execjs'
2
+
3
+ # Utilities which we use to handle differences between various execjs runtimes
4
+ module ExecJS::Rails::RuntimeSupport
5
+ # This should never actually be thrown, it is just a way to keep our rescue
6
+ # blocks valid when there is no runtime configured. This way, rather than
7
+ # getting a mysterious 'class or module required for rescue clause' error,
8
+ # we get the good 'Could not find a JavaScript runtime.' error.
9
+ class DisabledError < ::StandardError; end
10
+
11
+ def self.using_runtime(klass)
12
+ ExecJS::Runtimes.autodetect.class == klass
13
+ end
14
+
15
+ def self.using_v8
16
+ using_runtime(ExecJS::RubyRacerRuntime)
17
+ end
18
+
19
+ def self.using_rhino
20
+ using_runtime(ExecJS::RubyRhinoRuntime)
21
+ end
22
+
23
+ def self.error_class
24
+ if using_v8
25
+ V8::Error
26
+ elsif using_rhino
27
+ Rhino::JSError
28
+ else
29
+ DisabledError
30
+ end
31
+ end
32
+ end
@@ -1,5 +1,5 @@
1
1
  module ExecJS
2
2
  module Rails
3
- VERSION = '0.2.0'
3
+ VERSION = '0.2.2'
4
4
  end
5
5
  end
@@ -7,9 +7,12 @@ module ExecJS
7
7
  end
8
8
 
9
9
  def execjs_render(path, opts = {})
10
- Renderer.render(path, Renderer.config.view_to_function_options.call(self, opts))
10
+ view_opts = Renderer.config.view_to_function_options.call(self, opts)
11
+ if self.assigns.has_key?('__execjs_rails_dump_file')
12
+ Renderer.dump_render_context(path, self.assigns, view_opts)
13
+ end
14
+ Renderer.render(path, view_opts)
11
15
  end
12
-
13
16
  end
14
17
  end
15
18
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: execjs-rails
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.0
4
+ version: 0.2.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Revelry Labs, LLC
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-02-24 00:00:00.000000000 Z
11
+ date: 2015-04-17 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: execjs
@@ -49,6 +49,7 @@ files:
49
49
  - lib/execjs/rails/concern.rb
50
50
  - lib/execjs/rails/engine.rb
51
51
  - lib/execjs/rails/renderer.rb
52
+ - lib/execjs/rails/runtime_support.rb
52
53
  - lib/execjs/rails/template_resolver.rb
53
54
  - lib/execjs/rails/version.rb
54
55
  - lib/execjs/rails/view_helper.rb