Module: Xray
- Defined in:
- lib/xray-rails.rb,
lib/xray/config.rb,
lib/xray/engine.rb,
lib/xray/version.rb,
lib/xray/aliasing.rb,
lib/xray/middleware.rb
Defined Under Namespace
Modules: Aliasing Classes: Config, Engine, Middleware
Constant Summary collapse
- FILE_PLACEHOLDER =
'$file'
- VERSION =
"0.3.3".freeze
- OPEN_PATH =
'/_xray/open'
- UPDATE_CONFIG_PATH =
'/_xray/config'
Class Method Summary collapse
-
.augment_template(source, path) ⇒ Object
Returns augmented HTML where the source is simply wrapped in an HTML comment with filepath info.
- .config ⇒ Object
- .next_id ⇒ Object
- .open_file(file) ⇒ Object
-
.request_info ⇒ Object
Used to collect request information during each request cycle for use in the Xray bar.
Class Method Details
.augment_template(source, path) ⇒ Object
Returns augmented HTML where the source is simply wrapped in an HTML comment with filepath info. Xray.js uses these comments to associate elements with the templates that rendered them.
This:
<div class=".my-element">
...
</div>
Becomes:
<!-- XRAY START 123 /path/to/file.html -->
<div class=".my-element">
...
</div>
<!-- XRAY END 123 -->
36 37 38 39 40 41 42 43 44 45 46 47 48 |
# File 'lib/xray-rails.rb', line 36 def self.augment_template(source, path) id = next_id if source.include?('<!DOCTYPE') return source end # skim doesn't allow html comments, so use skim's comment syntax if it's skim if path =~ /\.(skim|hamlc)(\.|$)/ augmented = "/!XRAY START #{id} #{path}\n#{source}\n/!XRAY END #{id}" else augmented = "<!--XRAY START #{id} #{path}-->\n#{source}\n<!--XRAY END #{id}-->" end ActiveSupport::SafeBuffer === source ? ActiveSupport::SafeBuffer.new(augmented) : augmented end |
.config ⇒ Object
3 4 5 |
# File 'lib/xray/config.rb', line 3 def self.config @@config ||= Config.new end |
.next_id ⇒ Object
50 51 52 |
# File 'lib/xray-rails.rb', line 50 def self.next_id @id = (@id ||= 0) + 1 end |
.open_file(file) ⇒ Object
54 55 56 57 58 59 60 61 62 |
# File 'lib/xray-rails.rb', line 54 def self.open_file(file) editor = Xray.config.editor cmd = if editor.include?('$file') editor.gsub '$file', file else "#{editor} \"#{file}\"" end Open3.capture3(cmd) end |
.request_info ⇒ Object
Used to collect request information during each request cycle for use in the Xray bar.
17 18 19 |
# File 'lib/xray-rails.rb', line 17 def self.request_info Thread.current[:request_info] ||= {} end |