Module: Flammarion::Writeable

Included in:
Engraving, Pane
Defined in:
lib/flammarion/writeable.rb

Defined Under Namespace

Classes: DeferredValue

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#engravingObject (readonly)

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.



6
7
8
# File 'lib/flammarion/writeable.rb', line 6

def engraving
  @engraving
end

Instance Method Details

#break(options = {}) ⇒ Object

Adds a horizontal rule



290
291
292
# File 'lib/flammarion/writeable.rb', line 290

def break(options = {})
  send_json({action:'break'}.merge(options))
end

#button(label, options = {}, &block) ⇒ Object

Adds a clickable button which will call block when clicked

Parameters:

  • label (String)

    The text of the button

  • options (Hash) (defaults to: {})

    a customizable set of options

Options Hash (options):

  • :inline (Boolean) — default: false

    If true, creates a small button embedded in the text. If false, creates a button that spans the width of the writeable area.

  • :raw (Boolean) — default: false

    Perform no escaping at all.

  • :colorize (Boolean) — default: true

    Translate ANSI color escape codes into displayable colors.

  • :escape_html (Boolean) — default: true

    Renders any html tags as plain text. If false, allows any arbitrary html to be rendered in the writeable area.

  • :escape_icons (Boolean) — default: false

    If true, will translate any text between two ‘:` into a font-awesome icon or emoji (E.g. :thumbs-up:)



150
151
152
153
154
155
# File 'lib/flammarion/writeable.rb', line 150

def button(label, options = {}, &block)
  id = @engraving.make_id
  send_json({action:'button', label:label, id:id}.merge(options))
  @engraving.callbacks[id] = block
  id
end

#button_boxPane #button_box(name) ⇒ Object

Pops up a little floating writeable pane for buttons and stuff.

Overloads:



452
453
454
455
# File 'lib/flammarion/writeable.rb', line 452

def button_box(name = "buttonbox")
  send_json({action:'buttonbox', name:name})
  return Pane.new(@engraving, name)
end
Note:

Don’t forget to set the :escape_html option to false when including this string.

Creates a string representing a hyperlink that when clicked will call the given block. The string can be included in text for text-accepting methods (such as #puts, #table, etc).

Parameters:

  • label (String)

    The text to become the link

Returns:

  • a string representing the html for the link.



173
174
175
176
177
# File 'lib/flammarion/writeable.rb', line 173

def callback_link(label, options = {}, &block)
  id = @engraving.make_id
  @engraving.callbacks[id] = block
  %|<a href="#" onClick="$ws.send({id:'#{id}', action:'callback', source:'link'})">#{label}</a>|
end

#checkbox(label, options = {}) ⇒ DeferredValue #checkbox(label, options = {}) {|message_hash| ... } ⇒ Object

Creates a new checkbox which the user can click.

Overloads:

  • #checkbox(label, options = {}) ⇒ DeferredValue

    Returns An object representing the current value of the checkbox. Use #checked? to get the state of the checkbox.

    Returns:

    • (DeferredValue)

      An object representing the current value of the checkbox. Use #checked? to get the state of the checkbox.

  • #checkbox(label, options = {}) {|message_hash| ... } ⇒ Object

    Yields:

    • (message_hash)

      Invokes the block every time the checkbox is toggled. Use the “checked” field of message_hash to get the new state of the checkbox.

Parameters:

  • label (String)

    The placeholder text for the input

  • options (Hash) (defaults to: {})

    a customizable set of options

Options Hash (options):

  • :raw (Boolean) — default: false

    Perform no escaping at all.

  • :colorize (Boolean) — default: true

    Translate ANSI color escape codes into displayable colors.

  • :escape_html (Boolean) — default: true

    Renders any html tags as plain text. If false, allows any arbitrary html to be rendered in the writeable area.

  • :escape_icons (Boolean) — default: false

    If true, will translate any text between two ‘:` into a font-awesome icon or emoji (E.g. :thumbs-up:)



