Class: Hyperloop::Console::CodeHistoryItem

Inherits:
CodeMirror show all
Defined in:
lib/hyperloop/console/client_components.rb

Constant Summary

Constants inherited from Hyperloop::Component

Hyperloop::Component::VERSION

Instance Attribute Summary

Attributes inherited from CodeMirror

#editor

Instance Method Summary collapse

Instance Method Details

#formatObject



97
98
99
100
101
102
103
104
105
106
107
108
# File 'lib/hyperloop/console/client_components.rb', line 97

def format
  case params.item_type
  when :eval
    params.value
  when :exception
    format_lines("!!", params.value)
  when :result
    format_lines(">>", params.value)
  else
    format_lines("#{params.item_type}:", params.value)
  end
end

#format_lines(prefix, value) ⇒ Object



110
111
112
113
114
115
116
# File 'lib/hyperloop/console/client_components.rb', line 110

def format_lines(prefix, value)
  fill = prefix.gsub(/./, ' ')
  lines = value.split("\n")
  (["#{prefix} #{lines.shift}"]+lines.collect do |line|
    "#{fill} #{line}"
  end).join("\n")
end

#mark_response_linesObject



118
119
120
121
122
123
124
# File 'lib/hyperloop/console/client_components.rb', line 118

def mark_response_lines
  return if params.item_type == :eval
  lines = params.value.split("\n")
  padding = [:exception, :result].include?(params.item_type) ? 3 : 2+params.item_type.to_s.length
  last_line = lines[-1] || ''
  `#{@editor}.markText({line: 0, ch: 0}, {line: #{lines.count-1}, ch: #{last_line.length+padding}}, {className: 'response-line'})`
end