iruby 0.2.8 → 0.2.9
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGES +17 -0
- data/README.md +29 -9
- data/iruby.gemspec +1 -0
- data/lib/iruby.rb +1 -0
- data/lib/iruby/backend.rb +5 -0
- data/lib/iruby/display.rb +4 -0
- data/lib/iruby/formatter.rb +2 -1
- data/lib/iruby/input.rb +41 -0
- data/lib/iruby/input/README.ipynb +450 -0
- data/lib/iruby/input/autoload.rb +24 -0
- data/lib/iruby/input/builder.rb +67 -0
- data/lib/iruby/input/button.rb +47 -0
- data/lib/iruby/input/cancel.rb +32 -0
- data/lib/iruby/input/checkbox.rb +56 -0
- data/lib/iruby/input/date.rb +26 -0
- data/lib/iruby/input/field.rb +30 -0
- data/lib/iruby/input/file.rb +57 -0
- data/lib/iruby/input/form.rb +77 -0
- data/lib/iruby/input/label.rb +21 -0
- data/lib/iruby/input/popup.rb +38 -0
- data/lib/iruby/input/radio.rb +47 -0
- data/lib/iruby/input/select.rb +45 -0
- data/lib/iruby/input/textarea.rb +22 -0
- data/lib/iruby/input/widget.rb +34 -0
- data/lib/iruby/session/ffi_rzmq.rb +14 -1
- data/lib/iruby/session/rbczmq.rb +11 -1
- data/lib/iruby/version.rb +1 -1
- metadata +35 -3
@@ -0,0 +1,38 @@
|
|
1
|
+
module IRuby
|
2
|
+
module Input
|
3
|
+
class Popup < Widget
|
4
|
+
needs :title, :form, buttons: []
|
5
|
+
|
6
|
+
def widget_css
|
7
|
+
style = '.modal-body { overflow: auto; }'
|
8
|
+
widget_join :widget_css, style, @form, *@buttons
|
9
|
+
end
|
10
|
+
|
11
|
+
def widget_js
|
12
|
+
js = <<-JS
|
13
|
+
require(['base/js/dialog'], function(dialog) {
|
14
|
+
var popup = dialog.modal({
|
15
|
+
title: '#{@title.gsub("'"){"\\'"}}',
|
16
|
+
body: '#{@form.to_html}',
|
17
|
+
destroy: true,
|
18
|
+
sanitize: false,
|
19
|
+
keyboard_manager: Jupyter.notebook.keyboard_manager,
|
20
|
+
open: function() {
|
21
|
+
#{widget_join :widget_js, @form, *@buttons}
|
22
|
+
|
23
|
+
var popup = $(this);
|
24
|
+
$('#iruby-form').submit(function() {
|
25
|
+
popup.modal('hide');
|
26
|
+
})
|
27
|
+
}
|
28
|
+
});
|
29
|
+
|
30
|
+
popup.find('.modal-footer').each(function(e) {
|
31
|
+
$(this).append('#{@buttons.map(&:to_html).join}');
|
32
|
+
});
|
33
|
+
});
|
34
|
+
JS
|
35
|
+
end
|
36
|
+
end
|
37
|
+
end
|
38
|
+
end
|
@@ -0,0 +1,47 @@
|
|
1
|
+
module IRuby
|
2
|
+
module Input
|
3
|
+
class Radio < Label
|
4
|
+
needs :options
|
5
|
+
|
6
|
+
builder :radio do |*args, **params|
|
7
|
+
key = :radio
|
8
|
+
key, *args = args if args.first.is_a? Symbol
|
9
|
+
|
10
|
+
params[:key] = unique_key(key)
|
11
|
+
params[:options] = args
|
12
|
+
add_field Radio.new(**params)
|
13
|
+
end
|
14
|
+
|
15
|
+
def widget_js
|
16
|
+
<<-JS
|
17
|
+
$('.iruby-radio input').change(function(){
|
18
|
+
var parent = $(this).closest('.iruby-radio');
|
19
|
+
$(parent).data('iruby-value',
|
20
|
+
$(parent).find(':checked').val()
|
21
|
+
);
|
22
|
+
});
|
23
|
+
JS
|
24
|
+
end
|
25
|
+
|
26
|
+
def widget_html
|
27
|
+
params = {
|
28
|
+
:'data-iruby-key' => @key,
|
29
|
+
:'data-iruby-value' => @options.first,
|
30
|
+
class: 'iruby-radio form-control'
|
31
|
+
}
|
32
|
+
widget_label do
|
33
|
+
div **params do
|
34
|
+
@options.each do |option|
|
35
|
+
label class: 'radio-inline' do
|
36
|
+
input(
|
37
|
+
name: @key, value: option, type: 'radio'
|
38
|
+
)
|
39
|
+
text option
|
40
|
+
end
|
41
|
+
end
|
42
|
+
end
|
43
|
+
end
|
44
|
+
end
|
45
|
+
end
|
46
|
+
end
|
47
|
+
end
|
@@ -0,0 +1,45 @@
|
|
1
|
+
module IRuby
|
2
|
+
module Input
|
3
|
+
class Select < Label
|
4
|
+
needs :options
|
5
|
+
|
6
|
+
builder :select do |*args, **params|
|
7
|
+
key = :select
|
8
|
+
key, *args = args if args.first.is_a? Symbol
|
9
|
+
|
10
|
+
key = unique_key(key)
|
11
|
+
add_field Select.new(key: key, options: args)
|
12
|
+
end
|
13
|
+
|
14
|
+
def widget_css
|
15
|
+
'.iruby-select { margin-left: 0 !important }'
|
16
|
+
end
|
17
|
+
|
18
|
+
def widget_js
|
19
|
+
<<-JS
|
20
|
+
$('.iruby-select').change(function(){
|
21
|
+
$(this).data('iruby-value',
|
22
|
+
$(this).find('option:selected').text()
|
23
|
+
);
|
24
|
+
});
|
25
|
+
JS
|
26
|
+
end
|
27
|
+
|
28
|
+
def widget_html
|
29
|
+
widget_label do
|
30
|
+
div class: 'form-control' do
|
31
|
+
params = {
|
32
|
+
class: 'iruby-select',
|
33
|
+
:'data-iruby-key' => @key,
|
34
|
+
:'data-iruby-value' => @options.first
|
35
|
+
}
|
36
|
+
|
37
|
+
select **params do
|
38
|
+
@options.each {|o| option o }
|
39
|
+
end
|
40
|
+
end
|
41
|
+
end
|
42
|
+
end
|
43
|
+
end
|
44
|
+
end
|
45
|
+
end
|
@@ -0,0 +1,22 @@
|
|
1
|
+
module IRuby
|
2
|
+
module Input
|
3
|
+
class Textarea < Field
|
4
|
+
needs rows: 5
|
5
|
+
|
6
|
+
builder :textarea do |key='textarea', **params|
|
7
|
+
params[:key] = unique_key key
|
8
|
+
add_field Textarea.new(**params)
|
9
|
+
end
|
10
|
+
|
11
|
+
def widget_html
|
12
|
+
widget_label do
|
13
|
+
textarea(
|
14
|
+
rows: @rows,
|
15
|
+
:'data-iruby-key' => @key,
|
16
|
+
class: 'form-control iruby-field'
|
17
|
+
)
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
@@ -0,0 +1,34 @@
|
|
1
|
+
module IRuby
|
2
|
+
module Input
|
3
|
+
class Widget < Erector::Widget
|
4
|
+
needs key: nil
|
5
|
+
|
6
|
+
def widget_js; end
|
7
|
+
def widget_css; end
|
8
|
+
def widget_html; end
|
9
|
+
def content; widget_html; end
|
10
|
+
|
11
|
+
def self.builder method, &block
|
12
|
+
Builder.instance_eval do
|
13
|
+
define_method method, &block
|
14
|
+
end
|
15
|
+
end
|
16
|
+
|
17
|
+
def widget_join method, *args
|
18
|
+
strings = args.map do |arg|
|
19
|
+
arg.is_a?(String) ? arg : arg.send(method)
|
20
|
+
end
|
21
|
+
strings.uniq.join("\n")
|
22
|
+
end
|
23
|
+
|
24
|
+
def widget_display
|
25
|
+
IRuby.display(IRuby.html(
|
26
|
+
Erector.inline{ style raw(widget_css) }.to_html
|
27
|
+
))
|
28
|
+
|
29
|
+
IRuby.display(IRuby.html(to_html))
|
30
|
+
IRuby.display(IRuby.javascript(widget_js))
|
31
|
+
end
|
32
|
+
end
|
33
|
+
end
|
34
|
+
end
|
@@ -14,6 +14,9 @@ module IRuby
|
|
14
14
|
pub_socket = c.socket(ZMQ::PUB)
|
15
15
|
pub_socket.bind(connection % config['iopub_port'])
|
16
16
|
|
17
|
+
stdin_socket = c.socket(ZMQ::XREP)
|
18
|
+
stdin_socket.bind(connection % config['stdin_port'])
|
19
|
+
|
17
20
|
Thread.new do
|
18
21
|
begin
|
19
22
|
hb_socket = c.socket(ZMQ::REP)
|
@@ -24,7 +27,10 @@ module IRuby
|
|
24
27
|
end
|
25
28
|
end
|
26
29
|
|
27
|
-
@sockets = {
|
30
|
+
@sockets = {
|
31
|
+
publish: pub_socket, reply: reply_socket, stdin: stdin_socket
|
32
|
+
}
|
33
|
+
|
28
34
|
@session = SecureRandom.uuid
|
29
35
|
unless config['key'].to_s.empty? || config['signature_scheme'].to_s.empty?
|
30
36
|
raise 'Unknown signature scheme' unless config['signature_scheme'] =~ /\Ahmac-(.*)\Z/
|
@@ -70,5 +76,12 @@ module IRuby
|
|
70
76
|
|
71
77
|
@last_recvd_msg = unserialize(msg)
|
72
78
|
end
|
79
|
+
|
80
|
+
def recv_input
|
81
|
+
last_recvd_msg = @last_recvd_msg
|
82
|
+
input = recv(:stdin)[:content]["value"]
|
83
|
+
@last_recvd_msg = last_recvd_msg
|
84
|
+
input
|
85
|
+
end
|
73
86
|
end
|
74
87
|
end
|
data/lib/iruby/session/rbczmq.rb
CHANGED
@@ -14,6 +14,9 @@ module IRuby
|
|
14
14
|
pub_socket = c.socket(:PUB)
|
15
15
|
pub_socket.bind(connection % config['iopub_port'])
|
16
16
|
|
17
|
+
stdin_socket = c.socket(:ROUTER)
|
18
|
+
stdin_socket.bind(connection % config['stdin_port'])
|
19
|
+
|
17
20
|
Thread.new do
|
18
21
|
begin
|
19
22
|
hb_socket = c.socket(:REP)
|
@@ -24,7 +27,10 @@ module IRuby
|
|
24
27
|
end
|
25
28
|
end
|
26
29
|
|
27
|
-
@sockets = {
|
30
|
+
@sockets = {
|
31
|
+
publish: pub_socket, reply: reply_socket, stdin: stdin_socket
|
32
|
+
}
|
33
|
+
|
28
34
|
@session = SecureRandom.uuid
|
29
35
|
unless config['key'].to_s.empty? || config['signature_scheme'].to_s.empty?
|
30
36
|
raise 'Unknown signature scheme' unless config['signature_scheme'] =~ /\Ahmac-(.*)\Z/
|
@@ -54,5 +60,9 @@ module IRuby
|
|
54
60
|
def recv(socket)
|
55
61
|
@last_recvd_msg = unserialize(@sockets[socket].recv_message)
|
56
62
|
end
|
63
|
+
|
64
|
+
def recv_input
|
65
|
+
unserialize(@sockets[:stdin].recv_message)[:content]["value"]
|
66
|
+
end
|
57
67
|
end
|
58
68
|
end
|
data/lib/iruby/version.rb
CHANGED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: iruby
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.2.
|
4
|
+
version: 0.2.9
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Daniel Mendler
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date:
|
12
|
+
date: 2016-05-03 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: rake
|
@@ -81,6 +81,20 @@ dependencies:
|
|
81
81
|
- - "~>"
|
82
82
|
- !ruby/object:Gem::Version
|
83
83
|
version: '0.3'
|
84
|
+
- !ruby/object:Gem::Dependency
|
85
|
+
name: data_uri
|
86
|
+
requirement: !ruby/object:Gem::Requirement
|
87
|
+
requirements:
|
88
|
+
- - "~>"
|
89
|
+
- !ruby/object:Gem::Version
|
90
|
+
version: '0.1'
|
91
|
+
type: :runtime
|
92
|
+
prerelease: false
|
93
|
+
version_requirements: !ruby/object:Gem::Requirement
|
94
|
+
requirements:
|
95
|
+
- - "~>"
|
96
|
+
- !ruby/object:Gem::Version
|
97
|
+
version: '0.1'
|
84
98
|
description: A Ruby kernel for Jupyter/IPython frontends (e.g. notebook). Try it at
|
85
99
|
try.jupyter.org.
|
86
100
|
email:
|
@@ -110,6 +124,23 @@ files:
|
|
110
124
|
- lib/iruby/command.rb
|
111
125
|
- lib/iruby/display.rb
|
112
126
|
- lib/iruby/formatter.rb
|
127
|
+
- lib/iruby/input.rb
|
128
|
+
- lib/iruby/input/README.ipynb
|
129
|
+
- lib/iruby/input/autoload.rb
|
130
|
+
- lib/iruby/input/builder.rb
|
131
|
+
- lib/iruby/input/button.rb
|
132
|
+
- lib/iruby/input/cancel.rb
|
133
|
+
- lib/iruby/input/checkbox.rb
|
134
|
+
- lib/iruby/input/date.rb
|
135
|
+
- lib/iruby/input/field.rb
|
136
|
+
- lib/iruby/input/file.rb
|
137
|
+
- lib/iruby/input/form.rb
|
138
|
+
- lib/iruby/input/label.rb
|
139
|
+
- lib/iruby/input/popup.rb
|
140
|
+
- lib/iruby/input/radio.rb
|
141
|
+
- lib/iruby/input/select.rb
|
142
|
+
- lib/iruby/input/textarea.rb
|
143
|
+
- lib/iruby/input/widget.rb
|
113
144
|
- lib/iruby/kernel.rb
|
114
145
|
- lib/iruby/logger.rb
|
115
146
|
- lib/iruby/ostream.rb
|
@@ -152,7 +183,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
152
183
|
version: '0'
|
153
184
|
requirements: []
|
154
185
|
rubyforge_project:
|
155
|
-
rubygems_version: 2.
|
186
|
+
rubygems_version: 2.4.6
|
156
187
|
signing_key:
|
157
188
|
specification_version: 4
|
158
189
|
summary: Ruby Kernel for Jupyter/IPython
|
@@ -160,3 +191,4 @@ test_files:
|
|
160
191
|
- test/integration_test.rb
|
161
192
|
- test/iruby/multi_logger_test.rb
|
162
193
|
- test/test_helper.rb
|
194
|
+
has_rdoc:
|