├── .gitignore ├── .travis.yml ├── CHANGELOG.md ├── Gemfile ├── LICENSE ├── README.md ├── Rakefile ├── app ├── assets │ ├── javascripts │ │ ├── xray.js │ │ └── xray.js.coffee │ └── stylesheets │ │ └── xray.css └── views │ └── _xray_bar.html.erb ├── example └── screenshot.png ├── lib ├── xray-rails.rb └── xray │ ├── aliasing.rb │ ├── config.rb │ ├── engine.rb │ ├── middleware.rb │ └── version.rb ├── script └── server ├── spec ├── dummy │ ├── README.rdoc │ ├── Rakefile │ ├── app │ │ ├── assets │ │ │ ├── javascripts │ │ │ │ └── application.js │ │ │ └── stylesheets │ │ │ │ └── application.css │ │ ├── controllers │ │ │ └── application_controller.rb │ │ ├── helpers │ │ │ └── application_helper.rb │ │ ├── mailer_previews │ │ │ └── test_mailer_preview.rb │ │ ├── mailers │ │ │ ├── .gitkeep │ │ │ └── test_mailer.rb │ │ ├── models │ │ │ └── .gitkeep │ │ └── views │ │ │ ├── application │ │ │ ├── _simple_partial.html.erb │ │ │ ├── made_with_haml.json.haml │ │ │ └── root.html.erb │ │ │ ├── layouts │ │ │ └── application.html.erb │ │ │ └── test_mailer │ │ │ └── hello.html.erb │ ├── config.ru │ ├── config │ │ ├── application.rb │ │ ├── boot.rb │ │ ├── database.yml │ │ ├── environment.rb │ │ ├── environments │ │ │ ├── development.rb │ │ │ ├── production.rb │ │ │ └── test.rb │ │ ├── initializers │ │ │ ├── backtrace_silencers.rb │ │ │ ├── inflections.rb │ │ │ ├── mime_types.rb │ │ │ ├── secret_token.rb │ │ │ ├── session_store.rb │ │ │ └── wrap_parameters.rb │ │ ├── locales │ │ │ └── en.yml │ │ └── routes.rb │ ├── db │ │ └── .gitkeep │ ├── log │ │ └── .gitkeep │ ├── public │ │ ├── 404.html │ │ ├── 422.html │ │ ├── 500.html │ │ └── favicon.ico │ └── script │ │ └── rails ├── spec_helper.rb └── xray │ ├── augmentation_spec.rb │ ├── command_spec.rb │ ├── config_spec.rb │ ├── engine_spec.rb │ ├── middleware_spec.rb │ └── xray_bar_spec.rb └── xray-rails.gemspec /.gitignore: -------------------------------------------------------------------------------- 1 | .DS_Store 2 | *.gem 3 | *.rbc 4 | .bundle 5 | .config 6 | .yardoc 7 | Gemfile.lock 8 | InstalledFiles 9 | _yardoc 10 | coverage 11 | doc/ 12 | lib/bundler/man 13 | pkg 14 | rdoc 15 | spec/reports 16 | test/tmp 17 | test/version_tmp 18 | tmp 19 | spec/dummy/db/*.sqlite3 20 | spec/dummy/log/*.log 21 | spec/dummy/tmp/ 22 | spec/dummy/.sass-cache 23 | -------------------------------------------------------------------------------- /.travis.yml: -------------------------------------------------------------------------------- 1 | language: ruby 2 | cache: 3 | - bundler 4 | env: 5 | global: 6 | - RAILS_ENV=development 7 | matrix: 8 | include: 9 | - rvm: 2.1 10 | env: RAILS_VERSION="~> 4.2.7" 11 | - rvm: 2.2 12 | env: RAILS_VERSION="~> 4.2.7" 13 | - rvm: 2.2 14 | env: RAILS_VERSION="~> 5.0.0" 15 | - rvm: 2.3.3 16 | env: RAILS_VERSION="~> 4.2.7" 17 | - rvm: 2.3.3 18 | env: RAILS_VERSION="~> 5.0.0" 19 | - rvm: 2.4.0 20 | env: RAILS_VERSION="~> 5.0.0" 21 | before_install: gem install bundler -v "~> 1.17" --no-document 22 | -------------------------------------------------------------------------------- /CHANGELOG.md: -------------------------------------------------------------------------------- 1 | # xray-rails Change Log 2 | 3 | All notable changes to this project will be documented in this file. 4 | 5 | xray-rails is in a pre-1.0 state. This means that its APIs and behavior are 6 | subject to breaking changes without deprecation notices. Until 1.0, version 7 | numbers will follow a [Semver][]-ish `0.y.z` format, where `y` is incremented 8 | when new features or breaking changes are introduced, and `z` is incremented for 9 | lesser changes or bug fixes. 10 | 11 | ## [Unreleased][] 12 | 13 | * Your contribution here! 14 | 15 | ## [0.3.2][] (2019-03-16) 16 | 17 | * Gracefully handle nil templates 18 | [#96](https://github.com/brentd/xray-rails/pull/96) 19 | 20 | ## [0.3.1][] (2017-06-16) 21 | 22 | * Include xray.js when using jQuery3 23 | [#84](https://github.com/brentd/xray-rails/pull/84) 24 | 25 | ## [0.3.0][] (2017-04-28) 26 | 27 | * Remove `alias_method_chain` and make xray-rails compatible with Rails 5.1. 28 | 29 | ## [0.2.0][] (2016-09-23) 30 | 31 | * Removed support for Backbone-rendered templates. This feature was particularly 32 | complex and prone to failure. It will more than likely return in some form in 33 | the future - for now, if your workflow depends on it, don't upgrade to 0.2.0. 34 | * Removed the dependency on coffee-rails. 35 | * Fixed deprecation warnings from Sprockets 4. 36 | 37 | ## [0.1.23][] (2016-09-23) 38 | 39 | * Add a post-install message regarding future removal of Backbone support. 40 | 41 | ## [0.1.22][] (2016-09-08) 42 | 43 | * If you have not explicitly set an editor, xray-rails now chooses a default 44 | editor by using the following environment variables: `GEM_EDITOR`, `VISUAL`, 45 | and `EDITOR`. To explicitly set the editor, use `~/.xrayconfig` as explained 46 | in the [configuration section](https://github.com/brentd/xray-rails#configuration) 47 | of the README. 48 | 49 | ## [0.1.21][] (2016-05-21) 50 | 51 | * Fix a regression in 0.1.20 that broke Rails 3.2 apps 52 | [#72](https://github.com/brentd/xray-rails/pull/72) 53 | 54 | ## [0.1.20][] (2016-05-18) 55 | 56 | * Added support for Rails 5.0.0.rc1. 57 | [#70](https://github.com/brentd/xray-rails/pull/70) 58 | 59 | ## [0.1.19][] (2016-05-06) 60 | 61 | * Previous releases of xray-rails had a file permissions issue that caused a 62 | "can't load lib/xray/middleware" error on some systems. This should now be 63 | fixed. [#59](https://github.com/brentd/xray-rails/pull/59) 64 | * The xray-rails JavaScript is now properly injected after `jquery2`. This means 65 | that projects using jQuery2 should now work with xray-rails out of the box. 66 | [#64](https://github.com/brentd/xray-rails/pull/64) @nextekcarl 67 | 68 | ## [0.1.18][] (2016-01-11) 69 | 70 | * xray-rails is now compatible with sprockets-rails 3.0 71 | [#62](https://github.com/brentd/xray-rails/pull/62) @mattbrictson 72 | 73 | ## [0.1.17][] (2015-10-18) 74 | 75 | * Will no longer attempt to augment mailer templates 76 | * Added hamlc as a supported template (hopefully; needs testing) 77 | * Made the middleware smarter about when to inject xray.js and the bar partial 78 | 79 | ## [0.1.16][] (2015-05-09) 80 | 81 | * Add support for sprockets 3.0 82 | [#56](https://github.com/brentd/xray-rails/pull/56) @mattbrictson 83 | 84 | 85 | [Semver]: http://semver.org 86 | [Unreleased]: https://github.com/brentd/xray-rails/compare/v0.3.2...HEAD 87 | [0.3.2]: https://github.com/brentd/xray-rails/compare/v0.3.1...v0.3.2 88 | [0.3.1]: https://github.com/brentd/xray-rails/compare/v0.3.0...v0.3.1 89 | [0.3.0]: https://github.com/brentd/xray-rails/compare/v0.2.0...v0.3.0 90 | [0.2.0]: https://github.com/brentd/xray-rails/compare/v0.1.23...v0.2.0 91 | [0.1.23]: https://github.com/brentd/xray-rails/compare/v0.1.22...v0.1.23 92 | [0.1.22]: https://github.com/brentd/xray-rails/compare/v0.1.21...v0.1.22 93 | [0.1.21]: https://github.com/brentd/xray-rails/compare/v0.1.20...v0.1.21 94 | [0.1.20]: https://github.com/brentd/xray-rails/compare/v0.1.19...v0.1.20 95 | [0.1.19]: https://github.com/brentd/xray-rails/compare/v0.1.18...v0.1.19 96 | [0.1.18]: https://github.com/brentd/xray-rails/compare/v0.1.17...v0.1.18 97 | [0.1.17]: https://github.com/brentd/xray-rails/compare/v0.1.16...v0.1.17 98 | [0.1.16]: https://github.com/brentd/xray-rails/compare/v0.1.15...v0.1.16 99 | -------------------------------------------------------------------------------- /Gemfile: -------------------------------------------------------------------------------- 1 | source 'https://rubygems.org' 2 | gemspec 3 | 4 | gem 'rails', ENV['RAILS_VERSION'] if ENV['RAILS_VERSION'] 5 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | Copyright (c) 2012 Brent Dillingham 2 | 3 | MIT License 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining 6 | a copy of this software and associated documentation files (the 7 | "Software"), to deal in the Software without restriction, including 8 | without limitation the rights to use, copy, modify, merge, publish, 9 | distribute, sublicense, and/or sell copies of the Software, and to 10 | permit persons to whom the Software is furnished to do so, subject to 11 | the following conditions: 12 | 13 | The above copyright notice and this permission notice shall be 14 | included in all copies or substantial portions of the Software. 15 | 16 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 17 | EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 18 | MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 19 | NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE 20 | LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION 21 | OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION 22 | WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | Xray-rails 2 | ========== 3 | 4 | [![Gem Version](https://badge.fury.io/rb/xray-rails.svg)](https://rubygems.org/gems/xray-rails) 5 | [![Build Status](https://travis-ci.org/brentd/xray-rails.svg?branch=master)](https://travis-ci.org/brentd/xray-rails) 6 | 7 | ### Reveal your UI's bones 8 | 9 | The dev tools available to web developers in modern browsers are great. Many of us can't remember what life was like before "Inspect Element". But what we see in the compiled output sent to our browser is often the wrong level of detail - what about visualizing the higher level components of your UI? Controllers, view templates, partials, JS templates, etc. 10 | 11 | Xray is the missing link between the browser and your app code. Press **command+shift+x** (Mac) or **ctrl+shift+x** to reveal an overlay of the files that rendered your UI, and click anything to open the file in your editor. 12 | 13 | ![Screenshot](example/screenshot.png) 14 | 15 | ## Current Support 16 | 17 | Xray is intended for Rails 3.1+ and Ruby 1.9+. 18 | 19 | So far, Xray can reveal: 20 | 21 | * Rails views and partials 22 | * Javascript templates if using the asset pipeline with the .jst extension 23 | 24 | ## Installation 25 | 26 | Xray depends on **jQuery**. 27 | 28 | This gem should only be present during development. Add it to your Gemfile: 29 | 30 | ```ruby 31 | group :development do 32 | gem 'xray-rails' 33 | end 34 | ``` 35 | 36 | Then bundle and delete your cached assets: 37 | 38 | ``` 39 | $ bundle && rm -rf tmp/cache/assets 40 | ``` 41 | 42 | Restart your app, visit it in your browser, and press **command+shift+x** (Mac) or **ctrl+shift+x** to reveal the overlay. 43 | 44 | #### Note about `config.assets.debug` 45 | 46 | By default, Xray will insert itself into your views automatically. To do this, `config.assets.debug = true` (Rails' default) must be set in development.rb. 47 | 48 | Otherwise, you can insert Xray's scripts yourself, for example like so in application.js: 49 | 50 | ```js 51 | //= require jquery 52 | //= require xray 53 | ``` 54 | 55 | ## Configuration 56 | 57 | By default, Xray will check a few environment variables to determine 58 | which editor to open files in: `$GEM_EDITOR`, `$VISUAL`, then 59 | `$EDITOR` before falling back to `/usr/local/bin/subl`. 60 | 61 | You can configure your editor of choice either by setting one of these 62 | variables, or in Xray's UI, or in an `~/.xrayconfig` YAML file: 63 | 64 | ```yaml 65 | :editor: '/usr/local/bin/mate' 66 | ``` 67 | 68 | For something more complex, use the `$file` placeholder. 69 | 70 | ```yaml 71 | :editor: "/usr/local/bin/tmux new-window 'vim $file'" 72 | ``` 73 | 74 | ## How this works 75 | 76 | * At run time, HTML responses from Rails are wrapped with HTML comments containing filepath info. 77 | * A middleware inserts `xray.js`, `xray.css`, and the Xray bar into all successful HTML response bodies. 78 | * When the overlay is shown, `xray.js` examines the inserted filepath info to build the overlay. 79 | 80 | ## Disabling Xray 81 | 82 | Xray augments HTML templates by wrapping their contents with HTML comments. For some environments such as [Angular.js](http://angularjs.org/), this can cause Angular templates to stop working because Angular expects only one root node in the template HTML. You can pass in the option `xray: false` to any partial render statements to ensure Xray does not augment that partial. Example: 83 | 84 | ```ruby 85 | render partial: 'my_partial', locals: { xray: false } 86 | ``` 87 | 88 | Note that this disables Xray's HTML comment wrappers for `my_partial`, but not any sub-partials rendered within that template, if any. You must pass `xray: false` to each `render` call where you want Xray disabled. 89 | 90 | Currently there is no way to disable Xray entirely for a given request. If this feature is important to you, please leave a comment on [issue #75](https://github.com/brentd/xray-rails/issues/75). PRs are appreciated! 91 | 92 | ## Contributing 93 | 94 | If you have an idea, open an issue and let's talk about it, or fork away and send a pull request. 95 | 96 | A laundry list of things to take on: 97 | 98 | * Reveal views from Ember, Knockout, Angular, etc. 99 | * Overlapping boxes are a problem - parent views in real applications will often be obscured by their children. 100 | * The current scheme for associating a JS constructor with a filepath is messy and can make stack traces ugly. 101 | 102 | Worth noting is that I have plans to solidify xray.js into an API and specification that could be used to aid development in any framework - not just Rails and the asset pipeline. 103 | -------------------------------------------------------------------------------- /Rakefile: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env rake 2 | require "bundler/gem_tasks" 3 | require "rspec/core/rake_task" 4 | 5 | desc "Start the spec/dummy Rails app" 6 | task "server" do 7 | exec "script/server" 8 | end 9 | 10 | namespace :assets do 11 | desc "Compile xray.js.coffee" 12 | task "compile" do 13 | exec "coffee -cp app/assets/javascripts/xray.js.coffee > app/assets/javascripts/xray.js" 14 | end 15 | end 16 | 17 | desc "Run all examples" 18 | RSpec::Core::RakeTask.new(:spec) do |t| 19 | # TODO: uncomment this and fix warnings 20 | # t.ruby_opts = %w(-w) 21 | end 22 | 23 | task :default => [:spec] 24 | -------------------------------------------------------------------------------- /app/assets/javascripts/xray.js: -------------------------------------------------------------------------------- 1 | // Generated by CoffeeScript 1.9.2 2 | (function() { 3 | var $, MAX_ZINDEX, util, 4 | hasProp = {}.hasOwnProperty, 5 | bind = function(fn, me){ return function(){ return fn.apply(me, arguments); }; }, 6 | extend = function(child, parent) { for (var key in parent) { if (hasProp.call(parent, key)) child[key] = parent[key]; } function ctor() { this.constructor = child; } ctor.prototype = parent.prototype; child.prototype = new ctor(); child.__super__ = parent.prototype; return child; }; 7 | 8 | window.Xray = {}; 9 | 10 | if (!($ = window.jQuery)) { 11 | return; 12 | } 13 | 14 | MAX_ZINDEX = 2147483647; 15 | 16 | Xray.init = (function() { 17 | var is_mac; 18 | if (Xray.initialized) { 19 | return; 20 | } 21 | Xray.initialized = true; 22 | is_mac = navigator.platform.toUpperCase().indexOf('MAC') !== -1; 23 | $(document).keydown(function(e) { 24 | if ((is_mac && e.metaKey || !is_mac && e.ctrlKey) && e.shiftKey && e.keyCode === 88) { 25 | if (Xray.isShowing) { 26 | Xray.hide(); 27 | } else { 28 | Xray.show(); 29 | } 30 | } 31 | if (Xray.isShowing && e.keyCode === 27) { 32 | return Xray.hide(); 33 | } 34 | }); 35 | return $(function() { 36 | new Xray.Overlay; 37 | Xray.findTemplates(); 38 | return typeof console !== "undefined" && console !== null ? console.log("Ready to Xray. Press " + (is_mac ? 'cmd+shift+x' : 'ctrl+shift+x') + " to scan your UI.") : void 0; 39 | }); 40 | })(); 41 | 42 | Xray.specimens = function() { 43 | return Xray.ViewSpecimen.all.concat(Xray.TemplateSpecimen.all); 44 | }; 45 | 46 | Xray.constructorInfo = function(constructor) { 47 | var func, info, ref; 48 | if (window.XrayPaths) { 49 | ref = window.XrayPaths; 50 | for (info in ref) { 51 | if (!hasProp.call(ref, info)) continue; 52 | func = ref[info]; 53 | if (func === constructor) { 54 | return JSON.parse(info); 55 | } 56 | } 57 | } 58 | return null; 59 | }; 60 | 61 | Xray.findTemplates = function() { 62 | return util.bm('findTemplates', function() { 63 | var $templateContents, _, comment, comments, el, i, id, len, path, ref, results; 64 | comments = $('*:not(iframe,script)').contents().filter(function() { 65 | return this.nodeType === 8 && this.data.slice(0, 10) === "XRAY START"; 66 | }); 67 | results = []; 68 | for (i = 0, len = comments.length; i < len; i++) { 69 | comment = comments[i]; 70 | ref = comment.data.match(/^XRAY START (\d+) (.*)$/), _ = ref[0], id = ref[1], path = ref[2]; 71 | $templateContents = new jQuery; 72 | el = comment.nextSibling; 73 | while (!(!el || (el.nodeType === 8 && el.data === ("XRAY END " + id)))) { 74 | if (el.nodeType === 1 && el.tagName !== 'SCRIPT') { 75 | $templateContents.push(el); 76 | } 77 | el = el.nextSibling; 78 | } 79 | if ((el != null ? el.nodeType : void 0) === 8) { 80 | el.parentNode.removeChild(el); 81 | } 82 | comment.parentNode.removeChild(comment); 83 | results.push(Xray.TemplateSpecimen.add($templateContents, { 84 | name: path.split('/').slice(-1)[0], 85 | path: path 86 | })); 87 | } 88 | return results; 89 | }); 90 | }; 91 | 92 | Xray.open = function(path) { 93 | return $.ajax({ 94 | url: "/_xray/open?path=" + path 95 | }); 96 | }; 97 | 98 | Xray.show = function(type) { 99 | if (type == null) { 100 | type = null; 101 | } 102 | return Xray.Overlay.instance().show(type); 103 | }; 104 | 105 | Xray.hide = function() { 106 | return Xray.Overlay.instance().hide(); 107 | }; 108 | 109 | Xray.toggleSettings = function() { 110 | return Xray.Overlay.instance().settings.toggle(); 111 | }; 112 | 113 | Xray.Specimen = (function() { 114 | Specimen.add = function(el, info) { 115 | if (info == null) { 116 | info = {}; 117 | } 118 | return this.all.push(new this(el, info)); 119 | }; 120 | 121 | Specimen.remove = function(el) { 122 | var ref; 123 | return (ref = this.find(el)) != null ? ref.remove() : void 0; 124 | }; 125 | 126 | Specimen.find = function(el) { 127 | var i, len, ref, specimen; 128 | if (el instanceof jQuery) { 129 | el = el[0]; 130 | } 131 | ref = this.all; 132 | for (i = 0, len = ref.length; i < len; i++) { 133 | specimen = ref[i]; 134 | if (specimen.el === el) { 135 | return specimen; 136 | } 137 | } 138 | return null; 139 | }; 140 | 141 | Specimen.reset = function() { 142 | return this.all = []; 143 | }; 144 | 145 | function Specimen(contents, info) { 146 | if (info == null) { 147 | info = {}; 148 | } 149 | this.makeLabel = bind(this.makeLabel, this); 150 | this.el = contents instanceof jQuery ? contents[0] : contents; 151 | this.$contents = $(contents); 152 | this.name = info.name; 153 | this.path = info.path; 154 | } 155 | 156 | Specimen.prototype.remove = function() { 157 | var idx; 158 | idx = this.constructor.all.indexOf(this); 159 | if (idx !== -1) { 160 | return this.constructor.all.splice(idx, 1); 161 | } 162 | }; 163 | 164 | Specimen.prototype.isVisible = function() { 165 | return this.$contents.length && this.$contents.is(':visible'); 166 | }; 167 | 168 | Specimen.prototype.makeBox = function() { 169 | this.bounds = util.computeBoundingBox(this.$contents); 170 | this.$box = $("
").css(this.bounds).attr('title', this.path); 171 | if (this.$contents.css('position') === 'fixed') { 172 | this.$box.css({ 173 | position: 'fixed', 174 | top: this.$contents.css('top'), 175 | left: this.$contents.css('left') 176 | }); 177 | } 178 | this.$box.click((function(_this) { 179 | return function() { 180 | return Xray.open(_this.path); 181 | }; 182 | })(this)); 183 | return this.$box.append(this.makeLabel); 184 | }; 185 | 186 | Specimen.prototype.makeLabel = function() { 187 | return $("
").append(this.name); 188 | }; 189 | 190 | return Specimen; 191 | 192 | })(); 193 | 194 | Xray.ViewSpecimen = (function(superClass) { 195 | extend(ViewSpecimen, superClass); 196 | 197 | function ViewSpecimen() { 198 | return ViewSpecimen.__super__.constructor.apply(this, arguments); 199 | } 200 | 201 | ViewSpecimen.all = []; 202 | 203 | return ViewSpecimen; 204 | 205 | })(Xray.Specimen); 206 | 207 | Xray.TemplateSpecimen = (function(superClass) { 208 | extend(TemplateSpecimen, superClass); 209 | 210 | function TemplateSpecimen() { 211 | return TemplateSpecimen.__super__.constructor.apply(this, arguments); 212 | } 213 | 214 | TemplateSpecimen.all = []; 215 | 216 | return TemplateSpecimen; 217 | 218 | })(Xray.Specimen); 219 | 220 | Xray.Overlay = (function() { 221 | Overlay.instance = function() { 222 | return this.singletonInstance || (this.singletonInstance = new this); 223 | }; 224 | 225 | function Overlay() { 226 | Xray.Overlay.singletonInstance = this; 227 | this.bar = new Xray.Bar('#xray-bar'); 228 | this.settings = new Xray.Settings('#xray-settings'); 229 | this.shownBoxes = []; 230 | this.$overlay = $('
'); 231 | this.$overlay.click((function(_this) { 232 | return function() { 233 | return _this.hide(); 234 | }; 235 | })(this)); 236 | } 237 | 238 | Overlay.prototype.show = function(type) { 239 | if (type == null) { 240 | type = null; 241 | } 242 | this.reset(); 243 | Xray.isShowing = true; 244 | return util.bm('show', (function(_this) { 245 | return function() { 246 | var element, i, len, results, specimens; 247 | _this.bar.$el().find('#xray-bar-togglers .xray-bar-btn').removeClass('active'); 248 | if (!_this.$overlay.is(':visible')) { 249 | $('body').append(_this.$overlay); 250 | _this.bar.show(); 251 | } 252 | switch (type) { 253 | case 'templates': 254 | Xray.findTemplates(); 255 | specimens = Xray.TemplateSpecimen.all; 256 | _this.bar.$el().find('.xray-bar-templates-toggler').addClass('active'); 257 | break; 258 | case 'views': 259 | specimens = Xray.ViewSpecimen.all; 260 | _this.bar.$el().find('.xray-bar-views-toggler').addClass('active'); 261 | break; 262 | default: 263 | Xray.findTemplates(); 264 | specimens = Xray.specimens(); 265 | _this.bar.$el().find('.xray-bar-all-toggler').addClass('active'); 266 | } 267 | results = []; 268 | for (i = 0, len = specimens.length; i < len; i++) { 269 | element = specimens[i]; 270 | if (!element.isVisible()) { 271 | continue; 272 | } 273 | element.makeBox(); 274 | element.$box.css({ 275 | zIndex: Math.ceil(MAX_ZINDEX * 0.9 + element.bounds.top + element.bounds.left) 276 | }); 277 | _this.shownBoxes.push(element.$box); 278 | results.push($('body').append(element.$box)); 279 | } 280 | return results; 281 | }; 282 | })(this)); 283 | }; 284 | 285 | Overlay.prototype.reset = function() { 286 | var $box, i, len, ref; 287 | ref = this.shownBoxes; 288 | for (i = 0, len = ref.length; i < len; i++) { 289 | $box = ref[i]; 290 | $box.remove(); 291 | } 292 | return this.shownBoxes = []; 293 | }; 294 | 295 | Overlay.prototype.hide = function() { 296 | Xray.isShowing = false; 297 | this.$overlay.detach(); 298 | this.reset(); 299 | return this.bar.hide(); 300 | }; 301 | 302 | return Overlay; 303 | 304 | })(); 305 | 306 | Xray.Bar = (function() { 307 | function Bar(el) { 308 | this.el = el; 309 | } 310 | 311 | Bar.prototype.$el = function() { 312 | if ((this.$el_memo != null) && $.contains(window.document, this.$el_memo[0])) { 313 | return this.$el_memo; 314 | } 315 | this.$el_memo = $(this.el); 316 | this.$el_memo.css({ 317 | zIndex: MAX_ZINDEX 318 | }); 319 | this.$el_memo.find('#xray-bar-controller-path .xray-bar-btn').click(function() { 320 | return Xray.open($(this).attr('data-path')); 321 | }); 322 | this.$el_memo.find('.xray-bar-all-toggler').click(function() { 323 | return Xray.show(); 324 | }); 325 | this.$el_memo.find('.xray-bar-templates-toggler').click(function() { 326 | return Xray.show('templates'); 327 | }); 328 | this.$el_memo.find('.xray-bar-views-toggler').click(function() { 329 | return Xray.show('views'); 330 | }); 331 | this.$el_memo.find('.xray-bar-settings-btn').click(function() { 332 | return Xray.toggleSettings(); 333 | }); 334 | return this.$el_memo; 335 | }; 336 | 337 | Bar.prototype.show = function() { 338 | this.$el().show(); 339 | this.originalPadding = parseInt($('html').css('padding-bottom')); 340 | if (this.originalPadding < 40) { 341 | return $('html').css({ 342 | paddingBottom: 40 343 | }); 344 | } 345 | }; 346 | 347 | Bar.prototype.hide = function() { 348 | this.$el().hide(); 349 | return $('html').css({ 350 | paddingBottom: this.originalPadding 351 | }); 352 | }; 353 | 354 | return Bar; 355 | 356 | })(); 357 | 358 | Xray.Settings = (function() { 359 | function Settings(el) { 360 | this.displayUpdateMsg = bind(this.displayUpdateMsg, this); 361 | this.save = bind(this.save, this); 362 | this.toggle = bind(this.toggle, this); 363 | this.el = el; 364 | } 365 | 366 | Settings.prototype.$el = function() { 367 | if ((this.$el_memo != null) && $.contains(window.document, this.$el_memo[0])) { 368 | return this.$el_memo; 369 | } 370 | this.$el_memo = $(this.el); 371 | this.$el_memo.find('form').submit(this.save); 372 | return this.$el_memo; 373 | }; 374 | 375 | Settings.prototype.toggle = function() { 376 | return this.$el().toggle(); 377 | }; 378 | 379 | Settings.prototype.save = function(e) { 380 | var editor; 381 | e.preventDefault(); 382 | editor = this.$el().find('#xray-editor-input').val(); 383 | return $.ajax({ 384 | url: '/_xray/config', 385 | type: 'POST', 386 | data: { 387 | editor: editor 388 | }, 389 | success: (function(_this) { 390 | return function() { 391 | return _this.displayUpdateMsg(true); 392 | }; 393 | })(this), 394 | error: (function(_this) { 395 | return function() { 396 | return _this.displayUpdateMsg(false); 397 | }; 398 | })(this) 399 | }); 400 | }; 401 | 402 | Settings.prototype.displayUpdateMsg = function(success) { 403 | var $msg; 404 | if (success) { 405 | $msg = $("Success!"); 406 | } else { 407 | $msg = $("Uh oh, something went wrong!"); 408 | } 409 | this.$el().append($msg); 410 | return $msg.delay(2000).fadeOut(500, (function(_this) { 411 | return function() { 412 | $msg.remove(); 413 | return _this.toggle(); 414 | }; 415 | })(this)); 416 | }; 417 | 418 | return Settings; 419 | 420 | })(); 421 | 422 | util = { 423 | bm: function(name, fn) { 424 | var result, time; 425 | time = new Date; 426 | result = fn(); 427 | return result; 428 | }, 429 | computeBoundingBox: function($contents) { 430 | var $el, boxFrame, el, frame, i, len; 431 | if ($contents.length === 1 && $contents.height() <= 0) { 432 | return util.computeBoundingBox($contents.children()); 433 | } 434 | boxFrame = { 435 | top: Number.POSITIVE_INFINITY, 436 | left: Number.POSITIVE_INFINITY, 437 | right: Number.NEGATIVE_INFINITY, 438 | bottom: Number.NEGATIVE_INFINITY 439 | }; 440 | for (i = 0, len = $contents.length; i < len; i++) { 441 | el = $contents[i]; 442 | $el = $(el); 443 | if (!$el.is(':visible')) { 444 | continue; 445 | } 446 | frame = $el.offset(); 447 | frame.right = frame.left + $el.outerWidth(); 448 | frame.bottom = frame.top + $el.outerHeight(); 449 | if (frame.top < boxFrame.top) { 450 | boxFrame.top = frame.top; 451 | } 452 | if (frame.left < boxFrame.left) { 453 | boxFrame.left = frame.left; 454 | } 455 | if (frame.right > boxFrame.right) { 456 | boxFrame.right = frame.right; 457 | } 458 | if (frame.bottom > boxFrame.bottom) { 459 | boxFrame.bottom = frame.bottom; 460 | } 461 | } 462 | return { 463 | left: boxFrame.left, 464 | top: boxFrame.top, 465 | width: boxFrame.right - boxFrame.left, 466 | height: boxFrame.bottom - boxFrame.top 467 | }; 468 | } 469 | }; 470 | 471 | }).call(this); 472 | -------------------------------------------------------------------------------- /app/assets/javascripts/xray.js.coffee: -------------------------------------------------------------------------------- 1 | window.Xray = {} 2 | return unless $ = window.jQuery 3 | 4 | # Max CSS z-index. The overlay and xray bar use this. 5 | MAX_ZINDEX = 2147483647 6 | 7 | # Initialize Xray. Called immediately, but some setup is deferred until DOM ready. 8 | Xray.init = do -> 9 | return if Xray.initialized 10 | Xray.initialized = true 11 | 12 | is_mac = navigator.platform.toUpperCase().indexOf('MAC') isnt -1 13 | 14 | # Register keyboard shortcuts 15 | $(document).keydown (e) -> 16 | # cmd+shift+x on Mac, ctrl+shift+x on other platforms 17 | if (is_mac and e.metaKey or !is_mac and e.ctrlKey) and e.shiftKey and e.keyCode is 88 18 | if Xray.isShowing then Xray.hide() else Xray.show() 19 | if Xray.isShowing and e.keyCode is 27 # esc 20 | Xray.hide() 21 | 22 | $ -> 23 | # Instantiate the overlay singleton. 24 | new Xray.Overlay 25 | # Go ahead and do a pass on the DOM to find templates. 26 | Xray.findTemplates() 27 | # Ready to rock. 28 | console?.log "Ready to Xray. Press #{if is_mac then 'cmd+shift+x' else 'ctrl+shift+x'} to scan your UI." 29 | 30 | # Returns all currently created Xray.Specimen objects. 31 | Xray.specimens = -> 32 | Xray.ViewSpecimen.all.concat Xray.TemplateSpecimen.all 33 | 34 | # Looks up the stored constructor info 35 | Xray.constructorInfo = (constructor) -> 36 | if window.XrayPaths 37 | for own info, func of window.XrayPaths 38 | return JSON.parse(info) if func == constructor 39 | null 40 | 41 | # Scans the document for templates, creating Xray.TemplateSpecimens for them. 42 | Xray.findTemplates = -> util.bm 'findTemplates', -> 43 | # Find all comments 44 | comments = $('*:not(iframe,script)').contents().filter -> 45 | this.nodeType == 8 and this.data[0..9] == "XRAY START" 46 | 47 | # Find the comment for each. Everything between the 48 | # start and end comment becomes the contents of an Xray.TemplateSpecimen. 49 | for comment in comments 50 | [_, id, path] = comment.data.match(/^XRAY START (\d+) (.*)$/) 51 | $templateContents = new jQuery 52 | el = comment.nextSibling 53 | until !el or (el.nodeType == 8 and el.data == "XRAY END #{id}") 54 | if el.nodeType == 1 and el.tagName != 'SCRIPT' 55 | $templateContents.push el 56 | el = el.nextSibling 57 | # Remove XRAY template comments from the DOM. 58 | el.parentNode.removeChild(el) if el?.nodeType == 8 59 | comment.parentNode.removeChild(comment) 60 | # Add the template specimen 61 | Xray.TemplateSpecimen.add $templateContents, 62 | name: path.split('/').slice(-1)[0] 63 | path: path 64 | 65 | # Open the given filesystem path by calling out to Xray's server. 66 | Xray.open = (path) -> 67 | $.ajax(url: "/_xray/open?path=#{path}") 68 | 69 | # Show the Xray overlay 70 | Xray.show = (type = null) -> 71 | Xray.Overlay.instance().show(type) 72 | 73 | # Hide the Xray overlay 74 | Xray.hide = -> 75 | Xray.Overlay.instance().hide() 76 | 77 | Xray.toggleSettings = -> 78 | Xray.Overlay.instance().settings.toggle() 79 | 80 | # Wraps a DOM element that Xray is tracking. This is subclassed by 81 | # Xray.TemplateSpecimen and Xray.ViewSpecimen. 82 | class Xray.Specimen 83 | @add: (el, info = {}) -> 84 | @all.push new this(el, info) 85 | 86 | @remove: (el) -> 87 | @find(el)?.remove() 88 | 89 | @find: (el) -> 90 | el = el[0] if el instanceof jQuery 91 | for specimen in @all 92 | return specimen if specimen.el == el 93 | null 94 | 95 | @reset: -> 96 | @all = [] 97 | 98 | constructor: (contents, info = {}) -> 99 | @el = if contents instanceof jQuery then contents[0] else contents 100 | @$contents = $(contents) 101 | @name = info.name 102 | @path = info.path 103 | 104 | remove: -> 105 | idx = @constructor.all.indexOf(this) 106 | @constructor.all.splice(idx, 1) unless idx == -1 107 | 108 | isVisible: -> 109 | @$contents.length and @$contents.is(':visible') 110 | 111 | makeBox: -> 112 | @bounds = util.computeBoundingBox(@$contents) 113 | @$box = $("
").css(@bounds).attr('title', @path) 114 | 115 | # If the element is fixed, override the computed position with the fixed one. 116 | if @$contents.css('position') == 'fixed' 117 | @$box.css 118 | position : 'fixed' 119 | top : @$contents.css('top') 120 | left : @$contents.css('left') 121 | 122 | @$box.click => Xray.open @path 123 | @$box.append @makeLabel 124 | 125 | makeLabel: => 126 | $("
").append(@name) 127 | 128 | 129 | # Wraps elements that constitute a Javascript "view" object, e.g. 130 | # Backbone.View. 131 | class Xray.ViewSpecimen extends Xray.Specimen 132 | @all = [] 133 | 134 | 135 | # Wraps elements that were rendered by a template, e.g. a Rails partial or 136 | # a client-side rendered JS template. 137 | class Xray.TemplateSpecimen extends Xray.Specimen 138 | @all = [] 139 | 140 | 141 | # Singleton class for the Xray "overlay" invoked by the keyboard shortcut 142 | class Xray.Overlay 143 | @instance: -> 144 | @singletonInstance ||= new this 145 | 146 | constructor: -> 147 | Xray.Overlay.singletonInstance = this 148 | @bar = new Xray.Bar('#xray-bar') 149 | @settings = new Xray.Settings('#xray-settings') 150 | @shownBoxes = [] 151 | @$overlay = $('
') 152 | @$overlay.click => @hide() 153 | 154 | show: (type = null) -> 155 | @reset() 156 | Xray.isShowing = true 157 | util.bm 'show', => 158 | @bar.$el().find('#xray-bar-togglers .xray-bar-btn').removeClass('active') 159 | unless @$overlay.is(':visible') 160 | $('body').append @$overlay 161 | @bar.show() 162 | switch type 163 | when 'templates' 164 | Xray.findTemplates() 165 | specimens = Xray.TemplateSpecimen.all 166 | @bar.$el().find('.xray-bar-templates-toggler').addClass('active') 167 | when 'views' 168 | specimens = Xray.ViewSpecimen.all 169 | @bar.$el().find('.xray-bar-views-toggler').addClass('active') 170 | else 171 | Xray.findTemplates() 172 | specimens = Xray.specimens() 173 | @bar.$el().find('.xray-bar-all-toggler').addClass('active') 174 | for element in specimens 175 | continue unless element.isVisible() 176 | element.makeBox() 177 | # A cheap way to "order" the boxes, where boxes positioned closer to the 178 | # bottom right of the document have a higher z-index. 179 | element.$box.css 180 | zIndex: Math.ceil(MAX_ZINDEX*0.9 + element.bounds.top + element.bounds.left) 181 | @shownBoxes.push element.$box 182 | $('body').append element.$box 183 | 184 | reset: -> 185 | $box.remove() for $box in @shownBoxes 186 | @shownBoxes = [] 187 | 188 | hide: -> 189 | Xray.isShowing = false 190 | @$overlay.detach() 191 | @reset() 192 | @bar.hide() 193 | 194 | 195 | # The Xray bar shows controller, action, and view information, and has 196 | # toggle buttons for showing the different types of specimens in the overlay. 197 | class Xray.Bar 198 | constructor: (el) -> 199 | @el = el 200 | 201 | # Defer wiring up jQuery event handlers until needed and then memoize the 202 | # result. If the Bar element no longer exists in the DOM, re-wire it. 203 | # This allows the Bar to keep working even if e.g. Turbolinks replaces the 204 | # DOM out from under us. 205 | $el: -> 206 | return @$el_memo if @$el_memo? && $.contains(window.document, @$el_memo[0]) 207 | @$el_memo = $(@el) 208 | @$el_memo.css(zIndex: MAX_ZINDEX) 209 | @$el_memo.find('#xray-bar-controller-path .xray-bar-btn').click -> 210 | Xray.open($(this).attr('data-path')) 211 | @$el_memo.find('.xray-bar-all-toggler').click -> Xray.show() 212 | @$el_memo.find('.xray-bar-templates-toggler').click -> Xray.show('templates') 213 | @$el_memo.find('.xray-bar-views-toggler').click -> Xray.show('views') 214 | @$el_memo.find('.xray-bar-settings-btn').click -> Xray.toggleSettings() 215 | @$el_memo 216 | 217 | show: -> 218 | @$el().show() 219 | @originalPadding = parseInt $('html').css('padding-bottom') 220 | if @originalPadding < 40 221 | $('html').css paddingBottom: 40 222 | 223 | hide: -> 224 | @$el().hide() 225 | $('html').css paddingBottom: @originalPadding 226 | 227 | 228 | class Xray.Settings 229 | constructor: (el) -> 230 | @el = el 231 | 232 | $el: -> 233 | return @$el_memo if @$el_memo? && $.contains(window.document, @$el_memo[0]) 234 | @$el_memo = $(@el) 235 | @$el_memo.find('form').submit @save 236 | @$el_memo 237 | 238 | toggle: => 239 | @$el().toggle() 240 | 241 | save: (e) => 242 | e.preventDefault() 243 | editor = @$el().find('#xray-editor-input').val() 244 | $.ajax 245 | url: '/_xray/config' 246 | type: 'POST' 247 | data: {editor: editor} 248 | success: => @displayUpdateMsg(true) 249 | error: => @displayUpdateMsg(false) 250 | 251 | displayUpdateMsg: (success) => 252 | if success 253 | $msg = $("Success!") 254 | else 255 | $msg = $("Uh oh, something went wrong!") 256 | @$el().append($msg) 257 | $msg.delay(2000).fadeOut(500, => $msg.remove(); @toggle()) 258 | 259 | 260 | # Utility methods. 261 | util = 262 | # Benchmark a piece of code 263 | bm: (name, fn) -> 264 | time = new Date 265 | result = fn() 266 | # console.log "#{name} : #{new Date() - time}ms" 267 | result 268 | 269 | # Computes the bounding box of a jQuery set, which may be many sibling 270 | # elements with no parent in the set. 271 | computeBoundingBox: ($contents) -> 272 | # Edge case: the container may not physically wrap its children, for 273 | # example if they are floated and no clearfix is present. 274 | if $contents.length == 1 and $contents.height() <= 0 275 | return util.computeBoundingBox($contents.children()) 276 | 277 | boxFrame = 278 | top : Number.POSITIVE_INFINITY 279 | left : Number.POSITIVE_INFINITY 280 | right : Number.NEGATIVE_INFINITY 281 | bottom : Number.NEGATIVE_INFINITY 282 | 283 | for el in $contents 284 | $el = $(el) 285 | continue unless $el.is(':visible') 286 | frame = $el.offset() 287 | frame.right = frame.left + $el.outerWidth() 288 | frame.bottom = frame.top + $el.outerHeight() 289 | boxFrame.top = frame.top if frame.top < boxFrame.top 290 | boxFrame.left = frame.left if frame.left < boxFrame.left 291 | boxFrame.right = frame.right if frame.right > boxFrame.right 292 | boxFrame.bottom = frame.bottom if frame.bottom > boxFrame.bottom 293 | 294 | return { 295 | left : boxFrame.left 296 | top : boxFrame.top 297 | width : boxFrame.right - boxFrame.left 298 | height : boxFrame.bottom - boxFrame.top 299 | } 300 | -------------------------------------------------------------------------------- /app/assets/stylesheets/xray.css: -------------------------------------------------------------------------------- 1 | @charset "UTF-8"; 2 | 3 | /* selector for element and children */ 4 | #xray-overlay, #xray-overlay *, #xray-overlay a:hover, #xray-overlay a:visited, #xray-overlay a:active, 5 | #xray-bar, #xray-bar *, #xray-bar a:hover, #xray-bar a:visited, #xray-bar a:active { 6 | background:none; 7 | border:none; 8 | bottom:auto; 9 | clear:none; 10 | cursor:default; 11 | float:none; 12 | font-family:Arial, Helvetica, sans-serif; 13 | font-size:medium; 14 | font-style:normal; 15 | font-weight:normal; 16 | height:auto; 17 | left:auto; 18 | letter-spacing:normal; 19 | line-height:normal; 20 | max-height:none; 21 | max-width:none; 22 | min-height:0; 23 | min-width:0; 24 | overflow:visible; 25 | position:static; 26 | right:auto; 27 | text-align:left; 28 | text-decoration:none; 29 | text-indent:0; 30 | text-transform:none; 31 | top:auto; 32 | visibility:visible; 33 | white-space:normal; 34 | width:auto; 35 | z-index:auto; 36 | } 37 | 38 | #xray-overlay { 39 | position: fixed; left: 0; top: 0; bottom: 0; right: 0; 40 | background: rgba(0,0,0,0.7); 41 | background: -webkit-radial-gradient(center, ellipse cover, rgba(0,0,0,0.4) 10%, rgba(0,0,0,0.8) 100%); 42 | z-index: 9000; 43 | } 44 | 45 | .xray-specimen { 46 | position: absolute; 47 | background: rgba(255,255,255,0.15); 48 | outline: 1px solid rgba(255,255,255,0.8); 49 | outline-offset: -1px; 50 | color: #666; 51 | font-family: "Helvetica Neue", sans-serif; 52 | font-size: 13px; 53 | box-shadow: 0 1px 3px rgba(0,0,0,0.7); 54 | } 55 | 56 | .xray-specimen:hover { 57 | cursor: pointer; 58 | background: rgba(255,255,255,0.4); 59 | } 60 | 61 | .xray-specimen.TemplateSpecimen { 62 | outline: 1px solid rgba(255,50,50,0.8); 63 | background: rgba(255,50,50,0.1); 64 | } 65 | 66 | .xray-specimen.TemplateSpecimen:hover { 67 | background: rgba(255,50,50,0.4); 68 | } 69 | 70 | .xray-specimen-handle { 71 | float:left; 72 | background: #fff; 73 | padding: 0 3px; 74 | color: #333; 75 | font-size: 10px; 76 | } 77 | 78 | .xray-specimen-handle.TemplateSpecimen { 79 | background: rgba(255,50,50,0.8); 80 | color: #fff; 81 | } 82 | 83 | #xray-bar { 84 | position: fixed; 85 | left: 0; 86 | right: 0; 87 | bottom: 0; 88 | height: 40px; 89 | padding: 0 8px; 90 | background: #222; 91 | font-family: "Helvetica Neue", Helvetica, Arial, sans-serif; 92 | font-weight: 200; 93 | color: #fff; 94 | z-index: 10000; 95 | box-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N0YW5jZUlEPSJ4bXAuaWlkOkNGQ0ExNTA1N0ZFMjExRTJCMEZDQ0FFNzlENDcwQkU1IiBzdFJlZjpkb2N1bWVudElEPSJ4bXAuZGlkOkNGQ0ExNTA2N0ZFMjExRTJCMEZDQ0FFNzlENDcwQkU1Ii8+IDwvcmRmOkRlc2NyaXB0aW9uPiA8L3JkZjpSREY+IDwveDp4bXBtZXRhPiA8P3hwYWNrZXQgZW5kPSJyIj8+aIv7XwAAAEVJREFUeNpiFBMTY2BgEBISYsAGWICAATdgkZeXB1Lv37/HLo1LAgKYGPACdOl3YIAwHNOpKFw0aTSXokujuZSA0wACDABh2BIyJ1wQkwAAAABJRU5ErkJggg==); 98 | } 99 | 100 | @media (-webkit-min-device-pixel-ratio: 2), (min-resolution: 192dppx) { 101 | #xray-bar { 102 | background-image: linear-gradient(rgba(0,0,0,0), rgba(0,0,0,0.3)), 103 | url(data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABQAAAAUCAIAAAAC64paAAAAGXRFWHRTb2Z0d2FyZQBBZG9iZSBJbWFnZVJlYWR5ccllPAAAAyRpVFh0WE1MOmNvbS5hZG9iZS54bXAAAAAAADw/eHBhY2tldCBiZWdpbj0i77u/IiBpZD0iVzVNME1wQ2VoaUh6cmVTek5UY3prYzlkIj8+IDx4OnhtcG1ldGEgeG1sbnM6eD0iYWRvYmU6bnM6bWV0YS8iIHg6eG1wdGs9IkFkb2JlIFhNUCBDb3JlIDUuMy1jMDExIDY2LjE0NTY2MSwgMjAxMi8wMi8wNi0xNDo1NjoyNyAgICAgICAgIj4gPHJkZjpSREYgeG1sbnM6cmRmPSJodHRwOi8vd3d3LnczLm9yZy8xOTk5LzAyLzIyLXJkZi1zeW50YXgtbnMjIj4gPHJkZjpEZXNjcmlwdGlvbiByZGY6YWJvdXQ9IiIgeG1sbnM6eG1wPSJodHRwOi8vbnMuYWRvYmUuY29tL3hhcC8xLjAvIiB4bWxuczp4bXBNTT0iaHR0cDovL25zLmFkb2JlLmNvbS94YXAvMS4wL21tLyIgeG1sbnM6c3RSZWY9Imh0dHA6Ly9ucy5hZG9iZS5jb20veGFwLzEuMC9zVHlwZS9SZXNvdXJjZVJlZiMiIHhtcDpDcmVhdG9yVG9vbD0iQWRvYmUgUGhvdG9zaG9wIENTNiAoTWFjaW50b3NoKSIgeG1wTU06SW5zdGFuY2VJRD0ieG1wLmlpZDo0Q0ZGQkRGRTdGRTMxMUUyQjBGQ0NBRTc5RDQ3MEJFNSIgeG1wTU06RG9jdW1lbnRJRD0ieG1wLmRpZDo0Q0ZGQkRGRjdGRTMxMUUyQjBGQ0NBRTc5RDQ3MEJFNSI+IDx4bXBNTTpEZXJpdmVkRnJvbSBzdFJlZjppbnN0YW5jZUlEPSJ4bXAuaWlkOkNGQ0ExNTA5N0ZFMjExRTJCMEZDQ0FFNzlENDcwQkU1IiBzdFJlZjpkb2N1bWVudElEPSJ4bXAuZGlkOkNGQ0ExNTBBN0ZFMjExRTJCMEZDQ0FFNzlENDcwQkU1Ii8+IDwvcmRmOkRlc2NyaXB0aW9uPiA8L3JkZjpSREY+IDwveDp4bXBtZXRhPiA8P3hwYWNrZXQgZW5kPSJyIj8+T6y4zwAAAIZJREFUeNrkkjEKwCAMRWMbERw8gE5O3v9q6lIEbbDQMZJ2Kv0gBOSR8HkqxphzBgDnnDEGJNkRsfc+xmitWWtF8KaUuqZ7EMDee1qutQ4hSGGkl1Kis2utYviYgUfZ4EU+CiP/TV0y/i02l1L6DA3is3n/FjDvHy5bYfxbF8b490fDTgEGAJveOCvuYEabAAAAAElFTkSuQmCC); 104 | background-size: auto, 10px 10px; 105 | } 106 | } 107 | 108 | #xray-bar .xray-bar-btn { 109 | position: relative; 110 | color: #fff; 111 | margin: 8px 1px; 112 | height: 24px; 113 | line-height: 24px; 114 | padding: 0 8px; 115 | float: left; 116 | font-size: 14px; 117 | cursor: pointer; 118 | vertical-align: middle; 119 | background-color: #444; 120 | background-image: linear-gradient(rgba(0,0,0,0), rgba(0,0,0,0.2)); 121 | border-radius: 2px; 122 | box-shadow: 1px 1px 1px rgba(0,0,0,0.5), 123 | inset 0 1px 0 rgba(255, 255, 255, 0.2), 124 | inset 0 0 2px rgba(255, 255, 255, 0.2); 125 | text-shadow: 0 -1px 0 rgba(0,0,0,0.4); 126 | transition: background-color 0.1s; 127 | } 128 | 129 | #xray-bar .xray-bar-btn b { 130 | position: absolute; 131 | display: block; 132 | right: -19px; 133 | top: 0; 134 | width: 20px; 135 | height: 24px; 136 | z-index: 10; 137 | overflow: hidden; 138 | font-size: 44px; 139 | line-height: 19px; 140 | text-indent: -7px; 141 | } 142 | 143 | #xray-bar .xray-bar-btn b:before { 144 | content: ""; 145 | width: 18px; 146 | height: 18px; 147 | display: block; 148 | position: absolute; 149 | left: -9px; 150 | top: 3px; 151 | border-radius: 2px; 152 | box-shadow: 1px -1px 1px rgba(0,0,0,0.5), inset 0 1px 0 rgba(255, 255, 255, 0.2), inset 0 0 2px rgba(255, 255, 255, 0.2); 153 | background-image: linear-gradient(135deg, rgba(0,0,0,0), rgba(0,0,0,0.2)); 154 | -webkit-transform: rotate(45deg); 155 | transform: rotate(45deg); 156 | transition: background-color 0.1s; 157 | } 158 | 159 | #xray-bar .xray-bar-btn:hover { 160 | background-color: #555; 161 | } 162 | 163 | #xray-bar #xray-bar-controller-path { 164 | margin-right: 20px; 165 | } 166 | 167 | #xray-bar #xray-bar-controller-path .xray-bar-btn { 168 | border-radius: 2px 0 0 2px; 169 | padding: 0 6px 0 16px; 170 | margin: 8px 1px 8px 0; 171 | } 172 | 173 | #xray-bar #xray-bar-controller-path .xray-bar-btn:first-child { 174 | padding-left: 8px; 175 | } 176 | 177 | #xray-bar #xray-bar-controller-path .xray-bar-btn:last-child { 178 | border-radius: 2px; 179 | padding-right: 10px; 180 | } 181 | 182 | #xray-bar-controller-path .xray-bar-controller { padding-left: 6px; } 183 | #xray-bar-controller-path .xray-bar-controller, 184 | #xray-bar-controller-path .xray-bar-controller b:before { background-color: #444; } 185 | #xray-bar-controller-path .xray-bar-controller:hover, 186 | #xray-bar-controller-path .xray-bar-controller:hover b:before { background-color: #555; } 187 | #xray-bar-controller-path .xray-bar-controller-action { color: #ddd; } 188 | #xray-bar-controller-path .xray-bar-layout, 189 | #xray-bar-controller-path .xray-bar-layout b:before { background-color: #c12e27; } 190 | #xray-bar-controller-path .xray-bar-layout:hover, 191 | #xray-bar-controller-path .xray-bar-layout:hover b:before { background-color: #de362d; } 192 | #xray-bar-controller-path .xray-bar-view, 193 | #xray-bar-controller-path .xray-bar-view b:before { background-color: #ff2c1e; } 194 | #xray-bar-controller-path .xray-bar-view:hover, 195 | #xray-bar-controller-path .xray-bar-view:hover b:before { background-color: #ff4c36; } 196 | 197 | #xray-bar #xray-bar-togglers { 198 | float: left; 199 | margin-left: 20px; 200 | } 201 | 202 | #xray-bar #xray-bar-togglers .xray-bar-btn { 203 | border-radius: 0; 204 | margin-right: 0; 205 | color: #999; 206 | } 207 | 208 | #xray-bar #xray-bar-togglers .xray-bar-btn:first-child { 209 | border-radius: 2px 0 0 2px; 210 | } 211 | 212 | #xray-bar #xray-bar-togglers .xray-bar-btn:last-child { 213 | border-radius: 0 2px 2px 0; 214 | } 215 | 216 | #xray-bar #xray-bar-togglers .xray-bar-btn:before { 217 | font-size: 9px; 218 | vertical-align: middle; 219 | margin-bottom: 1px; 220 | margin-right: 5px; 221 | background: rgba(255,255,255,0.2); 222 | color: #eee; 223 | padding: 2px 4px; 224 | text-shadow: none; 225 | } 226 | 227 | #xray-bar #xray-bar-togglers .xray-bar-btn.active { 228 | background: #555; 229 | color: #fff; 230 | } 231 | 232 | #xray-bar #xray-bar-togglers .xray-bar-templates-toggler:before { content: 'HTML'; } 233 | #xray-bar #xray-bar-togglers .xray-bar-templates-toggler.active:before { background: red; } 234 | #xray-bar #xray-bar-togglers .xray-bar-views-toggler:before { content: 'JS'; } 235 | #xray-bar #xray-bar-togglers .xray-bar-views-toggler.active:before { background: #fff; color: #333; } 236 | #xray-bar #xray-bar-togglers .xray-bar-styles-toggler:before { content: 'CSS'; } 237 | 238 | #xray-bar #xray-bar-togglers .xray-icon-search:before { 239 | font-size: 16px; 240 | background: none; 241 | padding: 0; 242 | margin: 0; 243 | } 244 | 245 | #xray-bar .xray-bar-settings-btn { 246 | position: absolute; 247 | right: 10px; 248 | top: 10px; 249 | color: #666; 250 | cursor: pointer; 251 | text-shadow: 0 1px 0 #000; 252 | font-size: 16px; 253 | -webkit-touch-callout: none; 254 | -webkit-user-select: none; 255 | -khtml-user-select: none; 256 | -moz-user-select: none; 257 | -ms-user-select: none; 258 | user-select: none; 259 | } 260 | 261 | #xray-bar .xray-bar-settings-btn:hover { 262 | color: #fff; 263 | } 264 | 265 | #xray-settings { 266 | position: absolute; 267 | right: 0; 268 | bottom: 40px; 269 | width: 300px; 270 | height: 100px; 271 | background: rgba(0,0,0,0.9); 272 | padding: 10px; 273 | font-size: 14px 274 | } 275 | 276 | #xray-settings label { 277 | display: inline; 278 | margin: 2px 10px; 279 | padding: 0; 280 | } 281 | 282 | #xray-settings input { 283 | padding: 5px; 284 | display: inline; 285 | background: #333; 286 | border: 1px solid #666; 287 | color: #fff; 288 | width: 200px; 289 | margin: 0; 290 | font-size: 13px; 291 | line-height: 13px; 292 | border-radius: 3px; 293 | vertical-align: middle; 294 | } 295 | 296 | #xray-settings button { 297 | position: absolute; 298 | right: 18px; 299 | left: 18px; 300 | bottom: 10px; 301 | padding: 7px; 302 | color: #fff; 303 | background: #04be00; 304 | text-align: center; 305 | cursor: pointer; 306 | } 307 | 308 | #xray-settings button:hover { 309 | background: #049d00; 310 | } 311 | 312 | #xray-settings p { 313 | font-size: 12px; 314 | color: #666; 315 | text-align: center; 316 | margin: 10px 0 0 0; 317 | } 318 | 319 | #xray-settings .xray-settings-update-msg { 320 | margin-left: 12px; 321 | } 322 | 323 | 324 | @font-face { 325 | font-family: 'xray-icons'; 326 | src: url("data:application/octet-stream;base64,d09GRgABAAAAAA6MABAAAAAAFlAAAQAAAAAAAAA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ANystsEwssgABNystsE0ssgEANystsE4ssgEBNystsE8ssgAAOSstsFAssgABOSstsFEssgEAOSstsFIssgEBOSstsFMssgAAPCstsFQssgABPCstsFUssgEAPCstsFYssgEBPCstsFcssgAAOCstsFgssgABOCstsFkssgEAOCstsFossgEBOCstsFsssDArLrEkARQrLbBcLLAwK7A0Ky2wXSywMCuwNSstsF4ssAAWsDArsDYrLbBfLLAxKy6xJAEUKy2wYCywMSuwNCstsGEssDErsDUrLbBiLLAxK7A2Ky2wYyywMisusSQBFCstsGQssDIrsDQrLbBlLLAyK7A1Ky2wZiywMiuwNistsGcssDMrLrEkARQrLbBoLLAzK7A0Ky2waSywMyuwNSstsGossDMrsDYrLbBrLCuwCGWwAyRQeLABFTAtAABLuADIUlixAQGOWbkIAAgAYyCwASNEILADI3CyBCgJRVJEswoLBgQrsQYBRLEkAYhRWLBAiFixBgNEsSYBiFFYuAQAiFixBgFEWVlZWbgB/4WwBI2xBQBE") format('truetype'); 327 | } 328 | 329 | [class^="xray-icon-"]:before, 330 | [class*=" xray-icon-"]:before { 331 | font-family: 'xray-icons'; 332 | font-style: normal; 333 | font-weight: normal; 334 | speak: none; 335 | display: inline-block; 336 | text-decoration: inherit; 337 | width: 1em; 338 | margin-right: 0.1em; 339 | text-align: center; 340 | line-height: 1em; 341 | } 342 | 343 | .xray-icon-cog:before { content: '\e800'; } /* '' */ 344 | .xray-icon-flash:before { content: '\26a1'; } /* '⚡' */ 345 | .xray-icon-cancel:before { content: '\2715'; } /* '✕' */ 346 | .xray-icon-github:before { content: '\f056'; } /* '' */ 347 | .xray-icon-columns:before { content: '\f0db'; } /* '' */ 348 | .xray-icon-doc:before { content: '📄'; } /* '\1f4c4' */ 349 | .xray-icon-search:before { content: '🔍'; } /* '\1f50d' */ 350 | -------------------------------------------------------------------------------- /app/views/_xray_bar.html.erb: -------------------------------------------------------------------------------- 1 | 42 | -------------------------------------------------------------------------------- /example/screenshot.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/brentd/xray-rails/3d5fe94abee742fff387c393fc5c42db20649e09/example/screenshot.png -------------------------------------------------------------------------------- /lib/xray-rails.rb: -------------------------------------------------------------------------------- 1 | require "json" 2 | require "active_support/all" 3 | require_relative "xray/version" 4 | require_relative "xray/aliasing" 5 | require_relative "xray/config" 6 | require_relative "xray/middleware" 7 | 8 | if defined?(Rails) && Rails.env.development? 9 | require "xray/engine" 10 | end 11 | 12 | module Xray 13 | FILE_PLACEHOLDER = '$file' 14 | 15 | # Used to collect request information during each request cycle for use in 16 | # the Xray bar. 17 | def self.request_info 18 | Thread.current[:request_info] ||= {} 19 | end 20 | 21 | # Returns augmented HTML where the source is simply wrapped in an HTML 22 | # comment with filepath info. Xray.js uses these comments to associate 23 | # elements with the templates that rendered them. 24 | # 25 | # This: 26 | #
27 | # ... 28 | #
29 | # 30 | # Becomes: 31 | # 32 | #
33 | # ... 34 | #
35 | # 36 | def self.augment_template(source, path) 37 | id = next_id 38 | if source.include?('\n#{source}\n" 46 | end 47 | ActiveSupport::SafeBuffer === source ? ActiveSupport::SafeBuffer.new(augmented) : augmented 48 | end 49 | 50 | def self.next_id 51 | @id = (@id ||= 0) + 1 52 | end 53 | 54 | def self.open_file(file) 55 | editor = Xray.config.editor 56 | cmd = if editor.include?('$file') 57 | editor.gsub '$file', file 58 | else 59 | "#{editor} \"#{file}\"" 60 | end 61 | Open3.capture3(cmd) 62 | end 63 | end 64 | -------------------------------------------------------------------------------- /lib/xray/aliasing.rb: -------------------------------------------------------------------------------- 1 | module Xray 2 | # This module implements the old ActiveSupport alias_method_chain feature 3 | # with a new name, and without the deprecation warnings. In ActiveSupport 5+, 4 | # this style of patching was deprecated in favor of Module.prepend. But 5 | # Module.prepend is not present in Ruby 1.9, which we would still like to 6 | # support. So we continue to use of alias_method_chain, albeit with a 7 | # different name to avoid collisions. 8 | # 9 | # TODO: remove this and drop support for Ruby 1.9. 10 | # 11 | module Aliasing 12 | # This code is copied and pasted from ActiveSupport, but with :xray 13 | # hardcoded as the feature name, and with the deprecation warning removed. 14 | def xray_method_alias(target) 15 | feature = :xray 16 | 17 | # Strip out punctuation on predicates, bang or writer methods since 18 | # e.g. target?_without_feature is not a valid method name. 19 | aliased_target, punctuation = target.to_s.sub(/([?!=])$/, ''), $1 20 | yield(aliased_target, punctuation) if block_given? 21 | 22 | with_method = "#{aliased_target}_with_#{feature}#{punctuation}" 23 | without_method = "#{aliased_target}_without_#{feature}#{punctuation}" 24 | 25 | alias_method without_method, target 26 | alias_method target, with_method 27 | 28 | case 29 | when public_method_defined?(without_method) 30 | public target 31 | when protected_method_defined?(without_method) 32 | protected target 33 | when private_method_defined?(without_method) 34 | private target 35 | end 36 | end 37 | end 38 | end 39 | -------------------------------------------------------------------------------- /lib/xray/config.rb: -------------------------------------------------------------------------------- 1 | module Xray 2 | 3 | def self.config 4 | @@config ||= Config.new 5 | end 6 | 7 | class Config 8 | CONFIG_FILE = ".xrayconfig" 9 | 10 | def default_editor 11 | ENV['GEM_EDITOR'] || 12 | ENV['VISUAL'] || 13 | ENV['EDITOR'] || 14 | '/usr/local/bin/subl' 15 | end 16 | 17 | def editor 18 | load_config[:editor] 19 | end 20 | 21 | def editor=(new_editor) 22 | if new_editor && new_editor != editor 23 | write_config(editor: new_editor) 24 | true 25 | else 26 | false 27 | end 28 | end 29 | 30 | def to_yaml 31 | {editor: editor}.to_yaml 32 | end 33 | 34 | def config_file 35 | if File.exist?("#{Dir.pwd}/#{CONFIG_FILE}") 36 | "#{Dir.pwd}/#{CONFIG_FILE}" 37 | else 38 | "#{Dir.home}/#{CONFIG_FILE}" 39 | end 40 | end 41 | 42 | private 43 | 44 | def write_config(new_config) 45 | config = load_config.merge(new_config) 46 | File.open(config_file, 'w') { |f| f.write(config.to_yaml) } 47 | end 48 | 49 | def load_config 50 | default_config.merge(local_config) 51 | end 52 | 53 | def local_config 54 | YAML.load_file(config_file) 55 | rescue 56 | {} 57 | end 58 | 59 | def default_config 60 | { editor: default_editor } 61 | end 62 | end 63 | end 64 | -------------------------------------------------------------------------------- /lib/xray/engine.rb: -------------------------------------------------------------------------------- 1 | module Xray 2 | 3 | # This is the main point of integration with Rails. This engine hooks into 4 | # Sprockets and monkey patches ActionView in order to augment the app's JS 5 | # and HTML templates with filepath information that can be used by xray.js 6 | # in the browser. It also hooks in a middleware responsible for injecting 7 | # xray.js and the xray bar into the app's response bodies. 8 | class Engine < ::Rails::Engine 9 | initializer "xray.initialize" do |app| 10 | app.middleware.use Xray::Middleware 11 | 12 | # Required by Rails 4.1 13 | app.config.assets.precompile += %w(xray.js xray.css) 14 | end 15 | 16 | config.after_initialize do |app| 17 | ensure_asset_pipeline_enabled! app 18 | 19 | # Monkey patch ActionView::Template to augment server-side templates 20 | # with filepath information. See `Xray.augment_template` for details. 21 | ActionView::Template.class_eval do 22 | extend Xray::Aliasing 23 | 24 | def render_with_xray(*args, **kwargs, &block) 25 | path = identifier 26 | view = args.first 27 | source = render_without_xray(*args, **kwargs, &block) 28 | 29 | suitable_template = !(view.respond_to?(:mailer) && view.mailer) && 30 | !path.include?('_xray_bar') && 31 | path =~ /\.(html|slim|haml|hamlc)(\.|$)/ && 32 | path !~ /\.(js|json|css)(\.|$)/ 33 | 34 | options = args.last.kind_of?(Hash) ? args.last : {} 35 | 36 | if source && suitable_template && !(options.has_key?(:xray) && (options[:xray] == false)) 37 | Xray.augment_template(source, path) 38 | else 39 | source 40 | end 41 | end 42 | xray_method_alias :render 43 | end 44 | 45 | # Sprockets preprocessor interface which supports all versions of Sprockets. 46 | # See: https://github.com/rails/sprockets/blob/master/guides/extending_sprockets.md#supporting-all-versions-of-sprockets-in-processors 47 | class JavascriptPreprocessor 48 | def initialize(filename, &block) 49 | @filename = filename 50 | @source = block.call 51 | end 52 | 53 | def render(context, empty_hash_wtf) 54 | self.class.run(@filename, @source, context) 55 | end 56 | 57 | def self.run(filename, source, context) 58 | path = Pathname.new(context.filename).to_s 59 | if path =~ /^#{Rails.root}.+\.(jst)(\.|$)/ 60 | Xray.augment_template(source, path) 61 | else 62 | source 63 | end 64 | end 65 | 66 | def self.call(input) 67 | filename = input[:filename] 68 | source = input[:data] 69 | context = input[:environment].context_class.new(input) 70 | 71 | result = run(filename, source, context) 72 | context.metadata.merge(data: result) 73 | end 74 | end 75 | 76 | # Augment JS templates 77 | app.assets.register_preprocessor 'application/javascript', JavascriptPreprocessor 78 | 79 | # This event is called near the beginning of a request cycle. We use it to 80 | # collect information about the controller and action that is responding, for 81 | # display in the Xray bar. 82 | ActiveSupport::Notifications.subscribe('start_processing.action_controller') do |*args| 83 | event = ActiveSupport::Notifications::Event.new(*args) 84 | controller_name = event.payload[:controller] 85 | action_name = event.payload[:action] 86 | path = ActiveSupport::Dependencies.search_for_file(controller_name.underscore) 87 | 88 | Xray.request_info.clear 89 | 90 | Xray.request_info[:controller] = { 91 | :path => path, 92 | :name => controller_name, 93 | :action => action_name 94 | } 95 | end 96 | 97 | # This event is called each time during the request cycle that 98 | # ActionView renders a template. The first time it's called will most 99 | # likely be the view the controller is rendering, which is what we're 100 | # interested in. 101 | ActiveSupport::Notifications.subscribe('render_template.action_view') do |*args| 102 | event = ActiveSupport::Notifications::Event.new(*args) 103 | layout = event.payload[:layout] 104 | path = event.payload[:identifier] 105 | 106 | # We are only interested in the first notification that has a layout. 107 | if layout 108 | Xray.request_info[:view] ||= { 109 | :path => path, 110 | :layout => layout 111 | } 112 | end 113 | end 114 | end 115 | 116 | def ensure_asset_pipeline_enabled!(app) 117 | unless app.assets 118 | raise "xray-rails requires the Rails asset pipeline. 119 | The asset pipeline is currently disabled in this application. 120 | Either convert your application to use the asset pipeline, or remove xray-rails from your Gemfile." 121 | end 122 | end 123 | end 124 | end 125 | -------------------------------------------------------------------------------- /lib/xray/middleware.rb: -------------------------------------------------------------------------------- 1 | require "open3" 2 | 3 | module Xray 4 | OPEN_PATH = '/_xray/open' 5 | UPDATE_CONFIG_PATH = '/_xray/config' 6 | 7 | # This middleware is responsible for injecting xray.js and the Xray bar into 8 | # the app's pages. It also listens for requests to open files with the user's 9 | # editor. 10 | class Middleware 11 | def initialize(app) 12 | @app = app 13 | end 14 | 15 | def call(env) 16 | # Request for opening a file path. 17 | if env['PATH_INFO'] == OPEN_PATH 18 | req, res = Rack::Request.new(env), Rack::Response.new 19 | out, _err, status = Xray.open_file(req.GET['path']) 20 | if status.success? 21 | res.status = 200 22 | else 23 | res.write out 24 | res.status = 500 25 | end 26 | res.finish 27 | elsif env['PATH_INFO'] == UPDATE_CONFIG_PATH 28 | req, res = Rack::Request.new(env), Rack::Response.new 29 | if req.post? && Xray.config.editor = req.POST['editor'] 30 | res.status = 200 31 | else 32 | res.status = 400 33 | end 34 | res.finish 35 | 36 | # Inject xray.js and friends if this is a successful HTML response 37 | else 38 | status, headers, response = @app.call(env) 39 | 40 | if html_headers?(status, headers) && body = response_body(response) 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 | inject_xray_bar!(body) 48 | end 49 | end 50 | 51 | content_length = body.bytesize.to_s 52 | 53 | # For rails v4.2.0+ compatibility 54 | if defined?(ActionDispatch::Response::RackBody) && ActionDispatch::Response::RackBody === response 55 | response = response.instance_variable_get(:@response) 56 | end 57 | 58 | # Modifying the original response obj maintains compatibility with other middlewares 59 | if ActionDispatch::Response === response 60 | response.body = [body] 61 | response.header['Content-Length'] = content_length unless committed?(response) 62 | response.to_a 63 | else 64 | headers['Content-Length'] = content_length 65 | [status, headers, [body]] 66 | end 67 | else 68 | [status, headers, response] 69 | end 70 | end 71 | end 72 | 73 | private 74 | 75 | def committed?(response) 76 | response.respond_to?(:committed?) && response.committed? 77 | end 78 | 79 | def inject_xray_bar!(html) 80 | html.sub!(/]*>/) { "#{$~}\n#{render_xray_bar}" } 81 | end 82 | 83 | def render_xray_bar 84 | if ApplicationController.respond_to?(:render) 85 | # Rails 5 86 | ApplicationController.render(:partial => "/xray_bar").html_safe 87 | else 88 | # Rails <= 4.2 89 | ac = ActionController::Base.new 90 | ac.render_to_string(:partial => '/xray_bar').html_safe 91 | end 92 | end 93 | 94 | # Matches: 95 | # 96 | # 97 | # 98 | # 99 | def script_matcher(script_name) 100 | / 101 | ]+ 102 | \/#{script_name} 103 | (2|3)? # Optional jQuery version specification 104 | ([-.]{1}[\d\.]+)? # Optional version identifier (e.g. -1.9.1) 105 | ([-.]{1}min)? # Optional -min suffix 106 | (\.self)? # Sprockets 3 appends .self to the filename 107 | (-\h{32,64})? # Fingerprint varies based on Sprockets version 108 | \.js # Must have .js extension 109 | [^>]+><\/script> 110 | /x 111 | end 112 | 113 | # Appends the given `script_name` after the `after_script_name`. 114 | def append_js!(html, after_script_name, script_name) 115 | html.sub!(script_matcher(after_script_name)) do 116 | "#{$~}\n" + helper.javascript_include_tag(script_name) 117 | end 118 | end 119 | 120 | def helper 121 | ActionController::Base.helpers 122 | end 123 | 124 | def html_headers?(status, headers) 125 | status == 200 && 126 | headers['Content-Type'] && 127 | headers['Content-Type'].include?('text/html') && 128 | headers["Content-Transfer-Encoding"] != "binary" 129 | end 130 | 131 | def response_body(response) 132 | body = '' 133 | response.each { |s| body << s.to_s } 134 | body 135 | end 136 | end 137 | end 138 | -------------------------------------------------------------------------------- /lib/xray/version.rb: -------------------------------------------------------------------------------- 1 | module Xray 2 | VERSION = "0.3.3".freeze 3 | end 4 | -------------------------------------------------------------------------------- /script/server: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | (cd spec/dummy && rails s $*) 3 | -------------------------------------------------------------------------------- /spec/dummy/README.rdoc: -------------------------------------------------------------------------------- 1 | == Welcome to Rails 2 | 3 | Rails is a web-application framework that includes everything needed to create 4 | database-backed web applications according to the Model-View-Control pattern. 5 | 6 | This pattern splits the view (also called the presentation) into "dumb" 7 | templates that are primarily responsible for inserting pre-built data in between 8 | HTML tags. The model contains the "smart" domain objects (such as Account, 9 | Product, Person, Post) that holds all the business logic and knows how to 10 | persist themselves to a database. The controller handles the incoming requests 11 | (such as Save New Account, Update Product, Show Post) by manipulating the model 12 | and directing data to the view. 13 | 14 | In Rails, the model is handled by what's called an object-relational mapping 15 | layer entitled Active Record. This layer allows you to present the data from 16 | database rows as objects and embellish these data objects with business logic 17 | methods. You can read more about Active Record in 18 | link:files/vendor/rails/activerecord/README.html. 19 | 20 | The controller and view are handled by the Action Pack, which handles both 21 | layers by its two parts: Action View and Action Controller. These two layers 22 | are bundled in a single package due to their heavy interdependence. This is 23 | unlike the relationship between the Active Record and Action Pack that is much 24 | more separate. Each of these packages can be used independently outside of 25 | Rails. You can read more about Action Pack in 26 | link:files/vendor/rails/actionpack/README.html. 27 | 28 | 29 | == Getting Started 30 | 31 | 1. At the command prompt, create a new Rails application: 32 | rails new myapp (where myapp is the application name) 33 | 34 | 2. Change directory to myapp and start the web server: 35 | cd myapp; rails server (run with --help for options) 36 | 37 | 3. Go to http://localhost:3000/ and you'll see: 38 | "Welcome aboard: You're riding Ruby on Rails!" 39 | 40 | 4. Follow the guidelines to start developing your application. You can find 41 | the following resources handy: 42 | 43 | * The Getting Started Guide: http://guides.rubyonrails.org/getting_started.html 44 | * Ruby on Rails Tutorial Book: http://www.railstutorial.org/ 45 | 46 | 47 | == Debugging Rails 48 | 49 | Sometimes your application goes wrong. Fortunately there are a lot of tools that 50 | will help you debug it and get it back on the rails. 51 | 52 | First area to check is the application log files. Have "tail -f" commands 53 | running on the server.log and development.log. Rails will automatically display 54 | debugging and runtime information to these files. Debugging info will also be 55 | shown in the browser on requests from 127.0.0.1. 56 | 57 | You can also log your own messages directly into the log file from your code 58 | using the Ruby logger class from inside your controllers. Example: 59 | 60 | class WeblogController < ActionController::Base 61 | def destroy 62 | @weblog = Weblog.find(params[:id]) 63 | @weblog.destroy 64 | logger.info("#{Time.now} Destroyed Weblog ID ##{@weblog.id}!") 65 | end 66 | end 67 | 68 | The result will be a message in your log file along the lines of: 69 | 70 | Mon Oct 08 14:22:29 +1000 2007 Destroyed Weblog ID #1! 71 | 72 | More information on how to use the logger is at http://www.ruby-doc.org/core/ 73 | 74 | Also, Ruby documentation can be found at http://www.ruby-lang.org/. There are 75 | several books available online as well: 76 | 77 | * Programming Ruby: http://www.ruby-doc.org/docs/ProgrammingRuby/ (Pickaxe) 78 | * Learn to Program: http://pine.fm/LearnToProgram/ (a beginners guide) 79 | 80 | These two books will bring you up to speed on the Ruby language and also on 81 | programming in general. 82 | 83 | 84 | == Debugger 85 | 86 | Debugger support is available through the debugger command when you start your 87 | Mongrel or WEBrick server with --debugger. This means that you can break out of 88 | execution at any point in the code, investigate and change the model, and then, 89 | resume execution! You need to install ruby-debug to run the server in debugging 90 | mode. With gems, use sudo gem install ruby-debug. Example: 91 | 92 | class WeblogController < ActionController::Base 93 | def index 94 | @posts = Post.all 95 | debugger 96 | end 97 | end 98 | 99 | So the controller will accept the action, run the first line, then present you 100 | with a IRB prompt in the server window. Here you can do things like: 101 | 102 | >> @posts.inspect 103 | => "[#nil, "body"=>nil, "id"=>"1"}>, 105 | #"Rails", "body"=>"Only ten..", "id"=>"2"}>]" 107 | >> @posts.first.title = "hello from a debugger" 108 | => "hello from a debugger" 109 | 110 | ...and even better, you can examine how your runtime objects actually work: 111 | 112 | >> f = @posts.first 113 | => #nil, "body"=>nil, "id"=>"1"}> 114 | >> f. 115 | Display all 152 possibilities? (y or n) 116 | 117 | Finally, when you're ready to resume execution, you can enter "cont". 118 | 119 | 120 | == Console 121 | 122 | The console is a Ruby shell, which allows you to interact with your 123 | application's domain model. Here you'll have all parts of the application 124 | configured, just like it is when the application is running. You can inspect 125 | domain models, change values, and save to the database. Starting the script 126 | without arguments will launch it in the development environment. 127 | 128 | To start the console, run rails console from the application 129 | directory. 130 | 131 | Options: 132 | 133 | * Passing the -s, --sandbox argument will rollback any modifications 134 | made to the database. 135 | * Passing an environment name as an argument will load the corresponding 136 | environment. Example: rails console production. 137 | 138 | To reload your controllers and models after launching the console run 139 | reload! 140 | 141 | More information about irb can be found at: 142 | link:http://www.rubycentral.org/pickaxe/irb.html 143 | 144 | 145 | == dbconsole 146 | 147 | You can go to the command line of your database directly through rails 148 | dbconsole. You would be connected to the database with the credentials 149 | defined in database.yml. Starting the script without arguments will connect you 150 | to the development database. Passing an argument will connect you to a different 151 | database, like rails dbconsole production. Currently works for MySQL, 152 | PostgreSQL and SQLite 3. 153 | 154 | == Description of Contents 155 | 156 | The default directory structure of a generated Ruby on Rails application: 157 | 158 | |-- app 159 | | |-- assets 160 | | | |-- images 161 | | | |-- javascripts 162 | | | `-- stylesheets 163 | | |-- controllers 164 | | |-- helpers 165 | | |-- mailers 166 | | |-- models 167 | | `-- views 168 | | `-- layouts 169 | |-- config 170 | | |-- environments 171 | | |-- initializers 172 | | `-- locales 173 | |-- db 174 | |-- doc 175 | |-- lib 176 | | |-- assets 177 | | `-- tasks 178 | |-- log 179 | |-- public 180 | |-- script 181 | |-- test 182 | | |-- fixtures 183 | | |-- functional 184 | | |-- integration 185 | | |-- performance 186 | | `-- unit 187 | |-- tmp 188 | | `-- cache 189 | | `-- assets 190 | `-- vendor 191 | |-- assets 192 | | |-- javascripts 193 | | `-- stylesheets 194 | `-- plugins 195 | 196 | app 197 | Holds all the code that's specific to this particular application. 198 | 199 | app/assets 200 | Contains subdirectories for images, stylesheets, and JavaScript files. 201 | 202 | app/controllers 203 | Holds controllers that should be named like weblogs_controller.rb for 204 | automated URL mapping. All controllers should descend from 205 | ApplicationController which itself descends from ActionController::Base. 206 | 207 | app/models 208 | Holds models that should be named like post.rb. Models descend from 209 | ActiveRecord::Base by default. 210 | 211 | app/views 212 | Holds the template files for the view that should be named like 213 | weblogs/index.html.erb for the WeblogsController#index action. All views use 214 | eRuby syntax by default. 215 | 216 | app/views/layouts 217 | Holds the template files for layouts to be used with views. This models the 218 | common header/footer method of wrapping views. In your views, define a layout 219 | using the layout :default and create a file named default.html.erb. 220 | Inside default.html.erb, call <% yield %> to render the view using this 221 | layout. 222 | 223 | app/helpers 224 | Holds view helpers that should be named like weblogs_helper.rb. These are 225 | generated for you automatically when using generators for controllers. 226 | Helpers can be used to wrap functionality for your views into methods. 227 | 228 | config 229 | Configuration files for the Rails environment, the routing map, the database, 230 | and other dependencies. 231 | 232 | db 233 | Contains the database schema in schema.rb. db/migrate contains all the 234 | sequence of Migrations for your schema. 235 | 236 | doc 237 | This directory is where your application documentation will be stored when 238 | generated using rake doc:app 239 | 240 | lib 241 | Application specific libraries. Basically, any kind of custom code that 242 | doesn't belong under controllers, models, or helpers. This directory is in 243 | the load path. 244 | 245 | public 246 | The directory available for the web server. Also contains the dispatchers and the 247 | default HTML files. This should be set as the DOCUMENT_ROOT of your web 248 | server. 249 | 250 | script 251 | Helper scripts for automation and generation. 252 | 253 | test 254 | Unit and functional tests along with fixtures. When using the rails generate 255 | command, template test files will be generated for you and placed in this 256 | directory. 257 | 258 | vendor 259 | External libraries that the application depends on. Also includes the plugins 260 | subdirectory. If the app has frozen rails, those gems also go here, under 261 | vendor/rails/. This directory is in the load path. 262 | -------------------------------------------------------------------------------- /spec/dummy/Rakefile: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env rake 2 | # Add your own tasks in files placed in lib/tasks ending in .rake, 3 | # for example lib/tasks/capistrano.rake, and they will automatically be available to Rake. 4 | 5 | require File.expand_path('../config/application', __FILE__) 6 | 7 | Dummy::Application.load_tasks 8 | -------------------------------------------------------------------------------- /spec/dummy/app/assets/javascripts/application.js: -------------------------------------------------------------------------------- 1 | // This is a manifest file that'll be compiled into application.js, which will include all the files 2 | // listed below. 3 | // 4 | // Any JavaScript/Coffee file within this directory, lib/assets/javascripts, vendor/assets/javascripts, 5 | // or vendor/assets/javascripts of plugins, if any, can be referenced here using a relative path. 6 | // 7 | // It's not advisable to add code directly here, but if you do, it'll appear at the bottom of the 8 | // the compiled file. 9 | // 10 | // WARNING: THE FIRST BLANK LINE MARKS THE END OF WHAT'S TO BE PROCESSED, ANY BLANK LINE SHOULD 11 | // GO AFTER THE REQUIRES BELOW. 12 | // 13 | //= require jquery 14 | //= require jquery_ujs 15 | //= require_self 16 | //= require_tree . 17 | 18 | App = {} 19 | -------------------------------------------------------------------------------- /spec/dummy/app/assets/stylesheets/application.css: -------------------------------------------------------------------------------- 1 | /* 2 | * This is a manifest file that'll be compiled into application.css, which will include all the files 3 | * listed below. 4 | * 5 | * Any CSS and SCSS file within this directory, lib/assets/stylesheets, vendor/assets/stylesheets, 6 | * or vendor/assets/stylesheets of plugins, if any, can be referenced here using a relative path. 7 | * 8 | * You're free to add application-wide styles to this file and they'll appear at the top of the 9 | * compiled file, but it's generally better to create a new file per style scope. 10 | * 11 | *= require_self 12 | *= require_tree . 13 | */ 14 | 15 | body { 16 | font-family: "Helvetica Neue", "Helvetica", sans-serif; 17 | font-weight: 200; 18 | } 19 | 20 | .container { 21 | background: rgba(#000, 0.2); 22 | padding: 50px 0; 23 | text-align: center; 24 | margin: 20px; 25 | color: #999; 26 | font-size: 20px; 27 | } 28 | -------------------------------------------------------------------------------- /spec/dummy/app/controllers/application_controller.rb: -------------------------------------------------------------------------------- 1 | class ApplicationController < ActionController::Base 2 | protect_from_forgery 3 | 4 | def root 5 | end 6 | 7 | # For the tests 8 | def non_html 9 | render json: {foo: 'bar'} 10 | end 11 | 12 | def made_with_haml 13 | respond_to :json 14 | end 15 | end 16 | -------------------------------------------------------------------------------- /spec/dummy/app/helpers/application_helper.rb: -------------------------------------------------------------------------------- 1 | module ApplicationHelper 2 | end 3 | -------------------------------------------------------------------------------- /spec/dummy/app/mailer_previews/test_mailer_preview.rb: -------------------------------------------------------------------------------- 1 | class TestMailerPreview < ActionMailer::Preview 2 | def hello 3 | TestMailer.hello 4 | end 5 | end 6 | -------------------------------------------------------------------------------- /spec/dummy/app/mailers/.gitkeep: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/brentd/xray-rails/3d5fe94abee742fff387c393fc5c42db20649e09/spec/dummy/app/mailers/.gitkeep -------------------------------------------------------------------------------- /spec/dummy/app/mailers/test_mailer.rb: -------------------------------------------------------------------------------- 1 | class TestMailer < ActionMailer::Base 2 | def hello 3 | mail to: 'example@example.com', subject: 'hello' 4 | end 5 | end 6 | 7 | -------------------------------------------------------------------------------- /spec/dummy/app/models/.gitkeep: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/brentd/xray-rails/3d5fe94abee742fff387c393fc5c42db20649e09/spec/dummy/app/models/.gitkeep -------------------------------------------------------------------------------- /spec/dummy/app/views/application/_simple_partial.html.erb: -------------------------------------------------------------------------------- 1 |
2 | Element from a partial. 3 |
4 | -------------------------------------------------------------------------------- /spec/dummy/app/views/application/made_with_haml.json.haml: -------------------------------------------------------------------------------- 1 | = {foo: "bar"} 2 | -------------------------------------------------------------------------------- /spec/dummy/app/views/application/root.html.erb: -------------------------------------------------------------------------------- 1 |
2 | Element in the action's template. 3 |
4 | 5 | <%= render partial: 'simple_partial' %> 6 | -------------------------------------------------------------------------------- /spec/dummy/app/views/layouts/application.html.erb: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | Xray 5 | <%= stylesheet_link_tag "application", :media => "all" %> 6 | <%= javascript_include_tag "application" %> 7 | <%= csrf_meta_tags %> 8 | 9 | 10 | 11 | <%= yield %> 12 | 13 | 14 | 15 | -------------------------------------------------------------------------------- /spec/dummy/app/views/test_mailer/hello.html.erb: -------------------------------------------------------------------------------- 1 |

