opal-irb 0.7.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (54) hide show
  1. data/.gitignore +3 -0
  2. data/.ruby-gemset +1 -0
  3. data/.ruby-version +1 -0
  4. data/Gemfile +14 -0
  5. data/Gemfile.lock +113 -0
  6. data/Guardfile +5 -0
  7. data/LICENSE +21 -0
  8. data/README.md +175 -0
  9. data/Rakefile +65 -0
  10. data/Roadmap.org +17 -0
  11. data/app/assets/stylesheets/opal-irb/jqconsole.css +263 -0
  12. data/compiled/app-embeddable.js +39765 -0
  13. data/compiled/app-jqconsole.js +39767 -0
  14. data/compiled/application.js +27399 -0
  15. data/css/ansi.css +172 -0
  16. data/css/opal_irb_jqconsole.css +79 -0
  17. data/css/show-hint.css +38 -0
  18. data/doc/presentations/opal_irb_overview.html +678 -0
  19. data/doc/presentations/opal_irb_overview.org +448 -0
  20. data/examples/app-embeddable.rb +8 -0
  21. data/examples/app-jqconsole.rb +10 -0
  22. data/examples/application.rb +8 -0
  23. data/index-embeddable.html +29 -0
  24. data/index-homebrew.html +115 -0
  25. data/index-jq.html +80 -0
  26. data/js/anyword-hint.js +44 -0
  27. data/js/jqconsole.js +1583 -0
  28. data/js/nodeutil.js +546 -0
  29. data/js/ruby.js +285 -0
  30. data/js/show-hint.js +383 -0
  31. data/lib/opal-irb/rails_engine.rb +3 -0
  32. data/lib/opal-irb/version.rb +3 -0
  33. data/lib/opal-irb-rails.rb +2 -0
  34. data/lib/opal-irb.rb +44 -0
  35. data/opal/object_extensions.rb +20 -0
  36. data/opal/opal_irb/completion_engine.rb +202 -0
  37. data/opal/opal_irb/completion_formatter.rb +49 -0
  38. data/opal/opal_irb/completion_results.rb +88 -0
  39. data/opal/opal_irb.rb +88 -0
  40. data/opal/opal_irb_homebrew_console.rb +398 -0
  41. data/opal/opal_irb_jqconsole.rb +517 -0
  42. data/opal/opal_irb_jqconsole_css.rb +259 -0
  43. data/opal/opal_irb_log_redirector.rb +32 -0
  44. data/opal/opal_phantomjs.rb +49 -0
  45. data/opal-irb.gemspec +20 -0
  46. data/spec/code_link_handler_spec.rb +30 -0
  47. data/spec/jquery.js +5 -0
  48. data/spec/object_extensions_spec.rb +32 -0
  49. data/spec/opal_irb/completion_engine_spec.rb +204 -0
  50. data/spec/opal_irb/completion_results_spec.rb +32 -0
  51. data/spec/opal_irb_log_director_spec.rb +19 -0
  52. data/spec/opal_irb_spec.rb +19 -0
  53. data/spec/spec_helper.rb +1 -0
  54. metadata +151 -0
