flammarion 0.0.8 → 0.0.9

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.
@@ -103,6 +103,8 @@ module Flammarion
103
103
  nil
104
104
  end
105
105
 
106
+ # Creates a new pane, and resizes the existing panes to fit it.
107
+ # @param name [String] The name of the pane.
106
108
  def pane(name)
107
109
  return Pane.new(self, name)
108
110
  end
@@ -1,3 +1,3 @@
1
1
  module Flammarion
2
- VERSION = "0.0.8"
2
+ VERSION = "0.0.9"
3
3
  end
@@ -39,41 +39,81 @@ module Flammarion
39
39
  end
40
40
  end
41
41
 
42
+ # @!macro [new] escape_options
43
+ # @option options [Boolean] :raw (false) Perform no escaping at all.
44
+ # @option options [Boolean] :colorize (true) Translate ANSI color escape
45
+ # codes into displayable colors.
46
+ # @option options [Boolean] :escape_html (true) Renders any html tags as
47
+ # plain text. If false, allows any arbitrary html to be rendered in the
48
+ # writeable area.
49
+ # @option options [Boolean] :escape_icons (false) If true, will translate
50
+ # any text between two `:` into a font-awesome icon. (E.g. :thumbs-up:)
51
+
52
+ # @!macro [new] string_representation
53
+ # The string can be included in text for text-accepting methods (such as
54
+ # +#puts+, +#table+, etc).
55
+ # @note Don't forget to set the :escape_html option to false when including
56
+ # this string.
57
+
42
58
  def send_json(hash)
43
59
  @front_end.send_json({target: @pane_name}.merge(hash))
44
60
  end
45
61
 
62
+ # Adds text to the writeable area without appending a newline.
63
+ # @param str [String] The text to append
64
+ # @macro escape_options
46
65
  def send(str, options = {})
47
66
  @front_end.send_json({action:'append', text:str, target:@pane_name}.merge(options))
48
67
  end
49
68
  alias_method :print, :send
50
69
 
70
+ # Adds text to the writeable area and appends a newline.
71
+ # @param str [String] The text to append
72
+ # @macro escape_options
51
73
  def puts(str = "", options = {})
52
74
  send str, options
53
75
  send "\n"
54
76
  return nil
55
77
  end
56
78
 
79
+ # Replaces the contents of the writeable area with text
80
+ # @param str [String] The text to append
81
+ # @macro escape_options
57
82
  def replace(str, options = {})
58
83
  send_json({action:'replace', text:str}.merge(options))
59
84
  return nil
60
85
  end
61
86
 
87
+ # Clears the contents of the writeable area
62
88
  def clear
63
89
  send_json({action:'clear'})
64
90
  return nil
65
91
  end
66
92
 
93
+ # Closes the pane or window
67
94
  def close
68
95
  send_json({action:'closepane'})
96
+ return nil
69
97
  end
70
98
 
99
+ # Creates a new plot to display single axis data
100
+ # @param [Array<Number>] values A list of numbers to plot
101
+ # TODO: @options
102
+ # @return [Spectrum] A Spectrum object for manipulation after creation.
71
103
  def plot(values, options = {})
72
104
  id = @front_end.make_id
73
105
  send_json({action:'plot', data:values, id:id}.merge(options))
74
106
  return Spectrum.new(id, @pane_name, @front_end)
75
107
  end
76
108
 
109
+ # @overload highlight(data, options)
110
+ # Adds a pretty-printed, highlighted display of data
111
+ # @param text [Hash, Array] A dataset to be displayed
112
+ # @macro escape_options
113
+ # @overload highlight(text, options)
114
+ # Adds syntax-highlighted text or code to the writeable area
115
+ # @param text [String] Code to be highlighed
116
+ # @macro escape_options
77
117
  def highlight(text, options = {})
78
118
  output = text
79
119
  output = JSON.pretty_generate(text) if text.is_a? Hash or text.is_a? Array
@@ -81,6 +121,12 @@ module Flammarion
81
121
  nil
82
122
  end
83
123
 
124
+ # Adds a clickable button which will call +block+ when clicked
125
+ # @param label [String] The text of the button
126
+ # @option options [Boolean] :inline (false) If true, creates a small button
127
+ # embedded in the text. If false, creates a button that spans the width
128
+ # of the writeable area.
129
+ # @macro escape_options
84
130
  def button(label, options = {}, &block)
85
131
  id = @front_end.make_id
86
132
  send_json({action:'button', label:label, id:id}.merge(options))
@@ -88,22 +134,63 @@ module Flammarion
88
134
  id
89
135
  end
90
136
 
137
+ # Creates a string representing a button will call the given block when it
138
+ # is clicked.
139
+ # @macro string_representation
140
+ # @param label [String] The label on the button
141
+ # @return A string representing the html for the button.
91
142
  def embedded_button(label, options = {}, &block)
92
143
  id = @front_end.make_id
93
144
  @front_end.callbacks[id] = block
94
145
  %|<a class="floating-button" href="#" onClick="$ws.send({id:'#{id}', action:'callback', source:'embedded_button'})">#{label}</a>|
95
146
  end
96
147
 
148
+ # Creates a string representing a hyperlink that when clicked will call the
149
+ # given block.
150
+ # @macro string_representation
151
+ # @param label [String] The text to become the link
152
+ # @return a string representing the html for the link.
97
153
  def callback_link(label, options = {}, &block)
98
154
  id = @front_end.make_id
99
155
  @front_end.callbacks[id] = block