hello

2 | -------------------------------------------------------------------------------- /spec/dummy/config.ru: -------------------------------------------------------------------------------- 1 | # This file is used by Rack-based servers to start the application. 2 | 3 | require ::File.expand_path('../config/environment', __FILE__) 4 | run Dummy::Application 5 | -------------------------------------------------------------------------------- /spec/dummy/config/application.rb: -------------------------------------------------------------------------------- 1 | require File.expand_path('../boot', __FILE__) 2 | 3 | # Pick the frameworks you want: 4 | # require "active_record/railtie" 5 | require "action_controller/railtie" 6 | require "action_mailer/railtie" 7 | # require "active_resource/railtie" 8 | require "sprockets/railtie" 9 | # require "rails/test_unit/railtie" 10 | 11 | Bundler.require(:default, Rails.env) 12 | require 'xray-rails' 13 | 14 | module Dummy 15 | class Application < Rails::Application 16 | # Settings in config/environments/* take precedence over those specified here. 17 | # Application configuration should go into files in config/initializers 18 | # -- all .rb files in that directory are automatically loaded. 19 | 20 | # Custom directories with classes and modules you want to be autoloadable. 21 | # config.autoload_paths += %W(#{config.root}/extras) 22 | 23 | # Only load the plugins named here, in the order given (default is alphabetical). 24 | # :all can be used as a placeholder for all plugins not explicitly named. 25 | # config.plugins = [ :exception_notification, :ssl_requirement, :all ] 26 | 27 | # Activate observers that should always be running. 28 | # config.active_record.observers = :cacher, :garbage_collector, :forum_observer 29 | 30 | # Set Time.zone default to the specified zone and make Active Record auto-convert to this zone. 31 | # Run "rake -D time" for a list of tasks for finding time zone names. Default is UTC. 32 | # config.time_zone = 'Central Time (US & Canada)' 33 | 34 | # The default locale is :en and all translations from config/locales/*.rb,yml are auto loaded. 35 | # config.i18n.load_path += Dir[Rails.root.join('my', 'locales', '*.{rb,yml}').to_s] 36 | # config.i18n.default_locale = :de 37 | 38 | # Configure the default encoding used in templates for Ruby 1.9. 39 | config.encoding = "utf-8" 40 | 41 | # Configure sensitive parameters which will be filtered from the log file. 42 | config.filter_parameters += [:password] 43 | 44 | # Enable escaping HTML in JSON. 45 | config.active_support.escape_html_entities_in_json = true 46 | 47 | # Use SQL instead of Active Record's schema dumper when creating the database. 48 | # This is necessary if your schema can't be completely dumped by the schema dumper, 49 | # like if you have constraints or database-specific column types 50 | # config.active_record.schema_format = :sql 51 | 52 | # Enforce whitelist mode for mass assignment. 53 | # This will create an empty whitelist of attributes available for mass-assignment for all models 54 | # in your app. As such, your models will need to explicitly whitelist or blacklist accessible 55 | # parameters by using an attr_accessible or attr_protected declaration. 56 | # config.active_record.whitelist_attributes = true 57 | 58 | # Enable the asset pipeline 59 | config.assets.enabled = true 60 | 61 | # Version of your assets, change this if you want to expire all your assets 62 | config.assets.version = '1.0' 63 | end 64 | end 65 | 66 | -------------------------------------------------------------------------------- /spec/dummy/config/boot.rb: -------------------------------------------------------------------------------- 1 | require 'rubygems' 2 | gemfile = File.expand_path('../../../../Gemfile', __FILE__) 3 | 4 | if File.exist?(gemfile) 5 | ENV['BUNDLE_GEMFILE'] = gemfile 6 | require 'bundler' 7 | Bundler.setup 8 | end 9 | 10 | $:.unshift File.expand_path('../../../../lib', __FILE__) -------------------------------------------------------------------------------- /spec/dummy/config/database.yml: -------------------------------------------------------------------------------- 1 | # SQLite version 3.x 2 | # gem install sqlite3 3 | # 4 | # Ensure the SQLite 3 gem is defined in your Gemfile 5 | # gem 'sqlite3' 6 | development: 7 | adapter: sqlite3 8 | database: db/development.sqlite3 9 | pool: 5 10 | timeout: 5000 11 | 12 | # Warning: The database defined as "test" will be erased and 13 | # re-generated from your development database when you run "rake". 14 | # Do not set this db to the same as development or production. 15 | test: 16 | adapter: sqlite3 17 | database: db/test.sqlite3 18 | pool: 5 19 | timeout: 5000 20 | 21 | production: 22 | adapter: sqlite3 23 | database: db/production.sqlite3 24 | pool: 5 25 | timeout: 5000 26 | -------------------------------------------------------------------------------- /spec/dummy/config/environment.rb: -------------------------------------------------------------------------------- 1 | # Load the rails application 2 | require File.expand_path('../application', __FILE__) 3 | 4 | # Initialize the rails application 5 | Dummy::Application.initialize! 6 | -------------------------------------------------------------------------------- /spec/dummy/config/environments/development.rb: -------------------------------------------------------------------------------- 1 | Dummy::Application.configure do 2 | # Settings specified here will take precedence over those in config/application.rb 3 | 4 | # In the development environment your application's code is reloaded on 5 | # every request. This slows down response time but is perfect for development 6 | # since you don't have to restart the web server when you make code changes. 7 | config.cache_classes = false 8 | 9 | # Log error messages when you accidentally call methods on nil. 10 | config.whiny_nils = true 11 | 12 | # Show full error reports and disable caching 13 | config.consider_all_requests_local = true 14 | config.action_controller.perform_caching = false 15 | 16 | # Don't care if the mailer can't send 17 | config.action_mailer.raise_delivery_errors = false 18 | 19 | config.action_mailer.preview_path = "#{Rails.root}/app/mailer_previews" 20 | 21 | # Print deprecation notices to the Rails logger 22 | config.active_support.deprecation = :log 23 | 24 | # Only use best-standards-support built into browsers 25 | config.action_dispatch.best_standards_support = :builtin 26 | 27 | # Raise exception on mass assignment protection for Active Record models 28 | # config.active_record.mass_assignment_sanitizer = :strict 29 | 30 | # Log the query plan for queries taking more than this (works 31 | # with SQLite, MySQL, and PostgreSQL) 32 | # config.active_record.auto_explain_threshold_in_seconds = 0.5 33 | 34 | # Do not compress assets 35 | config.assets.compress = false 36 | 37 | # Expands the lines which load the assets 38 | config.assets.debug = true 39 | 40 | config.eager_load = false 41 | end 42 | -------------------------------------------------------------------------------- /spec/dummy/config/environments/production.rb: -------------------------------------------------------------------------------- 1 | Dummy::Application.configure do 2 | # Settings specified here will take precedence over those in config/application.rb 3 | 4 | # Code is not reloaded between requests 5 | config.cache_classes = true 6 | 7 | # Full error reports are disabled and caching is turned on 8 | config.consider_all_requests_local = false 9 | config.action_controller.perform_caching = true 10 | 11 | # Disable Rails's static asset server (Apache or nginx will already do this) 12 | config.serve_static_assets = false 13 | 14 | # Compress JavaScripts and CSS 15 | config.assets.compress = true 16 | 17 | # Don't fallback to assets pipeline if a precompiled asset is missed 18 | config.assets.compile = false 19 | 20 | # Generate digests for assets URLs 21 | config.assets.digest = true 22 | 23 | # Defaults to nil and saved in location specified by config.assets.prefix 24 | # config.assets.manifest = YOUR_PATH 25 | 26 | # Specifies the header that your server uses for sending files 27 | # config.action_dispatch.x_sendfile_header = "X-Sendfile" # for apache 28 | # config.action_dispatch.x_sendfile_header = 'X-Accel-Redirect' # for nginx 29 | 30 | # Force all access to the app over SSL, use Strict-Transport-Security, and use secure cookies. 31 | # config.force_ssl = true 32 | 33 | # See everything in the log (default is :info) 34 | # config.log_level = :debug 35 | 36 | # Prepend all log lines with the following tags 37 | # config.log_tags = [ :subdomain, :uuid ] 38 | 39 | # Use a different logger for distributed setups 40 | # config.logger = ActiveSupport::TaggedLogging.new(SyslogLogger.new) 41 | 42 | # Use a different cache store in production 43 | # config.cache_store = :mem_cache_store 44 | 45 | # Enable serving of images, stylesheets, and JavaScripts from an asset server 46 | # config.action_controller.asset_host = "http://assets.example.com" 47 | 48 | # Precompile additional assets (application.js, application.css, and all non-JS/CSS are already added) 49 | # config.assets.precompile += %w( search.js ) 50 | 51 | # Disable delivery errors, bad email addresses will be ignored 52 | # config.action_mailer.raise_delivery_errors = false 53 | 54 | # Enable threaded mode 55 | # config.threadsafe! 56 | 57 | # Enable locale fallbacks for I18n (makes lookups for any locale fall back to 58 | # the I18n.default_locale when a translation can not be found) 59 | config.i18n.fallbacks = true 60 | 61 | # Send deprecation notices to registered listeners 62 | config.active_support.deprecation = :notify 63 | 64 | # Log the query plan for queries taking more than this (works 65 | # with SQLite, MySQL, and PostgreSQL) 66 | # config.active_record.auto_explain_threshold_in_seconds = 0.5 67 | end 68 | -------------------------------------------------------------------------------- /spec/dummy/config/environments/test.rb: -------------------------------------------------------------------------------- 1 | Dummy::Application.configure do 2 | # Settings specified here will take precedence over those in config/application.rb 3 | 4 | # The test environment is used exclusively to run your application's 5 | # test suite. You never need to work with it otherwise. Remember that 6 | # your test database is "scratch space" for the test suite and is wiped 7 | # and recreated between test runs. Don't rely on the data there! 8 | config.cache_classes = true 9 | 10 | # Configure static asset server for tests with Cache-Control for performance 11 | config.serve_static_assets = true 12 | config.static_cache_control = "public, max-age=3600" 13 | 14 | # Log error messages when you accidentally call methods on nil 15 | config.whiny_nils = true 16 | 17 | # Show full error reports and disable caching 18 | config.consider_all_requests_local = true 19 | config.action_controller.perform_caching = false 20 | 21 | # Raise exceptions instead of rendering exception templates 22 | config.action_dispatch.show_exceptions = false 23 | 24 | # Disable request forgery protection in test environment 25 | config.action_controller.allow_forgery_protection = false 26 | 27 | # Tell Action Mailer not to deliver emails to the real world. 28 | # The :test delivery method accumulates sent emails in the 29 | # ActionMailer::Base.deliveries array. 30 | config.action_mailer.delivery_method = :test 31 | 32 | # Raise exception on mass assignment protection for Active Record models 33 | config.active_record.mass_assignment_sanitizer = :strict 34 | 35 | # Print deprecation notices to the stderr 36 | config.active_support.deprecation = :stderr 37 | end 38 | -------------------------------------------------------------------------------- /spec/dummy/config/initializers/backtrace_silencers.rb: -------------------------------------------------------------------------------- 1 | # Be sure to restart your server when you modify this file. 2 | 3 | # You can add backtrace silencers for libraries that you're using but don't wish to see in your backtraces. 4 | # Rails.backtrace_cleaner.add_silencer { |line| line =~ /my_noisy_library/ } 5 | 6 | # You can also remove all the silencers if you're trying to debug a problem that might stem from framework code. 7 | # Rails.backtrace_cleaner.remove_silencers! 8 | -------------------------------------------------------------------------------- /spec/dummy/config/initializers/inflections.rb: -------------------------------------------------------------------------------- 1 | # Be sure to restart your server when you modify this file. 2 | 3 | # Add new inflection rules using the following format 4 | # (all these examples are active by default): 5 | # ActiveSupport::Inflector.inflections do |inflect| 6 | # inflect.plural /^(ox)$/i, '\1en' 7 | # inflect.singular /^(ox)en/i, '\1' 8 | # inflect.irregular 'person', 'people' 9 | # inflect.uncountable %w( fish sheep ) 10 | # end 11 | # 12 | # These inflection rules are supported but not enabled by default: 13 | # ActiveSupport::Inflector.inflections do |inflect| 14 | # inflect.acronym 'RESTful' 15 | # end 16 | -------------------------------------------------------------------------------- /spec/dummy/config/initializers/mime_types.rb: -------------------------------------------------------------------------------- 1 | # Be sure to restart your server when you modify this file. 2 | 3 | # Add new mime types for use in respond_to blocks: 4 | # Mime::Type.register "text/richtext", :rtf 5 | # Mime::Type.register_alias "text/html", :iphone 6 | -------------------------------------------------------------------------------- /spec/dummy/config/initializers/secret_token.rb: -------------------------------------------------------------------------------- 1 | # Be sure to restart your server when you modify this file. 2 | 3 | # Your secret key for verifying the integrity of signed cookies. 4 | # If you change this key, all old signed cookies will become invalid! 5 | # Make sure the secret is at least 30 characters and all random, 6 | # no regular words or you'll be exposed to dictionary attacks. 7 | Dummy::Application.config.secret_token = '993d42039ba9bc9e9b994437c737ce3e3519a9dba12b9f03bcca9da037120f105f924b8fcd80cd460d933b86ef293f4f45b78d7e20a3587613519c8992e4fa22' 8 | -------------------------------------------------------------------------------- /spec/dummy/config/initializers/session_store.rb: -------------------------------------------------------------------------------- 1 | # Be sure to restart your server when you modify this file. 2 | 3 | Dummy::Application.config.session_store :cookie_store, key: '_dummy_session' 4 | 5 | # Use the database for sessions instead of the cookie-based default, 6 | # which shouldn't be used to store highly confidential information 7 | # (create the session table with "rails generate session_migration") 8 | # Dummy::Application.config.session_store :active_record_store 9 | -------------------------------------------------------------------------------- /spec/dummy/config/initializers/wrap_parameters.rb: -------------------------------------------------------------------------------- 1 | # Be sure to restart your server when you modify this file. 2 | # 3 | # This file contains settings for ActionController::ParamsWrapper which 4 | # is enabled by default. 5 | 6 | # Enable parameter wrapping for JSON. You can disable this by setting :format to an empty array. 7 | ActiveSupport.on_load(:action_controller) do 8 | wrap_parameters format: [:json] 9 | end 10 | 11 | # Disable root element in JSON by default. 12 | ActiveSupport.on_load(:active_record) do 13 | self.include_root_in_json = false 14 | end 15 | -------------------------------------------------------------------------------- /spec/dummy/config/locales/en.yml: -------------------------------------------------------------------------------- 1 | # Sample localization file for English. Add more files in this directory for other locales. 2 | # See https://github.com/svenfuchs/rails-i18n/tree/master/rails%2Flocale for starting points. 3 | 4 | en: 5 | hello: "Hello world" 6 | -------------------------------------------------------------------------------- /spec/dummy/config/routes.rb: -------------------------------------------------------------------------------- 1 | Dummy::Application.routes.draw do 2 | root to: 'application#root' 3 | get '/:action', controller: 'application' 4 | end 5 | -------------------------------------------------------------------------------- /spec/dummy/db/.gitkeep: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/brentd/xray-rails/3d5fe94abee742fff387c393fc5c42db20649e09/spec/dummy/db/.gitkeep -------------------------------------------------------------------------------- /spec/dummy/log/.gitkeep: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/brentd/xray-rails/3d5fe94abee742fff387c393fc5c42db20649e09/spec/dummy/log/.gitkeep -------------------------------------------------------------------------------- /spec/dummy/public/404.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | The page you were looking for doesn't exist (404) 5 | 17 | 18 | 19 | 20 | 21 |
22 |

