open_code-rails 0.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,7 @@
1
+ ---
2
+ sudo: false
3
+ language: ruby
4
+ cache: bundler
5
+ rvm:
6
+ - 2.5.3
7
+ before_install: gem install bundler -v 2.0.1
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source "https://rubygems.org"
2
+
3
+ # Specify your gem's dependencies in open_code-rails.gemspec
4
+ gemspec
@@ -0,0 +1,113 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ open_code-rails (0.1.0)
5
+ railties (>= 4.2)
6
+
7
+ GEM
8
+ remote: https://rubygems.org/
9
+ specs:
10
+ actionpack (5.2.2)
11
+ actionview (= 5.2.2)
12
+ activesupport (= 5.2.2)
13
+ rack (~> 2.0)
14
+ rack-test (>= 0.6.3)
15
+ rails-dom-testing (~> 2.0)
16
+ rails-html-sanitizer (~> 1.0, >= 1.0.2)
17
+ actionview (5.2.2)
18
+ activesupport (= 5.2.2)
19
+ builder (~> 3.1)
20
+ erubi (~> 1.4)
21
+ rails-dom-testing (~> 2.0)
22
+ rails-html-sanitizer (~> 1.0, >= 1.0.3)
23
+ activesupport (5.2.2)
24
+ concurrent-ruby (~> 1.0, >= 1.0.2)
25
+ i18n (>= 0.7, < 2)
26
+ minitest (~> 5.1)
27
+ tzinfo (~> 1.1)
28
+ ast (2.4.0)
29
+ builder (3.2.3)
30
+ byebug (11.0.0)
31
+ coderay (1.1.2)
32
+ concurrent-ruby (1.1.4)
33
+ crass (1.0.4)
34
+ diff-lcs (1.3)
35
+ erubi (1.8.0)
36
+ i18n (1.6.0)
37
+ concurrent-ruby (~> 1.0)
38
+ jaro_winkler (1.5.2)
39
+ loofah (2.2.3)
40
+ crass (~> 1.0.2)
41
+ nokogiri (>= 1.5.9)
42
+ method_source (0.9.2)
43
+ mini_portile2 (2.4.0)
44
+ minitest (5.11.3)
45
+ nokogiri (1.10.1)
46
+ mini_portile2 (~> 2.4.0)
47
+ parallel (1.14.0)
48
+ parser (2.6.0.0)
49
+ ast (~> 2.4.0)
50
+ powerpack (0.1.2)
51
+ pry (0.12.2)
52
+ coderay (~> 1.1.0)
53
+ method_source (~> 0.9.0)
54
+ pry-byebug (3.7.0)
55
+ byebug (~> 11.0)
56
+ pry (~> 0.10)
57
+ rack (2.0.6)
58
+ rack-test (1.1.0)
59
+ rack (>= 1.0, < 3)
60
+ rails-dom-testing (2.0.3)
61
+ activesupport (>= 4.2.0)
62
+ nokogiri (>= 1.6)
63
+ rails-html-sanitizer (1.0.4)
64
+ loofah (~> 2.2, >= 2.2.2)
65
+ railties (5.2.2)
66
+ actionpack (= 5.2.2)
67
+ activesupport (= 5.2.2)
68
+ method_source
69
+ rake (>= 0.8.7)
70
+ thor (>= 0.19.0, < 2.0)
71
+ rainbow (3.0.0)
72
+ rake (10.5.0)
73
+ rspec (3.8.0)
74
+ rspec-core (~> 3.8.0)
75
+ rspec-expectations (~> 3.8.0)
76
+ rspec-mocks (~> 3.8.0)
77
+ rspec-core (3.8.0)
78
+ rspec-support (~> 3.8.0)
79
+ rspec-expectations (3.8.2)
80
+ diff-lcs (>= 1.2.0, < 2.0)
81
+ rspec-support (~> 3.8.0)
82
+ rspec-mocks (3.8.0)
83
+ diff-lcs (>= 1.2.0, < 2.0)
84
+ rspec-support (~> 3.8.0)
85
+ rspec-support (3.8.0)
86
+ rubocop (0.58.2)
87
+ jaro_winkler (~> 1.5.1)
88
+ parallel (~> 1.10)
89
+ parser (>= 2.5, != 2.5.1.1)
90
+ powerpack (~> 0.1)
91
+ rainbow (>= 2.2.2, < 4.0)
92
+ ruby-progressbar (~> 1.7)
93
+ unicode-display_width (~> 1.0, >= 1.0.1)
94
+ ruby-progressbar (1.10.0)
95
+ thor (0.20.3)
96
+ thread_safe (0.3.6)
97
+ tzinfo (1.2.5)
98
+ thread_safe (~> 0.1)
99
+ unicode-display_width (1.5.0)
100
+
101
+ PLATFORMS
102
+ ruby
103
+
104
+ DEPENDENCIES
105
+ bundler (~> 2.0)
106
+ open_code-rails!
107
+ pry-byebug
108
+ rake (~> 10.0)
109
+ rspec (~> 3.0)
110
+ rubocop
111
+
112
+ BUNDLED WITH
113
+ 2.0.1
data/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2019 James
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
@@ -0,0 +1,65 @@
1
+ # OpenCode::Rails
2
+
3
+ Add links in exception page to open Application Trace file to line in VSCode. Now only support [VSCode](https://code.visualstudio.com/) or [VSCodium](https://github.com/VSCodium/vscodium).
4
+
5
+ - Show VSCode icons
6
+ ![icons](screenshots/icons.png)
7
+ - Click to open vscode/vscodium
8
+ ![open](screenshots/open.png)
9
+ - Open file to line
10
+ ![to_line](screenshots/to_line.png)
11
+ - Custom Settings and Full Trace
12
+ ![config_full_trace](screenshots/config_full_trace.png)
13
+
14
+ ## Installation
15
+
16
+ Add following to your Rails `Gemfile`:
17
+
18
+ ```ruby
19
+ group :development do
20
+ gem 'open_code-rails'
21
+ end
22
+ ```
23
+
24
+ ## How it works
25
+
26
+ VSCode supports [Opening VS Code with URLs](https://code.visualstudio.com/docs/editor/command-line#_opening-vs-code-with-urls).
27
+
28
+ This gem simply inject some CSS and JS to HTML response while status is 500. Your browser will parse DOM and generate new links.
29
+
30
+ ## Configuration
31
+
32
+ You should put settings in `config/environments/development.rb` because this gem should only work in dev server. It will prevent production server starting up.
33
+
34
+ 1. `config.open_code.editor` - default: `'vscode'`
35
+
36
+ Currently only support `'vscode'` and `'vscodium'`. It will be used to link's scheme part, like `vscode://` or `vscodium://`. You can set it any string but probably won't work, unless your editor supports `<scheme>://file/<absolute file path>`.
37
+
38
+ ```ruby
39
+ # config/environments/development.rb
40
+ Rails.application.configure do
41
+ config.open_code.editor = 'vscodium'
42
+ end
43
+ ```
44
+
45
+ 2. `config.open_code.place_holder` - default: `''` (blank)
46
+
47
+ Leave it blank will display links as VSCode icon. If you set it to a string, it will display text rather than icon. In case your browser does not support SVG Data URI in CSS, or you don't like the icon.
48
+
49
+ ```ruby
50
+ # config/environments/development.rb
51
+ Rails.application.configure do
52
+ config.open_code.place_holder = 'Open in VSCodium'
53
+ end
54
+ ```
55
+
56
+ 3. `config.open_code.root_dir` - default: `::Rails.root`
57
+
58
+ The absolute path of your Rails project folder. Sometimes you may run dev server remotely, so you need to set it to your local path.
59
+
60
+ ```ruby
61
+ # config/environments/development.rb
62
+ Rails.application.configure do
63
+ config.open_code.editor = '/Users/MyName/projects'
64
+ end
65
+ ```
@@ -0,0 +1,6 @@
1
+ require "bundler/gem_tasks"
2
+ require "rspec/core/rake_task"
3
+
4
+ RSpec::Core::RakeTask.new(:spec)
5
+
6
+ task(default: :spec)
@@ -0,0 +1,7 @@
1
+ require "open_code/rails/version"
2
+ require "open_code/rails/railtie"
3
+
4
+ module OpenCode
5
+ module Rails
6
+ end
7
+ end
@@ -0,0 +1,26 @@
1
+ module OpenCode
2
+ module Rails
3
+ module ConstAssets
4
+ ICONS = {
5
+ vscode: <<-XML.strip_heredoc,
6
+ <?xml version="1.0" encoding="UTF-8" standalone="no"?>
7
+ <svg xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:cc="http://creativecommons.org/ns#" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:svg="http://www.w3.org/2000/svg" xmlns="http://www.w3.org/2000/svg" xmlns:sodipodi="http://sodipodi.sourceforge.net/DTD/sodipodi-0.dtd" xmlns:inkscape="http://www.inkscape.org/namespaces/inkscape" viewBox="0 0 261 260" fill-rule="evenodd" clip-rule="evenodd" stroke-linejoin="round" stroke-miterlimit="1.414" version="1.1" id="svg4" sodipodi:docname="vscode.svg" inkscape:version="0.92.2 (unknown)">
8
+ <metadata id="metadata10">
9
+ <rdf:RDF>
10
+ <cc:Work rdf:about="">
11
+ <dc:format>image/svg+xml</dc:format>
12
+ <dc:type rdf:resource="http://purl.org/dc/dcmitype/StillImage"/>
13
+ <dc:title/>
14
+ </cc:Work>
15
+ </rdf:RDF>
16
+ </metadata>
17
+ <defs id="defs8"/>
18
+ <sodipodi:namedview pagecolor="#ffffff" bordercolor="#666666" borderopacity="1" objecttolerance="10" gridtolerance="10" guidetolerance="10" inkscape:pageopacity="0" inkscape:pageshadow="2" inkscape:window-width="1360" inkscape:window-height="722" id="namedview6" showgrid="false" inkscape:zoom="0.64183539" inkscape:cx="112.48701" inkscape:cy="128.72041" inkscape:window-x="0" inkscape:window-y="24" inkscape:window-maximized="1" inkscape:current-layer="svg4"/>
19
+ <path d="M 195.47461 -0.005859375 L 195.47461 223.29688 L 0.49609375 194.33789 L 195.47461 259.99219 L 260.47461 232.95312 L 260.47461 31.064453 L 260.49609 31.054688 L 260.47461 31.011719 L 260.47461 27.035156 L 195.47461 -0.005859375 z " id="path951" style="fill:#C52E23;fill-opacity:1"/>
20
+ <path d="M 127.24219 38.037109 L 67.521484 97.070312 L 31.566406 69.992188 L 16.748047 74.941406 L 53.328125 111.10156 L 16.748047 147.25977 L 31.566406 152.21094 L 67.521484 125.13086 L 67.523438 125.13086 L 127.24023 184.16016 L 163.00781 168.96289 L 163.00781 53.234375 L 127.24219 38.037109 z M 127.24023 80.158203 L 127.24023 142.03711 L 86.154297 111.09766 L 127.24023 80.158203 z " id="path887" style="fill:#C52E23;fill-opacity:1"/>
21
+ </svg>
22
+ XML
23
+ }
24
+ end
25
+ end
26
+ end
@@ -0,0 +1,64 @@
1
+ require 'base64'
2
+
3
+ module OpenCode
4
+ module Rails
5
+ class Middleware
6
+ cattr_accessor :css
7
+ cattr_accessor :place_holder
8
+ cattr_accessor :root_dir
9
+ cattr_accessor :scheme
10
+
11
+ def initialize(app)
12
+ @app = app
13
+ end
14
+
15
+ def call(env)
16
+ res = nil
17
+ begin
18
+ res = @app.call(env)
19
+ status, headers, body = res
20
+ return res unless status == 500 && headers['Content-Type'].to_s.include?('html')
21
+
22
+ script = <<-JS.strip_heredoc
23
+ (function () {
24
+ setTimeout(function () {
25
+ var prefix = '#{scheme}://file/#{root_dir}';
26
+ var tmp = document.createElement('div');
27
+ var items = document.querySelectorAll('#Application-Trace .trace-frames');
28
+ for (var i = 0; i < items.length; i += 1) {
29
+ var item = items[i];
30
+ var frameId = item.dataset.frameId;
31
+ var uri = encodeURI([prefix, item.innerText.split(':in')[0]].join('/'));
32
+ var html = '<a href="' + uri + '" class="-gem-open-me-link">#{place_holder}</a>';
33
+
34
+ var links = document.querySelectorAll('[data-frame-id=' + JSON.stringify(frameId) + ']');
35
+ for (var j = 0; j < links.length; j += 1) {
36
+ var link = links[j];
37
+ tmp.innerHTML = html;
38
+ link.parentElement.insertBefore(tmp.firstChild, link.nextSibling);
39
+ }
40
+ }
41
+ }, 0);
42
+ })();
43
+ JS
44
+
45
+ html = ''
46
+ body.each { |part| html << part }
47
+ html.sub!('</body>', "<style>#{css}</style><script>#{script}</script></body>")
48
+ body = html.encode('utf-8')
49
+ headers['Content-Length'] = body.size
50
+ [status, headers, [body]]
51
+ rescue => e
52
+ ::Rails.logger.error do
53
+ <<-LOG.strip_heredoc
54
+ [OpenCode::Rails::Middleware] #{e.class}: #{e}
55
+ Sorry still something went wrong
56
+ from #{e.backtrace.join("\n ")}
57
+ LOG
58
+ end
59
+ res
60
+ end
61
+ end
62
+ end
63
+ end
64
+ end
@@ -0,0 +1,61 @@
1
+ require "rails/railtie"
2
+
3
+ module OpenCode
4
+ module Rails
5
+ class Railtie < ::Rails::Railtie
6
+ config.open_code = ActiveSupport::OrderedOptions.new
7
+ config.open_code.editor = 'vscode'
8
+
9
+ initializer "open_code.initialize" do
10
+ abort('open_code-rails should not be used in production mode!') if ::Rails.env.production?
11
+ end
12
+
13
+ initializer "open_code.insert_middleware" do |app|
14
+ next if ::Rails.env.production? || !defined?(::Rails::Server)
15
+
16
+ require 'open_code/rails/const_assets'
17
+ require 'open_code/rails/middleware'
18
+
19
+ css = <<-CSS.strip_heredoc
20
+ .-gem-open-me-link {
21
+ box-sizing: border-box;
22
+ display: inline-block;
23
+ margin-left: 8px;
24
+ padding: 1px 6px;
25
+ vertical-align: middle;
26
+ border: 1px solid #FFCCCB;
27
+ color: #C52E23;
28
+ border-radius: 4px;
29
+ text-decoration: none;
30
+ }
31
+ .-gem-open-me-link:hover {
32
+ border-color: #C52E23;
33
+ }
34
+ CSS
35
+
36
+ cfg = config.open_code
37
+ if cfg.place_holder.blank?
38
+ b64 = Base64.strict_encode64(ConstAssets::ICONS[:vscode])
39
+ css << <<-CSS.strip_heredoc
40
+ .-gem-open-me-link {
41
+ padding: 3px;
42
+ }
43
+ .-gem-open-me-link::after {
44
+ display: block;
45
+ content: '';
46
+ width: 12px;
47
+ height: 12px;
48
+ background-image: url('data:image/svg+xml;base64,#{b64}');
49
+ }
50
+ CSS
51
+ end
52
+
53
+ Middleware.css = css.freeze
54
+ Middleware.place_holder = cfg.place_holder
55
+ Middleware.root_dir = (cfg.root_dir.presence || ::Rails.root).to_s.tr('\\', '/').chomp('/')
56
+ Middleware.scheme = cfg.editor.presence || 'vscode'
57
+ app.middleware.insert_before(ActionDispatch::DebugExceptions, Middleware)
58
+ end
59
+ end
60
+ end
61
+ end
@@ -0,0 +1,5 @@
1
+ module OpenCode
2
+ module Rails
3
+ VERSION = "0.1.0".freeze
4
+ end
5
+ end
@@ -0,0 +1,32 @@
1
+ lib = File.expand_path("../lib", __FILE__)
2
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
3
+ require "open_code/rails/version"
4
+
5
+ Gem::Specification.new do |spec|
6
+ spec.name = "open_code-rails"
7
+ spec.version = OpenCode::Rails::VERSION
8
+ spec.authors = ["James Chen"]
9
+ spec.email = ["egustc@gmail.com"]
10
+
11
+ spec.summary = 'Open file in editor in Rails exception pages'
12
+ spec.description = 'Add an link beside files on exception'
13
+ spec.homepage = "https://github.com/eGust/open_code-rails"
14
+
15
+ # Specify which files should be added to the gem when it is released.
16
+ # The `git ls-files -z` loads the files in the RubyGem that have been added into git.
17
+ spec.files = Dir.chdir(File.expand_path('..', __FILE__)) do
18
+ %x(git ls-files -z).split("\x0").reject { |f| f.match(%r{^(test|spec|features|screenshots)/}) }
19
+ end
20
+ spec.bindir = "exe"
21
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
22
+ spec.require_paths = %w(lib)
23
+
24
+ spec.required_ruby_version = ">= 2.2"
25
+ spec.add_dependency("railties", ">= 4.2")
26
+
27
+ spec.add_development_dependency("bundler", ">= 1.10")
28
+ spec.add_development_dependency("rake", "~> 10.0")
29
+ spec.add_development_dependency("rspec", "~> 3.0")
30
+ spec.add_development_dependency("pry-byebug")
31
+ spec.add_development_dependency("rubocop")
32
+ end
metadata ADDED
@@ -0,0 +1,143 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: open_code-rails
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - James Chen
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2019-03-07 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: railties
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ">="
18
+ - !ruby/object:Gem::Version
19
+ version: '4.2'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ">="
25
+ - !ruby/object:Gem::Version
26
+ version: '4.2'
27
+ - !ruby/object:Gem::Dependency
28
+ name: bundler
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ">="
32
+ - !ruby/object:Gem::Version
33
+ version: '1.10'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ">="
39
+ - !ruby/object:Gem::Version
40
+ version: '1.10'
41
+ - !ruby/object:Gem::Dependency
42
+ name: rake
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '10.0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '10.0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: rspec
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - "~>"
60
+ - !ruby/object:Gem::Version
61
+ version: '3.0'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - "~>"
67
+ - !ruby/object:Gem::Version
68
+ version: '3.0'
69
+ - !ruby/object:Gem::Dependency
70
+ name: pry-byebug
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - ">="
74
+ - !ruby/object:Gem::Version
75
+ version: '0'
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - ">="
81
+ - !ruby/object:Gem::Version
82
+ version: '0'
83
+ - !ruby/object:Gem::Dependency
84
+ name: rubocop
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - ">="
88
+ - !ruby/object:Gem::Version
89
+ version: '0'
90
+ type: :development
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - ">="
95
+ - !ruby/object:Gem::Version
96
+ version: '0'
97
+ description: Add an link beside files on exception
98
+ email:
99
+ - egustc@gmail.com
100
+ executables: []
101
+ extensions: []
102
+ extra_rdoc_files: []
103
+ files:
104
+ - ".gitignore"
105
+ - ".rspec"
106
+ - ".rubocop.yml"
107
+ - ".shopify-rubocop.yml"
108
+ - ".travis.yml"
109
+ - Gemfile
110
+ - Gemfile.lock
111
+ - LICENSE
112
+ - README.md
113
+ - Rakefile
114
+ - lib/open_code/rails.rb
115
+ - lib/open_code/rails/const_assets.rb
116
+ - lib/open_code/rails/middleware.rb
117
+ - lib/open_code/rails/railtie.rb
118
+ - lib/open_code/rails/version.rb
119
+ - open_code-rails.gemspec
120
+ homepage: https://github.com/eGust/open_code-rails
121
+ licenses: []
122
+ metadata: {}
123
+ post_install_message:
124
+ rdoc_options: []
125
+ require_paths:
126
+ - lib
127
+ required_ruby_version: !ruby/object:Gem::Requirement
128
+ requirements:
129
+ - - ">="
130
+ - !ruby/object:Gem::Version
131
+ version: '2.2'
132
+ required_rubygems_version: !ruby/object:Gem::Requirement
133
+ requirements:
134
+ - - ">="
135
+ - !ruby/object:Gem::Version
136
+ version: '0'
137
+ requirements: []
138
+ rubyforge_project:
139
+ rubygems_version: 2.7.6
140
+ signing_key:
141
+ specification_version: 4
142
+ summary: Open file in editor in Rails exception pages
143
+ test_files: []