iruby 0.1.4 → 0.1.5
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 +4 -4
- data/CHANGES +6 -1
- data/Gemfile +4 -2
- data/IRuby-Example.ipynb +309 -13
- data/lib/iruby/display.rb +19 -3
- data/lib/iruby/kernel.rb +9 -11
- data/lib/iruby/static/custom/custom.js +1 -0
- data/lib/iruby/utils.rb +67 -5
- data/lib/iruby/version.rb +1 -1
- metadata +2 -2
data/lib/iruby/kernel.rb
CHANGED
@@ -60,7 +60,7 @@ module IRuby
|
|
60
60
|
end
|
61
61
|
|
62
62
|
def display(obj, options={})
|
63
|
-
|
63
|
+
unless obj.nil?
|
64
64
|
content = { data: Display.new(obj, options).data, metadata: {}, execution_count: @execution_count }
|
65
65
|
@session.send(@pub_socket, 'pyout', content)
|
66
66
|
end
|
@@ -101,6 +101,13 @@ module IRuby
|
|
101
101
|
result = nil
|
102
102
|
begin
|
103
103
|
result = @backend.eval(code)
|
104
|
+
content = {
|
105
|
+
status: 'ok',
|
106
|
+
payload: [],
|
107
|
+
user_variables: {},
|
108
|
+
user_expressions: {},
|
109
|
+
execution_count: @execution_count
|
110
|
+
}
|
104
111
|
rescue Exception => e
|
105
112
|
content = {
|
106
113
|
ename: e.class.to_s,
|
@@ -112,17 +119,8 @@ module IRuby
|
|
112
119
|
}
|
113
120
|
@session.send(@pub_socket, 'pyerr', content)
|
114
121
|
end
|
115
|
-
|
116
|
-
content = {
|
117
|
-
status: 'ok',
|
118
|
-
payload: [],
|
119
|
-
user_variables: {},
|
120
|
-
user_expressions: {},
|
121
|
-
execution_count: @execution_count
|
122
|
-
}
|
123
122
|
@session.send(@reply_socket, 'execute_reply', content, ident)
|
124
|
-
|
125
|
-
display(result) if result && !msg[:content]['silent']
|
123
|
+
display(result) unless msg[:content]['silent']
|
126
124
|
send_status('idle')
|
127
125
|
end
|
128
126
|
|
@@ -7,4 +7,5 @@ $([IPython.events]).on('app_initialized.NotebookApp', function(){
|
|
7
7
|
// add here logic that shoudl be run once per **page load**
|
8
8
|
$.getScript('/static/components/codemirror/mode/ruby/ruby.js');
|
9
9
|
IPython.CodeCell.options_default['cm_config']['mode'] = 'ruby';
|
10
|
+
IPython.CodeCell.options_default['cm_config']['indentUnit'] = 2;
|
10
11
|
});
|
data/lib/iruby/utils.rb
CHANGED
@@ -1,9 +1,71 @@
|
|
1
1
|
module IRuby
|
2
|
-
|
3
|
-
|
4
|
-
|
2
|
+
class MimeString < String
|
3
|
+
attr_reader :mime
|
4
|
+
|
5
|
+
def initialize(mime, data)
|
6
|
+
super(data.to_s)
|
7
|
+
@mime = mime
|
8
|
+
end
|
9
|
+
|
10
|
+
def to_iruby
|
11
|
+
[@mime, self]
|
5
12
|
end
|
6
13
|
end
|
7
|
-
end
|
8
14
|
|
9
|
-
|
15
|
+
def self.display(obj, options={})
|
16
|
+
Kernel.instance.display(obj, options)
|
17
|
+
end
|
18
|
+
|
19
|
+
def self.table(obj)
|
20
|
+
return obj unless Enumerable === obj
|
21
|
+
keys = nil
|
22
|
+
size = 0
|
23
|
+
rows = []
|
24
|
+
obj.each do |row|
|
25
|
+
row = row.flatten(1) if obj.respond_to?(:keys)
|
26
|
+
if row.respond_to?(:keys)
|
27
|
+
# Array of Hashes
|
28
|
+
keys ||= Set.new
|
29
|
+
keys.merge(row.keys)
|
30
|
+
elsif row.respond_to?(:map)
|
31
|
+
# Array of Arrays
|
32
|
+
size = row.size if size < row.size
|
33
|
+
end
|
34
|
+
rows << row
|
35
|
+
end
|
36
|
+
table = '<table>'
|
37
|
+
if keys
|
38
|
+
keys.merge(0...size)
|
39
|
+
table << '<tr>' << keys.map {|k| "<th>#{k}</th>"}.join << '</tr>'
|
40
|
+
else
|
41
|
+
keys = 0...size
|
42
|
+
end
|
43
|
+
rows.each do |row|
|
44
|
+
table << '<tr>'
|
45
|
+
if row.respond_to?(:map)
|
46
|
+
row = keys.map {|k| "<td>#{row[k] rescue nil}</td>" }
|
47
|
+
if row.empty?
|
48
|
+
table << "<td#{keys.size > 1 ? " colspan='#{keys.size}'" : ''}></td>"
|
49
|
+
else
|
50
|
+
table << row.join
|
51
|
+
end
|
52
|
+
else
|
53
|
+
table << "<td#{keys.size > 1 ? " colspan='#{keys.size}'" : ''}>#{row}</td>"
|
54
|
+
end
|
55
|
+
table << '</tr>'
|
56
|
+
end
|
57
|
+
html(table << '</table>')
|
58
|
+
end
|
59
|
+
|
60
|
+
def self.latex(s)
|
61
|
+
MimeString.new('text/latex', s)
|
62
|
+
end
|
63
|
+
|
64
|
+
def self.math(s)
|
65
|
+
MimeString.new('text/latex', "$$#{s}$$")
|
66
|
+
end
|
67
|
+
|
68
|
+
def self.html(s)
|
69
|
+
MimeString.new('text/html', s)
|
70
|
+
end
|
71
|
+
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.1.
|
4
|
+
version: 0.1.5
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Damián Silvani
|
@@ -130,10 +130,10 @@ post_install_message: |+
|
|
130
130
|
* pry-syntax-hacks
|
131
131
|
* pry-git
|
132
132
|
* awesome_print
|
133
|
-
* hirb
|
134
133
|
* gruff
|
135
134
|
* rmagick
|
136
135
|
* gnuplot
|
136
|
+
* rubyvis
|
137
137
|
|
138
138
|
rdoc_options: []
|
139
139
|
require_paths:
|