100
156
  %|<a href="#" onClick="$ws.send({id:'#{id}', action:'callback', source:'link'})">#{label}</a>|
101
157
  end
102
158
 
159
+ # Creates a string representing a Font Awesome icon.
160
+ # @macro string_representation
161
+ # @param name [String] The name of a Font Awesome icon class. See
162
+ # @see https://fortawesome.github.io/Font-Awesome/icons/ for the list.
103
163
  def icon(name, additional_classes = [])
104
164
  %|<i class="fa fa-#{name} #{additional_classes.collect{|c| "fa-#{c}"}.join(" ")}"></i>|
105
165
  end
106
166
 
167
+ # Creates a new text-input field into which the user can enter text.
168
+ # If a block is given, the block will be called when ever the text is
169
+ # changed. If a block is not given, it will return a DeferredValue object
170
+ # which can be used to get the value at any time.
171
+ # @param label [String] The displayed placeholder text for the input. This
172
+ # does not set the actual value of the input field or the returned
173
+ # +DeferredValue+. Use the +:value+ option for that.
174
+ # @option options [Boolean] :multiline (false) Creates a large text box if
175
+ # true; otherwise creates a single line input box.
176
+ # @option options [Boolean] :autoclear (false) Automatically clears the
177
+ # input field every time the user changes the value. The callback will only
178
+ # be called for user initiated changes, not for auto-clear changes.
179
+ # @option options [String] :value Sets the starting value of the field and
180
+ # the returned +DeferredValue+.
181
+ # @option options [Boolean] :once (false) If true, then the input box will
182
+ # be converted into a normal line of text once the user has changed it.
183
+ # The callback will still be called, but the user will no longer be able
184
+ # to change the text.
185
+ # @option options [Boolean] :keep_label (false) If +:once+ is also set, this
186
+ # will prepend +label+ when converting the input to plain text.
187
+ # @overload input(label, options = {})
188
+ # @return [DeferredValue] An object representing the current value of the
189
+ # input, which can be converted to text using +#to_s+.
190
+ # @overload input(label, options = {})
191
+ # @yield [message_hash] Invokes the block every time the text changes. The
192
+ # new text of the input can be obtained from the +"text"+ key of the
193
+ # +message_hash+.
107
194
  def input(label, options = {}, &block)
108
195
  id = @front_end.make_id
109
196
  send_json({action:'input', label:label, id:id}.merge(options))
@@ -116,6 +203,16 @@ module Flammarion
116
203
  end
117
204
  end
118
205
 
206
+ # Creates a new checkbox which the user can click.
207
+ # @param label [String] The placeholder text for the input
208
+ # @macro escape_options
209
+ # @overload checkbox(label, options = {})
210
+ # @return [DeferredValue] An object representing the current value of the
211
+ # checkbox. Use +#checked?+ to get the state of the checkbox.
212
+ # @overload checkbox(label, options = {})
213
+ # @yield [message_hash] Invokes the block every time the checkbox is
214
+ # toggled. Use the "checked" field of +message_hash+ to get the new state
215
+ # of the checkbox.
119
216
  def checkbox(label, options = {}, &block)
120
217
  id = @front_end.make_id
121
218
  send_json({action:'checkbox', label:label, id:id}.merge(options))
@@ -129,10 +226,12 @@ module Flammarion
129
226
  end
130
227
  end
131
228
 
229
+ # Adds a horizontal rule
132
230
  def break(options = {})
133
231
  send_json({action:'break'}.merge(options))
134
232
  end
135
233
 
234
+ # Adds raw html
136
235
  def html(data)
137
236
  send_json({action:'replace', text:data, raw:true})
138
237
  end
@@ -189,7 +288,7 @@ module Flammarion
189
288
  send_json({action:'reorient', orientation:orientation})
190
289
  end
191
290
 
192
- def button_box(name)
291
+ def button_box(name = "buttonbox")
193
292
  send_json({action:'buttonbox', name:name})
194
293
  return Pane.new(@front_end, name)
195
294
  end
@@ -205,7 +205,7 @@ void 0===c?d&&"get"in d&&null!==(e=d.get(a,b))?e:(e=n.find.attr(a,b),null==e?voi
205
205
  element.append(this.__parent.escape(data.text, data));
206
206
  results = [];
207
207
  while (element.hasClass("pane")) {
208
- atBottom = atBottomStack.pop();
208
+ atBottom = atBottomStack.shift();
209
209
  if (atBottom) {
210
210
  element.scrollTop(element[0].scrollHeight - element.height() - marginSize);
211
211
  }
@@ -6826,7 +6826,7 @@ if (typeof module !== 'undefined') {
6826
6826
  element.append(this.__parent.escape(data.text, data));
6827
6827
  results = [];
6828
6828
  while (element.hasClass("pane")) {
6829
- atBottom = atBottomStack.pop();
6829
+ atBottom = atBottomStack.shift();
6830
6830
  if (atBottom) {
6831
6831
  element.scrollTop(element[0].scrollHeight - element.height() - marginSize);
6832
6832
  }
@@ -15,7 +15,7 @@ $.extend WSClient.prototype.actions,
15
15
  element.append(@__parent.escape(data.text, data))
16
16
 
17
17
  while element.hasClass("pane")
18
- atBottom = atBottomStack.pop()
18
+ atBottom = atBottomStack.shift()
19
19
  element.scrollTop(element[0].scrollHeight - element.height() - marginSize) if atBottom
20
20
  element = element.parent()
21
21
 
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: flammarion
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.8
4
+ version: 0.0.9
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors: