xray-rails 0.1.16 → 0.1.17

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: 9d3871d067a87b49c62b791a5c9d024ee00ea3ac
4
- data.tar.gz: 592adbcc6c0975e1df1e7411986854f6b68bd02c
3
+ metadata.gz: 1ab0151106aea3b79331261ace9df12dfa45076d
4
+ data.tar.gz: b2994a45e8fda3d0e1db9e7558eb153996386ca0
5
5
  SHA512:
6
- metadata.gz: f04e57f1a7f9922c997b89c45e5b5d370553f58892cf05e9171617a559475c8ffa9d0e0172abf0f2458da3bab0695debe505357da89efffb842fab262cbfb0d8
7
- data.tar.gz: c3386c3905b7ced7ba04d9c4673e440a934f61e7ff6cde82fd789c451fb337b72727d167fc11332177dbf3f0d63ef4fbb4d6eb6e4a65e42f5b23e57b3c4506aa
6
+ metadata.gz: db9788224693472e9144b1569aa7a8d502d989df31557861c1ad51992e6724642d94f59af7341827a70ebddf8e374496e58b941ecb6dd3431330227adc012c1b
7
+ data.tar.gz: 246519cd7958eef5123b50eb611fd9d709bd1c53d1420aa6c2c61e2d3e3bb07aba97de79dc758cc463e633619e388721e0e9c61559355af7f85d4288673cf7ed
data/lib/xray-rails.rb CHANGED
@@ -13,9 +13,8 @@ module Xray
13
13
 
14
14
  # Used to collect request information during each request cycle for use in
15
15
  # the Xray bar.
16
- # TODO: there's nothing thread-safe about this. Not sure how big of a deal that is.
17
16
  def self.request_info
18
- @request_info ||= {}
17
+ Thread.current[:request_info] ||= {}
19
18
  end
20
19
 
21
20
  # Patterns for the kind of JS constructors Xray is interested in knowing the
@@ -85,7 +84,7 @@ module Xray
85
84
  return source
86
85
  end
87
86
  # skim doesn't allow html comments, so use skim's comment syntax if it's skim
88
- if path =~ /\.(skim)(\.|$)/
87
+ if path =~ /\.(skim|hamlc)(\.|$)/
89
88
  augmented = "/!XRAY START #{id} #{path}\n#{source}\n/!XRAY END #{id}"
90
89
  else
91
90
  augmented = "<!--XRAY START #{id} #{path}-->\n#{source}\n<!--XRAY END #{id}-->"
data/lib/xray/engine.rb CHANGED
@@ -30,9 +30,16 @@ module Xray
30
30
  ActionView::Template.class_eval do
31
31
  def render_with_xray(*args, &block)
32
32
  path = identifier
33
+ view = args.first
33
34
  source = render_without_xray(*args, &block)
34
- suitable_template = path =~ /\.(html|slim|haml)(\.|$)/ && !path.match(/\.(js|json|css)\./) && !path.include?('_xray_bar')
35
+
36
+ suitable_template = !(view.respond_to?(:mailer) && view.mailer) &&
37
+ !path.include?('_xray_bar') &&
38
+ path =~ /\.(html|slim|haml|hamlc)(\.|$)/ &&
39
+ path !~ /\.(js|json|css)(\.|$)/
40
+
35
41
  options = args.last.kind_of?(Hash) ? args.last : {}
42
+
36
43
  if suitable_template && !(options.has_key?(:xray) && (options[:xray] == false))
37
44
  Xray.augment_template(source, path)
38
45
  else
@@ -61,8 +68,6 @@ module Xray
61
68
  action_name = event.payload[:action]
62
69
  path = ActiveSupport::Dependencies.search_for_file(controller_name.underscore)
63
70
 
64
- # Reset the request info hash for this request.
65
- # NOTE: Nothing about this is thread-safe. Could this affect anyone in dev mode?
66
71
  Xray.request_info.clear
67
72
 