@@ -0,0 +1,32 @@
1
+ require 'spec_helper'
2
+ require 'object_extensions'
3
+
4
+ class TestClass
5
+ def initialize
6
+ @a = "value_for_a"
7
+ @b = "value_for_b"
8
+ end
9
+ end
10
+
11
+ describe Object do
12
+
13
+ describe "#irb_instance_variables" do
14
+
15
+ it "should show vars and not _id, constructor, and toString" do
16
+ f = TestClass.new
17
+ f.irb_instance_variables.should == ["@a", "@b"]
18
+ end
19
+
20
+ end
21
+
22
+ describe "#irb_instance_var_values" do
23
+
24
+ it "should show vars and not _id, constructor, and toString" do
25
+ f = TestClass.new
26
+ f.irb_instance_var_values.should == [["@a", "value_for_a"],
27
+ ["@b", "value_for_b"]]
28
+ end
29
+
30
+ end
31
+
32
+ end
@@ -0,0 +1,204 @@
1
+ describe OpalIrb::CompletionEngine do
2
+ context 'regexps' do
3
+ context 'recognizes VARIABLE_DOT_COMPLETE' do
4
+
5
+ it 'recognizes 1 letter dot' do
6
+ expect('a.' =~ OpalIrb::CompletionEngine::VARIABLE_DOT_COMPLETE).to_not be_falsey
7
+ end
8
+
9
+ it 'recognizes spc 1 letter dot' do
10
+ expect(' a.' =~ OpalIrb::CompletionEngine::VARIABLE_DOT_COMPLETE).to_not be_falsey
11
+ end
12
+
13
+ it 'recognizes 2 letter dot' do
14
+ expect('ab.' =~ OpalIrb::CompletionEngine::VARIABLE_DOT_COMPLETE).to_not be_falsey
15
+ end
16
+
17
+ it 'recognizes spc 2 letter dot' do
18
+ expect(' ab.' =~ OpalIrb::CompletionEngine::VARIABLE_DOT_COMPLETE).to_not be_falsey
19
+ end
20
+
21
+ it 'recognizes a global variable' do
22
+ expect(' $ab.' =~ OpalIrb::CompletionEngine::VARIABLE_DOT_COMPLETE).to_not be_falsey
23
+ end
24
+
25
+ it 'recognizes a class' do
26
+ expect(' Ab.' =~ OpalIrb::CompletionEngine::VARIABLE_DOT_COMPLETE).to_not be_falsey
27
+ end
28
+
29
+ end
30
+
31
+ context 'recognizes METHOD_COMPLETE' do
32
+
33
+ it 'recognizes 1 letter dot 1 letter' do
34
+ expect('a.a' =~ OpalIrb::CompletionEngine::METHOD_COMPLETE).to_not be_falsey
35
+ end
36
+ it 'recognizes 2 letter dot 1 letter' do
37
+ expect('ab.a' =~ OpalIrb::CompletionEngine::METHOD_COMPLETE).to_not be_falsey
38
+ end
39
+
40
+ it 'recognizes spc 1 letter dot 2 letter' do
41
+ expect(' a.ab' =~ OpalIrb::CompletionEngine::METHOD_COMPLETE).to_not be_falsey
42
+ end
43
+ it 'recognizes spc 2 letter dot 2 letter' do
44
+ expect(' ab.ab' =~ OpalIrb::CompletionEngine::METHOD_COMPLETE).to_not be_falsey
45
+ end
46
+ it 'recognizes global' do
47
+ expect('$global.ab' =~ OpalIrb::CompletionEngine::METHOD_COMPLETE).to_not be_falsey
48
+ end
49
+ it 'recognizes class' do
50
+ expect('Klass.ab' =~ OpalIrb::CompletionEngine::METHOD_COMPLETE).to_not be_falsey
51
+ end
52
+ end
53
+
54
+ context 'recognizes CONSTANT' do
55
+ it 'recognizes 1 capital letter' do
56
+ expect('A' =~ OpalIrb::CompletionEngine::CONSTANT).to_not be_falsey
57
+ end
58
+ it 'recognizes 2 capital letters' do
59
+ expect('AB' =~ OpalIrb::CompletionEngine::CONSTANT).to_not be_falsey
60
+ end
61
+
62
+ it 'recognizes spc 1 capital letter' do
63
+ expect(' A' =~ OpalIrb::CompletionEngine::CONSTANT).to_not be_falsey
64
+ end
65
+ it 'recognizes spc 2 capital letter' do
66
+ expect(' AB' =~ OpalIrb::CompletionEngine::CONSTANT).to_not be_falsey
67
+ end
68
+ end
69
+
70
+ context 'recognizes METHOD_OR_VARIABLE' do
71
+ it 'recognizes 1 lowercase letter' do
72
+ expect('a' =~ OpalIrb::CompletionEngine::METHOD_OR_VARIABLE).to_not be_falsey
73
+ end
74
+ it 'recognizes 2 lowercase letters' do
75
+ expect('ab' =~ OpalIrb::CompletionEngine::METHOD_OR_VARIABLE).to_not be_falsey
76
+ end
77
+
78
+ it 'recognizes spc 1 lowercase letter' do
79
+ expect(' a' =~ OpalIrb::CompletionEngine::METHOD_OR_VARIABLE).to_not be_falsey
80
+ end
81
+ it 'recognizes spc 2 lowercase letter' do
82
+ expect(' ab' =~ OpalIrb::CompletionEngine::METHOD_OR_VARIABLE).to_not be_falsey
83
+ end
84
+
85
+
86
+ end
87
+
88
+ end
89
+
90
+ context '#complete' do
91
+ context 'VARIABLE_DOT_COMPLETE' do
92
+ it 'processes global dot' do
93
+ text = '$window.'
94
+ results = OpalIrb::CompletionEngine.complete(text, OpalIrb.new)
95
+ results.old_prompt.should == text
96
+ results.new_prompt_text.should == text
97
+ results.matches.size.should > 5
98
+ end
99
+ it 'processes variable dot' do
100
+ irb = OpalIrb.new
101
+ js = irb.parse('foo_var_bar = "2"')
102
+ `eval(#{js})`
103
+ text = 'foo_var_bar.'
104
+ results = OpalIrb::CompletionEngine.complete(text, irb)
105
+ results.old_prompt.should == text
106
+ results.new_prompt_text.should == text
107
+ results.matches.size.should > 5
108
+ results.matches.include?('reverse').should == true
109
+ end
110
+ it 'processes constant dot' do
111
+ text = 'STDIN.'
112
+ results = OpalIrb::CompletionEngine.complete(text, OpalIrb.new)
113
+ results.old_prompt.should == text
114
+ results.new_prompt_text.should == text
115
+ results.matches.size.should > 5
116
+ results.matches.include?('write').should == true
117
+ end
118
+
119
+ it 'handles non existing global' do
120
+ text = '$no_such_global.'
121
+ results = OpalIrb::CompletionEngine.complete(text, OpalIrb.new)
122
+ results.old_prompt.should == nil
123
+ results.new_prompt_text.should == nil
124
+ results.matches.size.should == 0
125
+
126
+ end
127
+ end
128
+ end
129
+
130
+ context 'METHOD_COMPLETE' do
131
+ it 'processes global dot' do
132
+ text = '$LOADED_FEATURES.'
133
+ results = OpalIrb::CompletionEngine.complete(text, OpalIrb.new)
134
+ results.old_prompt.should == text
135
+ results.new_prompt_text.should == text
136
+ results.matches.size.should > 1
137
+ results.matches.include?(:size).should == true
138
+ end
139
+ it 'processes variable dot' do
140
+ irb = OpalIrb.new
141
+ js = irb.parse('foo_var_bar = "2"')
142
+ `eval(#{js})`
143
+ text = 'foo_var_bar.st'
144
+ results = OpalIrb::CompletionEngine.complete(text, irb)
145
+ results.old_prompt.should == text
146
+ results.new_prompt_text.should == text
147
+ results.matches.size.should > 2
148
+ results.matches.include?('strip!').should == true
149
+ end
150
+ it 'processes constant dot' do
151
+ text = 'STDIN.w'
152
+ results = OpalIrb::CompletionEngine.complete(text, OpalIrb.new)
153
+ results.old_prompt.should == text
154
+ results.new_prompt_text.should == text
155
+ results.matches.size.should > 3
156
+ results.matches.include?('warn').should == true
157
+ end
158
+ end
159
+
160
+ context 'CONSTANT' do
161
+ it 'expands constants, and changes promt to most common prefix' do
162
+ text = 'ST' # STDIN STDOUT STDERR is what's in opal
163
+ results = OpalIrb::CompletionEngine.complete(text, OpalIrb.new)
164
+ results.old_prompt.should == text
165
+ results.new_prompt_text.should == 'STD'
166
+ results.matches.size.should > 2
167
+ results.matches.include?('STDIN').should == true
168
+ end
169
+ end
170
+
171
+ context 'METHOD_OR_VARIABLE' do
172
+ it 'recognizes a method' do
173
+ text = 'ali' # alias_method alias_native
174
+ results = OpalIrb::CompletionEngine.complete(text, OpalIrb.new)
175
+ results.old_prompt.should == text
176
+ results.new_prompt_text.should == 'alias_'
177
+ results.matches.size.should > 1
178
+ results.matches.include?('alias_method').should == true
179
+ end
180
+
181
+ it 'recognizes a variable, and completes the only respons' do
182
+ irb = OpalIrb.new
183
+ js = irb.parse('foo_var_bar = "2"')
184
+ `eval(#{js})`
185
+ text = 'foo_var_b'
186
+ results = OpalIrb::CompletionEngine.complete(text, OpalIrb.new)
187
+ results.old_prompt.should == nil
188
+ results.new_prompt_text.should == 'foo_var_bar'
189
+ results.matches.size.should == 1
190
+ results.matches.include?('foo_var_bar').should == true
191
+ end
192
+
193
+ end
194
+ context 'GLOBAL' do
195
+ it 'recognizes a global, and changes the prompt to most common prefix' do
196
+ text = '$st' # alias_method alias_native
197
+ results = OpalIrb::CompletionEngine.complete(text, OpalIrb.new)
198
+ results.old_prompt.should == text
199
+ results.new_prompt_text.should == '$std'
200
+ results.matches.size.should > 2
201
+ results.matches.include?('$stderr').should == true
202
+ end
203
+ end
204
+ end
@@ -0,0 +1,32 @@
1
+ describe OpalIrb::CompletionEngine::CompletionResults do
2
+ describe 'common_prefix' do
3
+ subject {OpalIrb::CompletionEngine::CompletionResults.new("orig_text", 1, [])}
4
+ it 'finds for 2' do
5
+ expect(subject.common_prefix_if_exists('a.b', 2, ['bellor', 'bella'])).to eq 'a.bell'
6
+ end
7
+ it 'finds for spc 2' do
8
+ expect(subject.common_prefix_if_exists(' a.b', 3, ['bellor', 'bella'])).to eq ' a.bell'
9
+ end
10
+
11
+ it 'finds for 3' do
12
+ expect(subject.common_prefix_if_exists('a.f', 2, ['fellor', 'fella', 'fells_point'])).to eq 'a.fell'
13
+ end
14
+
15
+ it 'finds for 3' do
16
+ expect(subject.common_prefix_if_exists(' a.f', 3, ['fellor', 'fella', 'fells_point'])).to eq ' a.fell'
17
+ end
18
+
19
+ it 'doesn\'t change when no common prefix' do
20
+ expect(subject.common_prefix_if_exists(' a.f', 3, ['fellow', 'freeze'])).to eq ' a.f'
21
+ end
22
+
23
+ it 'match_index == 0, no common matches' do
24
+ expect(subject.common_prefix_if_exists('a', 0, ['alert', 'able'])).to eq 'a'
25
+ end
26
+
27
+ it 'bug' do
28
+ expect(subject.common_prefix_if_exists('OpalIrbJqconsole.ad', 0, ["add_hot_key_panel_behavior", "add_open_panel_behavior"])).to eq 'add_'
29
+ end
30
+
31
+ end
32
+ end
@@ -0,0 +1,19 @@
1
+ require 'spec_helper'
2
+ require 'opal_irb_log_redirector'
3
+ describe OpalIrbLogRedirector do
4
+ it "redirect to added log clients" do
5
+ test_1 = "not changed 1"
6
+ test_2 = "not changed 2"
7
+ test_lambda1 = lambda {|stuff| test_1 = stuff}
8
+ test_lambda2 = lambda {|stuff| test_2 = "#{stuff} 2"}
9
+
10
+ OpalIrbLogRedirector.add_to_redirect(test_lambda1)
11
+ OpalIrbLogRedirector.add_to_redirect(test_lambda2)
12
+
13
+ OpalIrbLogRedirector.puts "changed"
14
+
15
+ test_1.should == "changed"
16
+ test_2.should == "changed 2"
17
+
18
+ end
19
+ end
@@ -0,0 +1,19 @@
1
+ require 'spec_helper'
2
+ require 'opal_irb'
3
+
4
+ describe OpalIrb do
5
+ let(:subject) {OpalIrb.new}
6
+ it "should parse with irb parsing" do
7
+ cmd = "'cmd'";
8
+ # want to do this
9
+ # subject.parser.should_receive(:parse).with(cmd, :irb => true)
10
+ # subject.parse cmd
11
+ subject.parse(cmd).should =~ /irb_vars/
12
+ end
13
+
14
+ it "should return classes" do
15
+ opal_classes = subject.opal_classes
16
+ expect(opal_classes.size).to be > 0
17
+ expect(opal_classes.include?(OpalIrb)).to be true
18
+ end
19
+ end
@@ -0,0 +1 @@
1
+ require 'jquery' # needed for opal-jquery stuff
metadata ADDED
@@ -0,0 +1,151 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: opal-irb
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.7.0
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - Forrest Chang
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2015-09-01 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: opal
16
+ requirement: !ruby/object:Gem::Requirement
17
+ none: false
18
+ requirements:
19
+ - - ~>
20
+ - !ruby/object:Gem::Version
21
+ version: 0.7.0
22
+ type: :runtime
23
+ prerelease: false
24
+ version_requirements: !ruby/object:Gem::Requirement
25
+ none: false
26
+ requirements:
27
+ - - ~>
28
+ - !ruby/object:Gem::Version
29
+ version: 0.7.0
30
+ - !ruby/object:Gem::Dependency
31
+ name: opal-jquery
32
+ requirement: !ruby/object:Gem::Requirement
33
+ none: false
34
+ requirements:
35
+ - - ! '>='
36
+ - !ruby/object:Gem::Version
37
+ version: '0'
38
+ type: :runtime
39
+ prerelease: false
40
+ version_requirements: !ruby/object:Gem::Requirement
41
+ none: false
42
+ requirements:
43
+ - - ! '>='
44
+ - !ruby/object:Gem::Version
45
+ version: '0'
46
+ - !ruby/object:Gem::Dependency
47
+ name: rake
48
+ requirement: !ruby/object:Gem::Requirement
49
+ none: false
50
+ requirements:
51
+ - - ! '>='
52
+ - !ruby/object:Gem::Version
53
+ version: '0'
54
+ type: :development
55
+ prerelease: false
56
+ version_requirements: !ruby/object:Gem::Requirement
57
+ none: false
58
+ requirements:
59
+ - - ! '>='
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ description: Irb and more for Opal
63
+ email: fkc_email-ruby@yahoo.com.com
64
+ executables: []
65
+ extensions: []
66
+ extra_rdoc_files: []
67
+ files:
68
+ - .gitignore
69
+ - .ruby-gemset
70
+ - .ruby-version
71
+ - Gemfile
72
+ - Gemfile.lock
73
+ - Guardfile
74
+ - LICENSE
75
+ - README.md
76
+ - Rakefile
77
+ - Roadmap.org
78
+ - app/assets/stylesheets/opal-irb/jqconsole.css
79
+ - compiled/app-embeddable.js
80
+ - compiled/app-jqconsole.js
81
+ - compiled/application.js
82
+ - css/ansi.css
83
+ - css/opal_irb_jqconsole.css
84
+ - css/show-hint.css
85
+ - doc/presentations/opal_irb_overview.html
86
+ - doc/presentations/opal_irb_overview.org
87
+ - examples/app-embeddable.rb
88
+ - examples/app-jqconsole.rb
89
+ - examples/application.rb
90
+ - index-embeddable.html
91
+ - index-homebrew.html
92
+ - index-jq.html
93
+ - js/anyword-hint.js
94
+ - js/jqconsole.js
95
+ - js/nodeutil.js
96
+ - js/ruby.js
97
+ - js/show-hint.js
98
+ - lib/opal-irb-rails.rb
99
+ - lib/opal-irb.rb
100
+ - lib/opal-irb/rails_engine.rb
101
+ - lib/opal-irb/version.rb
102
+ - opal-irb.gemspec
103
+ - opal/object_extensions.rb
104
+ - opal/opal_irb.rb
105
+ - opal/opal_irb/completion_engine.rb
106
+ - opal/opal_irb/completion_formatter.rb
107
+ - opal/opal_irb/completion_results.rb
108
+ - opal/opal_irb_homebrew_console.rb
109
+ - opal/opal_irb_jqconsole.rb
110
+ - opal/opal_irb_jqconsole_css.rb
111
+ - opal/opal_irb_log_redirector.rb
112
+ - opal/opal_phantomjs.rb
113
+ - spec/code_link_handler_spec.rb
114
+ - spec/jquery.js
115
+ - spec/object_extensions_spec.rb
116
+ - spec/opal_irb/completion_engine_spec.rb
117
+ - spec/opal_irb/completion_results_spec.rb
118
+ - spec/opal_irb_log_director_spec.rb
119
+ - spec/opal_irb_spec.rb
120
+ - spec/spec_helper.rb
121
+ homepage: https://github.com/fkchang/opal-irb
122
+ licenses: []
123
+ post_install_message:
124
+ rdoc_options: []
125
+ require_paths:
126
+ - lib
127
+ required_ruby_version: !ruby/object:Gem::Requirement
128
+ none: false
129
+ requirements:
130
+ - - ! '>='
131
+ - !ruby/object:Gem::Version
132
+ version: '0'
133
+ segments:
134
+ - 0
135
+ hash: -391164403187186275
136
+ required_rubygems_version: !ruby/object:Gem::Requirement
137
+ none: false
138
+ requirements:
139
+ - - ! '>='
140
+ - !ruby/object:Gem::Version
141
+ version: '0'
142
+ segments:
143
+ - 0
144
+ hash: -391164403187186275
145
+ requirements: []
146
+ rubyforge_project:
147
+ rubygems_version: 1.8.23.2
148
+ signing_key:
149
+ specification_version: 3
150
+ summary: Irb and more for Opal
151
+ test_files: []