class TkInspect::ClassBrowser::CodeComponent

Attributes

code[RW]
filename[RW]
method_line[RW]
method_name[RW]

Public Instance Methods

component_did_build() click to toggle source
# File lib/tk_inspect/class_browser/code_component.rb, line 43
def component_did_build
  TAG_STYLES.each do |k,v|
    @code_text.native_item.tag_configure(k.to_s, v)
  end
end
highlight_code(native_item, code, filename) click to toggle source
# File lib/tk_inspect/class_browser/code_component.rb, line 63
def highlight_code(native_item, code, filename)
  lexer = (@@lexers[filename] ||= Rouge::Lexers::Ruby.lex(code))
  native_item.replace('1.0', 'end', '')
  lexer.each do |token, chunk|
    tag = TOKEN_TAGS[token.to_s]
    native_item.insert('end', chunk, tag.to_s)
  end
end
render(p, parent_component) click to toggle source
# File lib/tk_inspect/class_browser/code_component.rb, line 36
def render(p, parent_component)
  p.vframe(padding: "0 0 0 0", sticky: 'nsew', x_flex: 1, y_flex: 1) do |vf|
    @filename_label = vf.label(font: 'TkSmallCaptionFont', sticky: 'ewn', x_flex: 1, y_flex: 0)
    @code_text = vf.text(sticky: 'nswe', x_flex: 1, y_flex: 1, wrap: 'none', scrollers: 'xy')
  end
end
update() click to toggle source
# File lib/tk_inspect/class_browser/code_component.rb, line 49
def update
  if @code && @method_line
    highlight_code(@code_text.native_item, @code, @filename)
    @code_text.tk_item.select_range("#{@method_line}.0", "#{@method_line}.end")
    @code_text.native_item.see("#{@method_line}.0")
    @filename_label.native_item.text(@filename)
  else
    @filename_label.native_item.text('')
    @code_text.tk_item.value = "Source code not available for #{@method_name}"
  end
end