Versions Compared


  • This line was added.
  • This line was removed.
  • Formatting was changed.

Table of Contents


In this recipe, we show how a Ruble command can output a snippet into the editor for further manipulation. Note that this sample already exists in the HTML bundle--we illustrate it here as it is a useful pattern.


In the snippet below, we manipulate the currently selected text to split it across lines , and then wrap each line in a template using mirrored variables (the $1s in the template).

Code Block
require 'ruble'

command 'Wrap Each Selected Line' do |cmd|
  #cmd.key_binding = 'SHIFT+CTRL+A' # uncomment for a key binding
  #cmd.scope = 'text.html' # uncomment to limit the scope in which this appears
  cmd.output = :insert_as_snippet
  cmd.input = :selection, :line
  cmd.invoke do |context|
    input =
    input.gsub(/[\$`\\]/, '\\1').gsub(/([ \t]*)(.+)/, '\1<${1:li}>\2</${1:li}>')



If you do not choose a key binding, you should place the command in a menu. Otherwise, otherwise it will be difficult or impossible to access.