68
73
  Xray.request_info[:controller] = {
@@ -32,18 +32,30 @@ module Xray
32
32
  res.status = 400
33
33
  end
34
34
  res.finish
35
+
35
36
  # Inject xray.js and friends if this is a successful HTML response
36
37
  else
37
38
  status, headers, response = @app.call(env)
38
39
 
39
40
  if html_headers?(status, headers) && body = response_body(response)
40
- body = body.sub(/<body[^>]*>/) { "#{$~}\n#{xray_bar(response)}" }
41
- # Inject js script tags if assets are unbundled
42
- if Rails.application.config.assets.debug
43
- append_js!(body, 'jquery', 'xray')
44
- append_js!(body, 'backbone', 'xray-backbone')
41
+ if body =~ script_matcher('xray')
42
+ # Inject the xray bar if xray.js is already on the page
43
+ inject_xray_bar!(body)
44
+ elsif Rails.application.config.assets.debug
45
+ # Otherwise try to inject xray.js if assets are unbundled
46
+ if append_js!(body, 'jquery', 'xray')
47
+ append_js!(body, 'backbone', 'xray-backbone')
48
+ inject_xray_bar!(body)
49
+ end
45
50
  end
51
+
46
52
  content_length = body.bytesize.to_s
53
+
54
+ # For rails v4.2.0+ compatibility
55
+ if defined?(ActionDispatch::Response::RackBody) && ActionDispatch::Response::RackBody === response
56
+ response = response.instance_variable_get(:@response)
57
+ end
58
+
47
59
  # Modifying the original response obj maintains compatibility with other middlewares
48
60
  if ActionDispatch::Response === response
49
61
  response.body = [body]
@@ -61,22 +73,24 @@ module Xray
61
73
 
62
74
  private
63
75
 
64
- def xray_bar(response)
76
+ def inject_xray_bar!(html)
77
+ html.sub!(/<body[^>]*>/) { "#{$~}\n#{render_xray_bar}" }
78
+ end
79
+
80
+ def render_xray_bar
65
81
  ac = ActionController::Base.new
66
- ac.request = response.request if response.respond_to?(:request)
67
82
  ac.render_to_string(:partial => '/xray_bar').html_safe
68
83
  end
69
84
 
70
- # Appends the given `script_name` after the `after_script_name`.
71
- def append_js!(html, after_script_name, script_name)
72
- # Matches:
73
- # <script src="/assets/jquery.js"></script>
74
- # <script src="/assets/jquery-min.js"></script>
75
- # <script src="/assets/jquery.min.1.9.1.js"></script>
76
- # <script src="/assets/jquery.min.1.9.1-89255b9dbf3de2fbaa6754b3a00db431.js"></script>
77
- script_pattern = /
85
+ # Matches:
86
+ # <script src="/assets/jquery.js"></script>
87
+ # <script src="/assets/jquery-min.js"></script>
88
+ # <script src="/assets/jquery.min.1.9.1.js"></script>
89
+ # <script src="/assets/jquery.min.1.9.1-89255b9dbf3de2fbaa6754b3a00db431.js"></script>
90
+ def script_matcher(script_name)
91
+ /
78
92
  <script[^>]+
79
- \/#{after_script_name} # Name of the script itself
93
+ \/#{script_name}
80
94
  ([-.]{1}[\d\.]+)? # Optional version identifier (e.g. -1.9.1)
81
95
  ([-.]{1}min)? # Optional -min suffix
82
96
  (\.self)? # Sprockets 3 appends .self to the filename
@@ -84,12 +98,19 @@ module Xray
84
98
  \.js # Must have .js extension
85
99
  [^>]+><\/script>
86
100
  /x
87
- html.sub!(script_pattern) do
88
- h = ActionController::Base.helpers
89
- "#{$~}\n" + h.javascript_include_tag(script_name)
101
+ end
102
+
103
+ # Appends the given `script_name` after the `after_script_name`.
104
+ def append_js!(html, after_script_name, script_name)
105
+ html.sub!(script_matcher(after_script_name)) do
106
+ "#{$~}\n" + helper.javascript_include_tag(script_name)
90
107
  end
91
108
  end
92
109
 
110
+ def helper
111
+ ActionController::Base.helpers
112
+ end
113
+
93
114
  def html_headers?(status, headers)
94
115
  status == 200 &&
95
116
  headers['Content-Type'] &&
data/lib/xray/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module Xray
2
- VERSION = "0.1.16"
2
+ VERSION = "0.1.17"
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: xray-rails
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.16
4
+ version: 0.1.17
5
5
  platform: ruby
6
6
  authors:
7
7
  - Brent Dillingham
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-05-09 00:00:00.000000000 Z
11
+ date: 2015-10-18 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rails
@@ -189,7 +189,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
189
189
  version: '0'
190
190
  requirements: []
191
191
  rubyforge_project:
192
- rubygems_version: 2.4.6
192
+ rubygems_version: 2.4.5
193
193
  signing_key:
194
194
  specification_version: 4
195
195
  summary: Reveal the structure of your UI