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.



4
5
6
# File 'lib/flammarion/writeable.rb', line 4

def engraving
  @engraving
end

Instance Method Details

#break(options = {}) ⇒ Object

Adds a horizontal rule



278
279
280
# File 'lib/flammarion/writeable.rb', line 278

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 or emojione icon. (E.g. :thumbs-up:)



141
142
143
144
145
146
# File 'lib/flammarion/writeable.rb', line 141

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:



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

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.



164
165
166
167
168
# File 'lib/flammarion/writeable.rb', line 164

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 or emojione icon. (E.g. :thumbs-up:)



264
265
266
267
268
269
270
271
272
273
274
275
# File 'lib/flammarion/writeable.rb', line 264

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



96
97
98
99
# File 'lib/flammarion/writeable.rb', line 96

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

#closeObject

Closes the pane or window



102
103
104
105
# File 'lib/flammarion/writeable.rb', line 102

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



240
241
242
243
244
245
246
247
248
249
250
251
252
# File 'lib/flammarion/writeable.rb', line 240

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.



153
154
155
156
157
# File 'lib/flammarion/writeable.rb', line 153

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



526
527
528
529
# File 'lib/flammarion/writeable.rb', line 526

def emoji
  @@emoji ||= JSON.parse(File.read(File.join(File.dirname(__FILE__), "../html/build/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:



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

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:



377
378
379
# File 'lib/flammarion/writeable.rb', line 377

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 or emojione icon. (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 or emojione icon. (E.g. :thumbs-up:)



128
129
130
131
132
133
# File 'lib/flammarion/writeable.rb', line 128

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



283
284
285
# File 'lib/flammarion/writeable.rb', line 283

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 Emojione 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:



175
176
177
178
179
180
181
182
# File 'lib/flammarion/writeable.rb', line 175

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="emojione" alt="#{name}" src="images/emoji/#{e['unicode'].last.downcase}.png">|
  end
end

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



184
185
186
# File 'lib/flammarion/writeable.rb', line 184

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.

  • :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.



219
220
221
222
223
224
225
226
227
228
229
# File 'lib/flammarion/writeable.rb', line 219

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
    @engraving.callbacks[id] = Proc.new {|v| d.__setobj__ v["text"] }
    return d
  end
end

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



307
308
309
# File 'lib/flammarion/writeable.rb', line 307

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

#live_reload_template(file) ⇒ Object

Reloads a template every time the file changes. This is mostly just useful when developing a template file.

See Also:



354
355
356
# File 'lib/flammarion/writeable.rb', line 354

def live_reload_template(file)
  FileWatcher.new(file).watch {|file| template(file) }
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



498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
# File 'lib/flammarion/writeable.rb', line 498

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.



363
364
365
366
367
368
369
370
371
372
# File 'lib/flammarion/writeable.rb', line 363

def markdown(text, options = {})
  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)
  send_json({action:'markdown', text: markdown_html}.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:



433
434
435
436
# File 'lib/flammarion/writeable.rb', line 433

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:



418
419
420
421
# File 'lib/flammarion/writeable.rb', line 418

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


112
113
114
115
116
117
# File 'lib/flammarion/writeable.rb', line 112

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 or emojione icon. (E.g. :thumbs-up:)



81
82
83
84
85
# File 'lib/flammarion/writeable.rb', line 81

def puts(str = "", options = {})
  send str, options
  send "\n"
  return nil
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 or emojione icon. (E.g. :thumbs-up:)



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

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



292
293
294
295
296
297
298
299
300
301
302
303
304
305
# File 'lib/flammarion/writeable.rb', line 292

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



311
312
313
314
315
316
317
# File 'lib/flammarion/writeable.rb', line 311

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

#search(string) ⇒ Object

Searches for and highlights the string in the engraving.



521
522
523
# File 'lib/flammarion/writeable.rb', line 521

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 or emojione icon. (E.g. :thumbs-up:)



73
74
75
# File 'lib/flammarion/writeable.rb', line 73

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.



66
67
68
# File 'lib/flammarion/writeable.rb', line 66

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

#showObject

Shows a hidden pane.

See Also:



383
384
385
# File 'lib/flammarion/writeable.rb', line 383

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



455
456
457
458
# File 'lib/flammarion/writeable.rb', line 455

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.



327
328
329
330
331
332
333
334
335
336
337
# File 'lib/flammarion/writeable.rb', line 327

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:



405
406
407
408
# File 'lib/flammarion/writeable.rb', line 405

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 or emojione icon. (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.



470
471
472
# File 'lib/flammarion/writeable.rb', line 470

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:



346
347
348
349
# File 'lib/flammarion/writeable.rb', line 346

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