276
277
278
279
280
281
282
283
284
285
286
287
# File 'lib/flammarion/writeable.rb', line 276

def checkbox(label, options = {}, &block)
  id = @engraving.make_id
  send_json({action:'checkbox', label:label, id:id}.merge(options))
  if block_given?
    @engraving.callbacks[id] = block
  else
    d = DeferredValue.new
    d.__setobj__(options[:value] || options['value'])
    @engraving.callbacks[id] = Proc.new {|v| d.__setobj__(v["checked"])}
    return d
  end
end

#clearObject

Clears the contents of the writeable area



105
106
107
108
# File 'lib/flammarion/writeable.rb', line 105

def clear
  send_json({action:'clear'})
  return nil
end

#closeObject

Closes the pane or window



111
112
113
114
# File 'lib/flammarion/writeable.rb', line 111

def close
  send_json({action:'closepane'})
  return nil
end

Creates a dropdown menu for a user to choose a list of options

Overloads:

  • #dropdown(items, options = {}) ⇒ DeferredValue

    Returns An object representing the currently selected item, which can be retrieved using Flammarion::Writeable::DeferredValue#value.

    Returns:

  • #dropdown(item, options = {}) {|message_hash| ... } ⇒ Object

    Yields:

    • (message_hash)

      Invokes the block every time the user selects a different option. Current item text can be obtained from the “text” key of the message_hash