The page you were looking for doesn't exist.

23 |

You may have mistyped the address or the page may have moved.

24 |
25 | 26 | 27 | -------------------------------------------------------------------------------- /spec/dummy/public/422.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | The change you wanted was rejected (422) 5 | 17 | 18 | 19 | 20 | 21 |
22 |

The change you wanted was rejected.

23 |

Maybe you tried to change something you didn't have access to.

24 |
25 | 26 | 27 | -------------------------------------------------------------------------------- /spec/dummy/public/500.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | We're sorry, but something went wrong (500) 5 | 17 | 18 | 19 | 20 | 21 |
22 |

We're sorry, but something went wrong.

23 |
24 | 25 | 26 | -------------------------------------------------------------------------------- /spec/dummy/public/favicon.ico: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/brentd/xray-rails/3d5fe94abee742fff387c393fc5c42db20649e09/spec/dummy/public/favicon.ico -------------------------------------------------------------------------------- /spec/dummy/script/rails: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env ruby 2 | # This command will automatically be run when you run "rails" with Rails 3 gems installed from the root of your application. 3 | 4 | APP_PATH = File.expand_path('../../config/application', __FILE__) 5 | require File.expand_path('../../config/boot', __FILE__) 6 | require 'rails/commands' 7 | -------------------------------------------------------------------------------- /spec/spec_helper.rb: -------------------------------------------------------------------------------- 1 | require File.expand_path("../dummy/config/environment", __FILE__) 2 | require 'rspec/rails' 3 | require 'capybara/rspec' 4 | 5 | class String 6 | def unindent 7 | gsub(/^#{scan(/^\s*/).min_by{|l|l.length}}/, "").chomp! 8 | end 9 | end 10 | 11 | RSpec.configure do |config| 12 | config.include Capybara::DSL 13 | config.include Capybara::RSpecMatchers 14 | end 15 | 16 | Capybara.configure do |config| 17 | config.ignore_hidden_elements = false 18 | end 19 | -------------------------------------------------------------------------------- /spec/xray/augmentation_spec.rb: -------------------------------------------------------------------------------- 1 | require 'spec_helper' 2 | 3 | describe "Xray.augment_template" do 4 | it "wraps HTML source with comments containing the path" do 5 | Xray.stub(next_id: 1) 6 | source = <<-END.unindent 7 |
8 |
9 | END 10 | augmented = Xray.augment_template(source, "/path/to/file.html.erb") 11 | expect(augmented).to eql <<-END.unindent 12 | 13 |
14 |
15 | 16 | END 17 | end 18 | 19 | it "does not wrap templates beginning with a doctype" do 20 | source = <<-END.unindent 21 | 22 | foo 23 | END 24 | augmented = Xray.augment_template(source, "/path/to/file.html.erb") 25 | expect(augmented).to eql <<-END.unindent 26 | 27 | foo 28 | END 29 | end 30 | end 31 | -------------------------------------------------------------------------------- /spec/xray/command_spec.rb: -------------------------------------------------------------------------------- 1 | require 'spec_helper' 2 | 3 | describe 'Xray.open_file' do 4 | let(:file) { '/path/to/file' } 5 | 6 | it "uses the configured editor" do 7 | Xray.config.stub(editor: 'cool_editor') 8 | Open3.should_receive(:capture3).with("cool_editor \"#{file}\"") 9 | Xray.open_file(file) 10 | end 11 | 12 | it "replace $file in the editor command with the filename" do 13 | Xray.config.stub(editor: 'cool_editor --open "$file"') 14 | Open3.should_receive(:capture3).with("cool_editor --open \"#{file}\"") 15 | Xray.open_file(file) 16 | end 17 | end 18 | -------------------------------------------------------------------------------- /spec/xray/config_spec.rb: -------------------------------------------------------------------------------- 1 | require 'spec_helper' 2 | 3 | describe Xray::Config do 4 | context 'default_editor' do 5 | before do 6 | Xray.config.stub(:local_config).and_return({}) 7 | end 8 | 9 | it 'should default to /usr/local/bin/subl' do 10 | ENV.stub(:[]) 11 | Xray.config.editor.should eq('/usr/local/bin/subl') 12 | end 13 | 14 | it 'should use $GEM_EDITOR over $VISUAL and $EDITOR' do 15 | ENV['GEM_EDITOR'] = 'vim' 16 | ENV['VISUAL'] = 'emacs' 17 | ENV['EDITOR'] = 'emacs' 18 | Xray.config.editor.should eq('vim') 19 | end 20 | 21 | it 'should use $VISUAL over $EDITOR' do 22 | ENV['GEM_EDITOR'] = nil 23 | ENV['VISUAL'] = 'vim' 24 | ENV['EDITOR'] = 'emacs' 25 | Xray.config.editor.should eq('vim') 26 | end 27 | 28 | it 'should use $HOME/.xrayconfig over env variables' do 29 | ENV['GEM_EDITOR'] = 'vim' 30 | Xray.config.stub(:local_config).and_return(editor: 'emacs') 31 | Xray.config.editor.should eq('emacs') 32 | end 33 | end 34 | 35 | context ".config_file" do 36 | it "should use $HOME/.xrayconfig as default config file" do 37 | Dir.stub(:home).and_return('/home') 38 | Xray.config.config_file.should eq('/home/.xrayconfig') 39 | end 40 | 41 | it "should use $PROJECT/.xrayconfig if it exists" do 42 | File.stub(:exist?).and_return(true) 43 | Dir.stub(:pwd).and_return('/project') 44 | Xray.config.config_file.should eq("/project/.xrayconfig") 45 | end 46 | end 47 | end 48 | -------------------------------------------------------------------------------- /spec/xray/engine_spec.rb: -------------------------------------------------------------------------------- 1 | require 'spec_helper' 2 | 3 | describe Xray::Engine do 4 | context 'ActionView::Template monkeypatch #render' do 5 | subject { ActionView::Template.new(nil, nil, nil, {}) } 6 | let(:xray_enabled_render_args) { ['template', { example_option: true }] } 7 | let(:xray_disabled_render_args) { ['template', { example_option: true, xray: false }] } 8 | let(:render_result) { 'Example' } 9 | let(:plain_text_result) { 'Example' } 10 | let(:augmented_render_result) { 'Example' } 11 | let(:html_identifier) { 'template.html' } 12 | let(:txt_identifier) { 'template.txt' } 13 | 14 | it 'should render and augment valid HTML like files by default' do 15 | subject.should_receive(:render_without_xray).with(*xray_enabled_render_args).and_return(render_result) 16 | subject.should_receive(:identifier).and_return(html_identifier) 17 | Xray.should_receive(:augment_template).with(render_result, html_identifier).and_return(augmented_render_result) 18 | expect(subject.render(*xray_enabled_render_args)).to eql(augmented_render_result) 19 | end 20 | 21 | it 'should render and augment when template source is an empty string' do 22 | subject.should_receive(:render_without_xray).with(*xray_enabled_render_args).and_return('') 23 | subject.should_receive(:identifier).and_return(html_identifier) 24 | Xray.should_receive(:augment_template).with('', html_identifier).and_return(augmented_render_result) 25 | expect(subject.render(*xray_enabled_render_args)).to eql(augmented_render_result) 26 | end 27 | 28 | it 'should render but not augment HTML if :xray => false passed as an option' do 29 | subject.should_receive(:render_without_xray).with(*xray_enabled_render_args).and_return(render_result) 30 | subject.should_receive(:identifier).and_return(html_identifier) 31 | Xray.should_receive(:augment_template).with(render_result, html_identifier).and_return(augmented_render_result) 32 | expect(subject.render(*xray_enabled_render_args)).to eql(augmented_render_result) 33 | end 34 | 35 | it 'should render but not augment non HTML files' do 36 | subject.should_receive(:render_without_xray).with(*xray_disabled_render_args).and_return(plain_text_result) 37 | subject.should_receive(:identifier).and_return(txt_identifier) 38 | Xray.should_not_receive(:augment_template) 39 | expect(subject.render(*xray_disabled_render_args)).to eql(plain_text_result) 40 | end 41 | 42 | it 'should render but not augment when template source is nil' do 43 | subject.should_receive(:render_without_xray).with(*xray_enabled_render_args).and_return(nil) 44 | subject.should_receive(:identifier).and_return(html_identifier) 45 | Xray.should_not_receive(:augment_template) 46 | expect(subject.render(*xray_enabled_render_args)).to eql(nil) 47 | end 48 | end 49 | end 50 | 51 | -------------------------------------------------------------------------------- /spec/xray/middleware_spec.rb: -------------------------------------------------------------------------------- 1 | require 'spec_helper' 2 | 3 | describe Xray::Middleware, "in a middleware stack" do 4 | def mock_response(status, content_type, body) 5 | body = body.unindent 6 | app = Rack::Builder.new do 7 | use Xray::Middleware 8 | run lambda { |env| [status, {'Content-Type' => content_type}, [body]] } 9 | end 10 | Rack::MockRequest.new(app).get('/') 11 | end 12 | 13 | context "when the response is html and contains " do 14 | it "injects the xray bar and xray.js" do 15 | response = mock_response 200, 'text/html', <<-HTML 16 | 17 | 18 | 19 | 20 | 21 | 22 | HTML 23 | expect(response.body).to have_selector('#xray-bar') 24 | expect(response.body).to have_selector('script[src^="/assets/xray"]') 25 | end 26 | 27 | it "does not inject xray.js or the xray bar if jquery is not found" do 28 | response = mock_response 200, 'text/html', <<-HTML 29 | 30 | 31 | 32 | 33 | HTML 34 | expect(response.body).to_not have_selector('#xray-bar') 35 | expect(response.body).to_not have_selector('script[src^="/assets/xray"]') 36 | end 37 | 38 | it "does inject xray.js or the xray bar if jquery2 is found" do 39 | response = mock_response 200, 'text/html', <<-HTML 40 | 41 | 42 | 43 | 44 | 45 | 46 | HTML 47 | expect(response.body).to have_selector('#xray-bar') 48 | expect(response.body).to have_selector('script[src^="/assets/xray"]') 49 | end 50 | 51 | it "does inject xray.js or the xray bar if jquery3 is found" do 52 | response = mock_response 200, 'text/html', <<-HTML 53 | 54 | 55 | 56 | 57 | 58 | 59 | HTML 60 | expect(response.body).to have_selector('#xray-bar') 61 | expect(response.body).to have_selector('script[src^="/assets/xray"]') 62 | end 63 | end 64 | 65 | context "when the response does not contain " do 66 | it "does not inject xray bar or xray.js" do 67 | response = mock_response 200, 'text/html', <<-HTML 68 |
just some html
69 | HTML 70 | expect(response.body).to_not have_selector('#xray-bar') 71 | expect(response.body).to_not have_selector('script[src^="/assets/xray"]') 72 | end 73 | end 74 | 75 | context "when the response is blank" do 76 | it "does not inject xray" do 77 | response = mock_response 200, 'text/html', '' 78 | expect(response.body).to_not have_selector('#xray-bar') 79 | expect(response.body).to_not have_selector('script[src^="/assets/xray"]') 80 | end 81 | end 82 | 83 | context "when the response is unsuccessful" do 84 | it "does not inject xray" do 85 | response = mock_response 500, 'text/html', '' 86 | expect(response.body).to_not have_selector('#xray-bar') 87 | expect(response.body).to_not have_selector('script[src^="/assets/xray"]') 88 | end 89 | end 90 | end 91 | 92 | describe Xray::Middleware, "in a Rails app" do 93 | it "injects xray.js into the response" do 94 | visit '/' 95 | expect(page).to have_selector('script[src^="/assets/xray"]') 96 | end 97 | 98 | it "injects the xray bar into the response" do 99 | visit '/' 100 | expect(page).to have_selector('#xray-bar') 101 | end 102 | 103 | it "doesn't mess with non-html requests" do 104 | visit '/non_html' 105 | expect(page.html).not_to include('xray') 106 | expect(page).not_to have_selector('#xray-bar') 107 | end 108 | 109 | context "edge cases" do 110 | it "does not add html comments to json.haml pages" do 111 | visit '/made_with_haml.json' 112 | expect(page.html).not_to include('