open_code-rails 0.2.3 → 0.3.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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 0bd0991ca17a9e84ed33cd35e67a1075813a595e1b77a0b0b65a6ee030d76c84
4
- data.tar.gz: 55d65a39e7721d8f1674c6378a004d65e9eb502e51e3298218ba94adf53c09c3
3
+ metadata.gz: ac340cbee917db96ba7cfa83c00849badd21dc922f38a199602a0423de957ac5
4
+ data.tar.gz: b493f03dd96915c4276929d5cc37c96a6e7bef8063e3ac3ead4b9caf35bfe33e
5
5
  SHA512:
6
- metadata.gz: 266ca92d8f61df7b39cc9e9bc0277697b29eb27de4e36c30cfc8f3b67d5bed9453fec23bc89cced346cc4b72ca61ac22be25adb6f332237cffdf0fe79489dd33
7
- data.tar.gz: 628b2b0c8a27d7d577e5ce8ab46c2c4ead4d990e3f1159fee2258be1123569cabb016048010322c4b8ab78499174a0fa80219eb57c6de48cdfdfb0a43c628b65
6
+ metadata.gz: 6487b7e205aa51e52a4336faebeebfe5e8e6516afdcadc9e9800f02337cf10893b88b51adb51e7ce22394b1c5efae40008b9d133d4fdd839cd3884b4af721e88
7
+ data.tar.gz: 75e8833be7373d620486c53c1306a055a174cfffdf072f584b8dfbe86b3f8c291c5740643f722c76d40566eb0fdf5d961ebdcd1f71bddee5fc978a29f31cc6cd
data/.travis.yml CHANGED
@@ -6,7 +6,7 @@ rvm:
6
6
  - 2.3
7
7
  - 2.4
8
8
  - 2.5
9
- before_install: gem install bundler -v '~> 1.17.3'
9
+ before_install: gem update --system
10
10
  jobs:
11
11
  include:
12
12
  - stage: gem release
data/Gemfile.lock CHANGED
@@ -1,26 +1,26 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- open_code-rails (0.2.3)
4
+ open_code-rails (0.3.0)
5
5
  railties (>= 4.2)
6
6
 
7
7
  GEM
8
8
  remote: https://rubygems.org/
9
9
  specs:
10
- actionpack (5.2.2)
11
- actionview (= 5.2.2)
12
- activesupport (= 5.2.2)
10
+ actionpack (5.2.2.1)
11
+ actionview (= 5.2.2.1)
12
+ activesupport (= 5.2.2.1)
13
13
  rack (~> 2.0)
14
14
  rack-test (>= 0.6.3)
15
15
  rails-dom-testing (~> 2.0)
16
16
  rails-html-sanitizer (~> 1.0, >= 1.0.2)
17
- actionview (5.2.2)
18
- activesupport (= 5.2.2)
17
+ actionview (5.2.2.1)
18
+ activesupport (= 5.2.2.1)
19
19
  builder (~> 3.1)
20
20
  erubi (~> 1.4)
21
21
  rails-dom-testing (~> 2.0)
22
22
  rails-html-sanitizer (~> 1.0, >= 1.0.3)
23
- activesupport (5.2.2)
23
+ activesupport (5.2.2.1)
24
24
  concurrent-ruby (~> 1.0, >= 1.0.2)
25
25
  i18n (>= 0.7, < 2)
26
26
  minitest (~> 5.1)
@@ -29,7 +29,7 @@ GEM
29
29
  builder (3.2.3)
30
30
  byebug (11.0.0)
31
31
  coderay (1.1.2)
32
- concurrent-ruby (1.1.4)
32
+ concurrent-ruby (1.1.5)
33
33
  crass (1.0.4)
34
34
  diff-lcs (1.3)
35
35
  erubi (1.8.0)
@@ -63,9 +63,9 @@ GEM
63
63
  nokogiri (>= 1.6)
64
64
  rails-html-sanitizer (1.0.4)
65
65
  loofah (~> 2.2, >= 2.2.2)
66
- railties (5.2.2)
67
- actionpack (= 5.2.2)
68
- activesupport (= 5.2.2)
66
+ railties (5.2.2.1)
67
+ actionpack (= 5.2.2.1)
68
+ activesupport (= 5.2.2.1)
69
69
  method_source
70
70
  rake (>= 0.8.7)
71
71
  thor (>= 0.19.0, < 2.0)
data/README.md CHANGED
@@ -70,7 +70,9 @@ You should put settings in `config/environments/development.rb` because this gem
70
70
  end
71
71
  ```
72
72
 
73
- ### Advanced - via Environment Variables
73
+ ### Advanced
74
+
75
+ #### Environment Variables
74
76
 
75
77
  Some flexibility is probably required for cooperation. Different people may have various preferences of IDE/editors, also the folder could be placed differently. So here you go.
76
78
 
@@ -93,3 +95,35 @@ Some flexibility is probably required for cooperation. Different people may have
93
95
  When is not blank, `config.open_code.root_dir` will be overridden.
94
96
 
95
97
  $ /usr/bin/env FORCE_OPEN_CODE_ROOT_DIR='/my/project/path' rails s
98
+
99
+ #### Browser
100
+
101
+ This functionality requires [localStorage](https://developer.mozilla.org/en-US/docs/Web/API/Window/localStorage).
102
+
103
+ - `_openCode.settings()`
104
+
105
+ Should return keys below
106
+
107
+ - disabled
108
+ - iconUrl or placeHolder - you can only have one at the same time.
109
+ - rootDir
110
+ - scheme - same as `config.open_code.editor`
111
+ - linkBuilder - a function to build `href`. Default builder:
112
+
113
+ ```js
114
+ function (scheme, rootDir, path, line) {
115
+ return scheme + '://file/' + encodeURI(rootDir + '/' + path + ':' + line);
116
+ }
117
+ ```
118
+
119
+ - `_openCode.getValue(key)`
120
+
121
+ Get individual value by given key.
122
+
123
+ - `_openCode.setValue(key, value)`
124
+
125
+ Set individual value by given key.
126
+
127
+ - `_openCode.reset()`
128
+
129
+ Reset all settings - back to default.
@@ -1,4 +1,6 @@
1
1
  require 'active_support/all'
2
+ require 'pathname'
3
+ require 'json'
2
4
 
3
5
  module OpenCode
4
6
  module Rails
@@ -36,76 +38,38 @@ module OpenCode
36
38
  def loadable?(config)
37
39
  return false if %w[false off disabled].include?(config.editor)
38
40
 
39
- css = generate_css(config.place_holder.blank?)
40
- js = generate_js(config.editor, config.place_holder, config.root_dir)
41
- self.html_code = "<style>#{css}</style><script>#{js}</script>"
41
+ dir = Pathname.new(__dir__)
42
+ css = dir.join('vcr.css').read
43
+ defaults = generate_defaults(dir, config.editor, config.place_holder, config.root_dir)
44
+ js = dir.join('vcr.js').read.sub('$$__DEFAULTS__$$', JSON.pretty_generate(defaults))
45
+ self.html_code = <<-HTML.strip_heredoc
46
+ <style id="_open-code-rails_">
47
+ #{css}
48
+ </style>
49
+ <script>
50
+ #{js}
51
+ </script>
52
+ HTML
42
53
  true
43
54
  end
44
55
 
45
56
  private
46
57
 
47
- def generate_js(scheme, place_holder, root_dir)
48
- <<-JS.strip_heredoc
49
- (function () {
50
- setTimeout(function () {
51
- var prefix = '#{scheme}://file/#{root_dir}';
52
- var tmp = document.createElement('div');
53
- var items = document.querySelectorAll('#Application-Trace .trace-frames');
54
- for (var i = 0; i < items.length; i += 1) {
55
- var item = items[i];
56
- var uri = [prefix, item.innerText.split(':in')[0]].join('/');
57
- var h = JSON.stringify(encodeURI(uri));
58
- var html = '<a href=' + h + ' class="open-code-rails-link">#{place_holder}</a>';
59
-
60
- var selFrameId = JSON.stringify(item.dataset.frameId);
61
- var links = document.querySelectorAll('[data-frame-id=' + selFrameId + ']');
62
- for (var j = 0; j < links.length; j += 1) {
63
- var link = links[j];
64
- tmp.innerHTML = html;
65
- link.parentElement.insertBefore(tmp.firstChild, link.nextSibling);
66
- }
67
- }
68
- }, 0);
69
- })();
70
- JS
71
- end
72
-
73
- def generate_css(use_icon)
74
- css = <<-CSS.strip_heredoc
75
- .open-code-rails-link {
76
- box-sizing: border-box;
77
- display: inline-block;
78
- margin-left: 8px;
79
- padding: 1px 6px;
80
- vertical-align: middle;
81
- border: 1px solid #FFCCCB;
82
- color: #C52E23;
83
- border-radius: 4px;
84
- text-decoration: none;
85
- }
86
- .open-code-rails-link:hover {
87
- border-color: #C52E23;
88
- }
89
- CSS
90
- return css unless use_icon
91
-
92
- require 'pathname'
93
- require 'base64'
94
- icon = Base64.strict_encode64(Pathname.new(__dir__).join('vscode.svg').read)
58
+ def generate_defaults(dir, scheme, place_holder, root_dir)
59
+ icon_url = if place_holder.blank?
60
+ require 'base64'
61
+ "data:image/svg+xml;base64,#{Base64.strict_encode64(dir.join('vscode.svg').read)}"
62
+ else
63
+ false
64
+ end
95
65
 
96
- css << <<-CSS.strip_heredoc
97
- .open-code-rails-link {
98
- padding: 3px;
99
- }
100
- .open-code-rails-link::after {
101
- display: block;
102
- content: '';
103
- width: 12px;
104
- height: 12px;
105
- background-image: url('data:image/svg+xml;base64,#{icon}');
106
- }
107
- CSS
108
- css
66
+ {
67
+ scheme: scheme,
68
+ rootDir: root_dir,
69
+ placeHolder: place_holder,
70
+ iconUrl: icon_url,
71
+ disabled: false,
72
+ }
109
73
  end
110
74
  end
111
75
  end
@@ -0,0 +1,15 @@
1
+ .open-code-rails-link {
2
+ box-sizing: border-box;
3
+ display: inline-block;
4
+ margin-left: 8px;
5
+ padding: 1px 6px;
6
+ vertical-align: middle;
7
+ border: 1px solid #FFCCCB;
8
+ color: #C52E23;
9
+ border-radius: 4px;
10
+ text-decoration: none;
11
+ }
12
+
13
+ .open-code-rails-link:hover {
14
+ border-color: #C52E23;
15
+ }
@@ -0,0 +1,162 @@
1
+ (function () {
2
+ var CSS_ICON_POS = '/* _ICON_ */';
3
+ var defaults = $$__DEFAULTS__$$;
4
+
5
+ defaults.linkBuilder = function (scheme, rootDir, path, line) {
6
+ return scheme + '://file/' + encodeURI(rootDir + '/' + path + ':' + line);
7
+ };
8
+
9
+ var current = {
10
+ scheme: defaults.scheme,
11
+ rootDir: defaults.rootDir,
12
+ linkBuilder: defaults.linkBuilder,
13
+ placeHolder: defaults.placeHolder,
14
+ iconUrl: defaults.iconUrl,
15
+ disabled: false
16
+ };
17
+
18
+ function generateIconStyle() {
19
+ return current.placeHolder || !current.iconUrl ? null :
20
+ '.open-code-rails-link {' +
21
+ ' padding: 3px;' +
22
+ '}' +
23
+ '.open-code-rails-link::after {' +
24
+ ' display: block;' +
25
+ ' content: "";' +
26
+ ' width: 12px;' +
27
+ ' height: 12px;' +
28
+ ' background-image: url(' + JSON.stringify(current.iconUrl) + ');' +
29
+ '}';
30
+ }
31
+
32
+ function buildLink(path, line) {
33
+ return current.linkBuilder(current.scheme, current.rootDir, path, line);
34
+ }
35
+
36
+ var cssStyle = null;
37
+
38
+ function generateLinks() {
39
+ if (cssStyle == null) {
40
+ cssStyle = document.querySelector('style#_open-code-rails_') || false;
41
+ if (cssStyle) {
42
+ cssStyle.innerText = cssStyle.innerText + CSS_ICON_POS;
43
+ }
44
+ }
45
+
46
+ if (current.disabled) return;
47
+
48
+ var iconStyle = generateIconStyle();
49
+ if (iconStyle && cssStyle) {
50
+ cssStyle.innerText = cssStyle.innerText + iconStyle;
51
+ }
52
+ var tmp = document.createElement('div');
53
+ var items = document.querySelectorAll('#Application-Trace .trace-frames');
54
+ var ph = current.placeHolder || '';
55
+ for (var i = 0; i < items.length; i += 1) {
56
+ var item = items[i];
57
+ var pathLine = item.innerText.split(':in')[0].split(':');
58
+ var h = JSON.stringify(buildLink(pathLine[0], pathLine[1]));
59
+ var html = '<a href=' + h + ' class="open-code-rails-link">' + ph + '</a>';
60
+
61
+ var selFrameId = JSON.stringify(item.dataset.frameId);
62
+ var links = document.querySelectorAll('[data-frame-id=' + selFrameId + ']');
63
+ for (var j = 0; j < links.length; j += 1) {
64
+ var link = links[j];
65
+ tmp.innerHTML = html;
66
+ link.parentElement.insertBefore(tmp.firstChild, link.nextSibling);
67
+ }
68
+ }
69
+ }
70
+
71
+ setTimeout(generateLinks, 0);
72
+ if (!window.localStorage) return;
73
+
74
+ var ROOT_KEY = '_dbg-open_code_';
75
+ function loadLocalSettings() {
76
+ try {
77
+ var settings = JSON.parse(localStorage.getItem(ROOT_KEY) || '{}') || {};
78
+ var linkBuilder = settings.linkBuilder;
79
+ delete settings.linkBuilder;
80
+ for (var key in defaults) {
81
+ current[key] = settings[key];
82
+ }
83
+ try {
84
+ current.linkBuilder = linkBuilder && eval(linkBuilder);
85
+ } catch (_e) {
86
+ current.linkBuilder = null;
87
+ }
88
+ } catch (_e) {}
89
+
90
+ for (var key in defaults) {
91
+ if (current[key] != null) continue;
92
+ current[key] = defaults[key];
93
+ }
94
+ }
95
+
96
+ loadLocalSettings();
97
+
98
+ function regenerate() {
99
+ var links = document.querySelectorAll('.open-code-rails-link');
100
+ for (var j = 0; j < links.length; j += 1) {
101
+ var link = links[j];
102
+ link.parentElement.removeChild(link);
103
+ }
104
+
105
+ if (cssStyle) {
106
+ var css = cssStyle.innerText;
107
+ var pos = css.indexOf(CSS_ICON_POS);
108
+ cssStyle.innerText = css.slice(0, pos) + CSS_ICON_POS;
109
+ }
110
+
111
+ loadLocalSettings();
112
+ generateLinks();
113
+ }
114
+
115
+ function check(key) {
116
+ if (typeof defaults[key] == 'undefined') throw Error('Unsupported key: ' + key);
117
+ }
118
+
119
+ var ocr = {
120
+ settings: function () {
121
+ var r = {};
122
+ for (var key in defaults) {
123
+ var val = current[key]
124
+ r[key] = val == null ? defaults[key] : val;
125
+ }
126
+ return r;
127
+ },
128
+ getValue: function (key) {
129
+ check(key);
130
+ return (ocr.settings() || {})[key];
131
+ },
132
+ setValue: function(key, value) {
133
+ check(key);
134
+ var settings = ocr.settings();
135
+ var oldVal = key == 'linkBuilder' ? settings[key].toString() : settings[key];
136
+ var val = key == 'linkBuilder' && typeof value == 'function' ? value.toString() : value;
137
+ if (oldVal == val) return;
138
+
139
+ settings[key] = val;
140
+ if (key == 'placeHolder' && value || key == 'iconUrl' && !value) {
141
+ settings.iconUrl = null;
142
+ } else if (key == 'iconUrl' && value || key == 'placeHolder' && !value) {
143
+ settings.placeHolder = null;
144
+ }
145
+
146
+ var json = {};
147
+ for (var k in settings) {
148
+ var v = settings[k];
149
+ if (v == null || '' + v == '' + defaults[k]) continue;
150
+ json[k] = v;
151
+ }
152
+ localStorage.setItem(ROOT_KEY, JSON.stringify(json));
153
+ regenerate();
154
+ return settings[key];
155
+ },
156
+ reset() {
157
+ localStorage.removeItem(ROOT_KEY);
158
+ regenerate();
159
+ }
160
+ };
161
+ window._openCode = ocr;
162
+ })();
@@ -1,5 +1,5 @@
1
1
  module OpenCode
2
2
  module Rails
3
- VERSION = "0.2.3".freeze
3
+ VERSION = "0.3.0".freeze
4
4
  end
5
5
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: open_code-rails
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.3
4
+ version: 0.3.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - James Chen
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2019-03-10 00:00:00.000000000 Z
11
+ date: 2019-03-19 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: railties
@@ -113,6 +113,8 @@ files:
113
113
  - lib/open_code/rails.rb
114
114
  - lib/open_code/rails/middleware.rb
115
115
  - lib/open_code/rails/railtie.rb
116
+ - lib/open_code/rails/vcr.css
117
+ - lib/open_code/rails/vcr.js
116
118
  - lib/open_code/rails/version.rb
117
119
  - lib/open_code/rails/vscode.svg
118
120
  - open_code-rails.gemspec