Parameters:

  • items (Array<#to_s>)

    The possible choices



252
253
254
255
256
257
258
259
260
261
262
263
264
# File 'lib/flammarion/writeable.rb', line 252

def dropdown(items, options = {}, &block)
  id = @engraving.make_id
  send_json({action:'dropdown', id:id, options:items}.merge(options))
  if block_given?
    @engraving.callbacks[id] = block
  else
    d = DeferredValue.new
    d.__setobj__(items[0]) if items.is_a? Array
    d.__setobj__(items[items.keys.first]) if items.is_a? Hash
    @engraving.callbacks[id] = Proc.new {|v| d.__setobj__ v["value"]}
    return d
  end
end

#embedded_button(label, options = {}, &block) ⇒ Object

Note:

Don’t forget to set the :escape_html option to false when including this string.

Creates a string representing a button will call the given block when it is clicked. The string can be included in text for text-accepting methods (such as #puts, #table, etc).

Parameters:

  • label (String)

    The label on the button

Returns:

  • A string representing the html for the button.



162
163
164
165
166
# File 'lib/flammarion/writeable.rb', line 162

def embedded_button(label, options = {}, &block)
  id = @engraving.make_id
  @engraving.callbacks[id] = block
  %|<a class="floating-button" href="#" onClick="$ws.send({id:'#{id}', action:'callback', source:'embedded_button'})">#{label}</a>|
end

#emojiObject

Returns the list of currently installed emoji from Emojione



535
536
537
538
# File 'lib/flammarion/writeable.rb', line 535

def emoji
  @@emoji ||= JSON.parse(File.read(File.join(File.dirname(__FILE__), "../html/source/javascripts/vendor/emojione.js")).each_line.find{|l| l.start_with?("    ns.emojioneList")}.scan(/= (\{[^;]+);/).flatten.first)
  return @@emoji
end

#gets(prompt = "", options = {}) ⇒ String

Prompts the user for a sting. Blocks until a string has been entered.

Parameters:

  • prompt (String) (defaults to: "")

    A prompt to tell the user what to input.

  • options (defaults to: {})

    Same as #input

Returns:

  • (String)

    The text that the user has entered.

See Also:



488
489
490
491
492
493
# File 'lib/flammarion/writeable.rb', line 488

def gets(prompt = "", options = {})
  str = nil
  input(prompt, {once:true, focus:true}.merge(options)) {|msg| str = msg["text"]}
  sleep 0.1 while str.nil?
  return str
end

#hideObject

Hides (but doesn’t close) the pane. This allows the pane to be written to without it opening up again.

See Also:



386
387
388
# File 'lib/flammarion/writeable.rb', line 386

def hide
  send_json({action:'hidepane'})
end

#highlight(data, options) ⇒ Object #highlight(text, options) ⇒ Object

Adds a pretty-printed, colorful display of data or code

Overloads:

  • #highlight(data, options) ⇒ Object

    Adds a pretty-printed, highlighted display of data

    Parameters:

    • text (Hash, Array)

      A dataset to be displayed

    Options Hash (options):

    • :raw (Boolean) — default: false

      Perform no escaping at all.

    • :colorize (Boolean) — default: true

      Translate ANSI color escape codes into displayable colors.

    • :escape_html (Boolean) — default: true

      Renders any html tags as plain text. If false, allows any arbitrary html to be rendered in the writeable area.

    • :escape_icons (Boolean) — default: false

      If true, will translate any text between two ‘:` into a font-awesome icon or emoji (E.g. :thumbs-up:)

  • #highlight(text, options) ⇒ Object

    Adds syntax-highlighted code to the writeable area

    Parameters:

    • text (String)

      Code to be highlighed

    Options Hash (options):

    • :raw (Boolean) — default: false

      Perform no escaping at all.

    • :colorize (Boolean) — default: true

      Translate ANSI color escape codes into displayable colors.

    • :escape_html (Boolean) — default: true

      Renders any html tags as plain text. If false, allows any arbitrary html to be rendered in the writeable area.

    • :escape_icons (Boolean) — default: false

      If true, will translate any text between two ‘:` into a font-awesome icon or emoji (E.g. :thumbs-up:)



137
138
139
140
141
142
# File 'lib/flammarion/writeable.rb', line 137

def highlight(text, options = {})
  output = text
  output = JSON.pretty_generate(text) if text.is_a? Hash or text.is_a? Array
  send_json({action:'highlight', text:output}.merge(options))
  nil
end

#html(data) ⇒ Object

Renders raw html into the writeable area by replacing the previous content



295
296
297
# File 'lib/flammarion/writeable.rb', line 295

def html(data)
  send_json({action:'replace', text:data, raw:true})
end

#icon(name, additional_classes = []) ⇒ Object

Note:

Don’t forget to set the :escape_html option to false when including this string.

Creates a string representing a emoji or Font Awesome icon. The string can be included in text for text-accepting methods (such as #puts, #table, etc).

Parameters:

  • name (String)

    The name of a Font Awesome icon class. See

See Also:



184
185
186
187
188
189
190
191
# File 'lib/flammarion/writeable.rb', line 184

def icon(name, additional_classes = [])
  e = emoji[":#{name}:"]
  if e.nil? then
    return %|<i class="fa fa-#{name} #{additional_classes.collect{|c| "fa-#{c}"}.join(" ")}"></i>|
  else
    return %|<img class="emoji" alt="#{name}" src="images/emoji/#{e['unicode'].last.downcase}.png">|
  end
end

#image(url, options = {}) ⇒ Object



193
194
195
# File 'lib/flammarion/writeable.rb', line 193

def image(url, options = {})
  puts(%|<img src="#{url}">|, {escape_html: false}.merge(options))
end

#input(label, options = {}) ⇒ DeferredValue #input(label, options = {}) {|message_hash| ... } ⇒ Object

Creates a new text-input field into which the user can enter text. If a block is given, the block will be called when ever the text is changed. If a block is not given, it will return a DeferredValue object which can be used to get the value at any time.

Overloads:

  • #input(label, options = {}) ⇒ DeferredValue

    Returns An object representing the current value of the input, which can be converted to text using #to_s.

    Returns:

    • (DeferredValue)

      An object representing the current value of the input, which can be converted to text using #to_s.

  • #input(label, options = {}) {|message_hash| ... } ⇒ Object

    Yields:

    • (message_hash)

      Invokes the block every time the text changes. The new text of the input can be obtained from the “text” key of the message_hash.

Parameters:

  • label (String)

    The displayed placeholder text for the input. This does not set the actual value of the input field or the returned DeferredValue. Use the :value option for that.

  • options (Hash) (defaults to: {})

    a customizable set of options

Options Hash (options):

  • :multiline (Boolean) — default: false

    Creates a large text box if true; otherwise creates a single line input box.

  • :password (Boolean) — default: false

    Creates a password input text box if true; otherwise creates a normal single line input box.

  • :autoclear (Boolean) — default: false

    Automatically clears the input field every time the user changes the value. The callback will only be called for user initiated changes, not for auto-clear changes.

  • :history (Boolean) — default: false

    Keeps track of entered values, letting the user choose betwen them with the up and down keys.

  • :value (String)

    Sets the starting value of the field and the returned DeferredValue.

  • :once (Boolean) — default: false

    If true, then the input box will be converted into a normal line of text once the user has changed it. The callback will still be called, but the user will no longer be able to change the text.

  • :keep_label (Boolean) — default: false

    If :once is also set, this will prepend label when converting the input to plain text.

  • :enter_only (Boolean) — default: false

    Only accept the users input when the enter key is pressed, not merely when it changes.



230
231
232
233
234
235
236
237
238
239
240
241
# File 'lib/flammarion/writeable.rb', line 230

def input(label, options = {}, &block)
  id = @engraving.make_id
  send_json({action:'input', label:label, id:id}.merge(options))
  if block_given?
    @engraving.callbacks[id] = block
  else
    d = DeferredValue.new
    d.__setobj__(options[:value] || options['value'])
    @engraving.callbacks[id] = Proc.new {|v| d.__setobj__ v["text"] }
    return d
  end
end

#js(text, options = {}, &block) ⇒ Object



319
320
321
# File 'lib/flammarion/writeable.rb', line 319

def js(text, options = {}, &block)
  script(text, options.merge(coffee:false), &block)
end

#map(options) ⇒ Object #map(address, options = {}) ⇒ Object #map(latitude, longitude, options = {}) ⇒ Object

Note:

Street map provided by openstreetmap.org

Adds an interactive street map of a specified location.

Overloads:

  • #map(address, options = {}) ⇒ Object

    Parameters:

    • address (String)

      The address or landmark to look up and display.

  • #map(latitude, longitude, options = {}) ⇒ Object

    Parameters:

    • latitude (Float)

      The latitude to display

    • longitude (Float)

      The longitude to display

Parameters:

  • options (Hash)

    a customizable set of options



507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
# File 'lib/flammarion/writeable.rb', line 507

def map(*args)
  case (args.size)
  when 1
    if args[0].respond_to? :keys then
      options = args[0]
    else
      options = {address:args[0].to_s}
    end
  when 2
    if args[1].respond_to? :keys then
      options = {address:args[0]}.merge(args[1])
    else
      options = {latitude:args[0], longitude:args[1]}
    end
  when 3
    options = {latitude:args[0], longitude:args[1]}.merge(args[2])
  else
    raise ArgumentError.new("Expected 1..3 arguments")
  end
  send_json({action:'map'}.merge(options))
end

#markdown(text, options = {}) ⇒ Object

Renders the given markdown text into the pane.

Parameters:

  • text (String)

    The markdown text to render.

  • options (Hash) (defaults to: {})

    a customizable set of options

Options Hash (options):

  • :markdown_extensions (Hash)

    Additional Redcarpet extensions to enable.



368
369
370
371
372
373
374
375
376
377
378
379
380
381
# File 'lib/flammarion/writeable.rb', line 368

def markdown(text, options = {})
  # if defined?(Redcarpet::Markdown) then
  #   markdown_html = Redcarpet::Markdown.new(Redcarpet::Render::HTML, {
  #     tables: true,
  #     fenced_code_blocks: true,
  #     autolink: true,
  #     strikethrough: true,
  #     superscript: true,
  #   }.merge(options[:markdown_extensions] || {})).render(text)
  # else
  #   markdown_html = Kramdown::Document.new(text, {input: 'GFM', hard_wrap: false, syntax_highlighter: nil}.merge(options)).to_html
  # end
  send_json({action:'markdown', text: text, hard_wrap:false}.merge(options))
end

#orientation=(orientation) ⇒ Object

Note:

This applies only to panes, not to subpanes.

Changes the orientation of the panes within this Writeable area. If orientation is :vertical (the default), the panes will be stacked on top of each other, each occupying 1/nth of the height (where n is the number of panes) and 100% of the width. If orientation is :horizontal, the panes will be placed next to each other, with each pane occupying 1/n of the width (where n is the number of panes) and 100% of the heigh.

Parameters:

  • orientation (Symbol)

    can be :horizontal or :vertical

Raises:

  • ArgumentError if the orientation is not one of the allowed values

See Also:



442
443
444
445
# File 'lib/flammarion/writeable.rb', line 442

def orientation=(orientation)
  raise ArgumentError.new("Orientation must be :horizontal or :vertical") unless [:horizontal, :vertical].include?(orientation)
  send_json({action:'reorient', orientation:orientation})
end

#pane(name, options = {}) ⇒ Pane

Note:

The difference between pane and subpane is that a pane is automatically scaled depending on the number of other panes and the current orientation, while subpanes are automatically the size of their contents. Another way to think about it might be that pane creates structural layout elements, while subpane creates embedded sections within other panes.

Creates a scaled pane within the current writeable area. Where it goes depends on the orientation.

Parameters:

  • name (String)

    an identifier for the subpane. All panes and subpanes share the same scope, so you want to be careful with your naming.

Returns:

  • (Pane)

    The newly created or already existing pane.

See Also:



427
428
429
430
# File 'lib/flammarion/writeable.rb', line 427

def pane(name, options = {})
  send_json({action:'addpane', name:name}.merge(options))
  return Pane.new(@engraving, name)
end

#plot(data, options = {}) ⇒ Object

Creates a new plot to display data. Uses Plotly javascript library for plotting, options are passed directly to Plotly, so all types of plots and options are supported.

See Also:

  • Plot.plot


121
122
123
124
125
126
# File 'lib/flammarion/writeable.rb', line 121

def plot(data, options = {})
  id = @engraving.make_id
  p = Plot.new(id, @pane_name, @engraving)
  p.plot(data, options)
  return p
end

#puts(str = "", options = {}) ⇒ Object

Adds text to the writeable area and appends a newline.

Parameters:

  • str (String) (defaults to: "")

    The text to append

  • options (Hash) (defaults to: {})

    a customizable set of options

Options Hash (options):

  • :raw (Boolean) — default: false

    Perform no escaping at all.

  • :colorize (Boolean) — default: true

    Translate ANSI color escape codes into displayable colors.

  • :escape_html (Boolean) — default: true

    Renders any html tags as plain text. If false, allows any arbitrary html to be rendered in the writeable area.

  • :escape_icons (Boolean) — default: false

    If true, will translate any text between two ‘:` into a font-awesome icon or emoji (E.g. :thumbs-up:)



83
84
85
86
87
# File 'lib/flammarion/writeable.rb', line 83

def puts(str = "", options = {})
  send str, options
  send "\n"
  return nil
end

#raw(data) ⇒ Object

Adds raw html to the writeable area without appending a newline.

Parameters:

  • data (String)

    The raw html to append

See Also:



92
93
94
# File 'lib/flammarion/writeable.rb', line 92

def raw(data)
  send data, raw: true
end

#replace(str, options = {}) ⇒ Object

Replaces the contents of the writeable area with text

Parameters:

  • str (String)

    The text to append

  • options (Hash) (defaults to: {})

    a customizable set of options

Options Hash (options):

  • :raw (Boolean) — default: false

    Perform no escaping at all.

  • :colorize (Boolean) — default: true

    Translate ANSI color escape codes into displayable colors.

  • :escape_html (Boolean) — default: true

    Renders any html tags as plain text. If false, allows any arbitrary html to be rendered in the writeable area.

  • :escape_icons (Boolean) — default: false

    If true, will translate any text between two ‘:` into a font-awesome icon or emoji (E.g. :thumbs-up:)



99
100
101
102
# File 'lib/flammarion/writeable.rb', line 99

def replace(str, options = {})
  send_json({action:'replace', text:str}.merge(options))
  return nil
end

#script(text, options = {}, &block) ⇒ Object

Runs a script in the engraving window.

Parameters:

  • text (String)

    The script to run. Lanuage of the script depends on the options given. Defaults to CoffeeScript

  • options (Hash) (defaults to: {})

    a customizable set of options

Options Hash (options):

  • :coffee (Boolean) — default: true

    If true, will compile text from CoffeeScript to JavaScript. If false, will pass text as plain JavaScript



304
305
306
307
308
309
310
311
312
313
314
315
316
317
# File 'lib/flammarion/writeable.rb', line 304

def script(text, options = {}, &block)
  return script_src(text) if !options.fetch(:no_file, false) && File.exist?(text)
  data = options.fetch(:coffee, true) ? CoffeeScript.compile(text) : text
  id = @engraving.make_id
  d = nil
  if block_given?
    @engraving.callbacks[id] = block
  else
    d = DeferredValue.new
    @engraving.callbacks[id] = Proc.new {|v| d.__setobj__(v["result"])}
  end
  send_json({action:'script', data:data, id: id}.merge(options))
  return d
end

#script_src(src) ⇒ Object



323
324
325
326
327
328
329
# File 'lib/flammarion/writeable.rb', line 323

def script_src(src)
  if File.exist?(src) then
    html("<script>#{File.read(src)}</script>")
  else
    html("<script src='#{src}'></script>")
  end
end

#search(string) ⇒ Object

Searches for and highlights the string in the engraving.



530
531
532
# File 'lib/flammarion/writeable.rb', line 530

def search(string)
  send_json({action:'search', text: string})
end

#send(str, options = {}) ⇒ Object Also known as: print

Adds text to the writeable area without appending a newline.

Parameters:

  • str (String)

    The text to append

  • options (Hash) (defaults to: {})

    a customizable set of options

Options Hash (options):

  • :raw (Boolean) — default: false

    Perform no escaping at all.

  • :colorize (Boolean) — default: true

    Translate ANSI color escape codes into displayable colors.

  • :escape_html (Boolean) — default: true

    Renders any html tags as plain text. If false, allows any arbitrary html to be rendered in the writeable area.

  • :escape_icons (Boolean) — default: false

    If true, will translate any text between two ‘:` into a font-awesome icon or emoji (E.g. :thumbs-up:)



75
76
77
# File 'lib/flammarion/writeable.rb', line 75

def send(str, options = {})
  @engraving.send_json({action:'append', text:str, target:@pane_name}.merge(options))
end

#send_json(hash) ⇒ Object

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.



68
69
70
# File 'lib/flammarion/writeable.rb', line 68

def send_json(hash)
  @engraving.send_json({target: @pane_name}.merge(hash))
end

#showObject

Shows a hidden pane.

See Also:



392
393
394
# File 'lib/flammarion/writeable.rb', line 392

def show
  send_json({action:'showpane'})
end

#status(str, position) ⇒ Object #status(str, options = {}) ⇒ Object

Displays a message to the bottom status bar.

Overloads:

  • #status(str, position) ⇒ Object

    Parameters:

    • position (Symbol)

      Where to put it. May be :left or :right

  • #status(str, options = {}) ⇒ Object

    Options Hash (options):

    • :position (Symbol)

      Where to put it. May be :left or :right

Parameters:

  • str (String)

    The message to display



464
465
466
467
# File 'lib/flammarion/writeable.rb', line 464

def status(str, options = {})
  options = {position: options} if options.is_a? Symbol
  @engraving.send_json({action:'status', text: str}.merge(options))
end

#style(attribute, value) ⇒ Object #style(attributes) ⇒ Object

Sets CSS styles attributes on the current pane.

Overloads:

  • #style(attribute, value) ⇒ Object

    Parameters:

    • attribute (String)

      The css attribute to set. Currently does not support selectors or anything.

    • value (#to_s)

      The value to set the attribute to. (Don’t forget units!)

  • #style(attributes) ⇒ Object

    Parameters:

    • attributes (Hash)

      Table of css attribute to value mapping to set.



339
340
341
342
343
344
345
346
347
348
349
# File 'lib/flammarion/writeable.rb', line 339

def style(*args)
  case args.length
  when 1
    # @todo Pass this as a whole hash, rather than individually.
    args[0].each{|a,v| send_json({action: 'style', attribute: a, value: v})}
  when 2
    send_json({action: 'style', attribute: args[0], value: args[1]})
  else
    raise ArgumentError.new("Invalid number of arguments (Expected 1 or 2)")
  end
end

#subpane(name, options = {}) ⇒ Pane

Note:

The difference between pane and subpane is that a pane is automatically scaled depending on the number of other panes and the current orientation, while subpanes are automatically the size of their contents. Another way to think about it might be that pane creates structural layout elements, while subpane creates embedded sections within other panes.

Creates a writeable area within the current writeable area. This lets you update the contents of the writeable later, without disturbing the rest of the curent pane. If a pane or subpane with the given name already exists, it will just use that one instead.

Parameters:

  • name (String)

    an identifier for the subpane. All panes and subpanes share the same scope, so you want to be careful with your naming.

Returns:

  • (Pane)

    The newly created or already existing pane.

See Also:



414
415
416
417
# File 'lib/flammarion/writeable.rb', line 414

def subpane(name, options = {})
  send_json({action:'subpane', name:name}.merge(options))
  return Pane.new(@engraving, name)
end

#table(rows, options = {}) ⇒ Object

Displays a table of data

Parameters:

  • rows (Array<Array<#to_s>>)

    an array of rows, where each row is an array of objects which will be converted to a string and diplayed in the table.

  • options (Hash) (defaults to: {})

    a customizable set of options

Options Hash (options):

  • :raw (Boolean) — default: false

    Perform no escaping at all.

  • :colorize (Boolean) — default: true

    Translate ANSI color escape codes into displayable colors.

  • :escape_html (Boolean) — default: true

    Renders any html tags as plain text. If false, allows any arbitrary html to be rendered in the writeable area.

  • :escape_icons (Boolean) — default: false

    If true, will translate any text between two ‘:` into a font-awesome icon or emoji (E.g. :thumbs-up:)

  • :headers (Array<#to_s>)

    An array of column headers to put at the top of the table.

  • :interactive (Boolean) — default: true

    Allows the user to mouse over the table and have it styled. Set to false if you experience performance issues with large datasets.



479
480
481
# File 'lib/flammarion/writeable.rb', line 479

def table(rows, options = {})
  send_json({action:'table', rows: rows}.merge(options))
end

#template(file) ⇒ Object

Note:

If you just want to include html (or outut from another template engine, you can just use #html)

Will render the given Slim template into the Writeable area. This is useful for creating complex or custom application layouts components beyond what’s built into Flammarion.

Parameters:

  • file (String)

    Path to the Slim file to render

See Also:



358
359
360
361
# File 'lib/flammarion/writeable.rb', line 358

def template(file)
  data = Slim::Template.new(file).render
  send_json({action:'replace', text:data, raw:true})
end