Class: Ruber::RI::Plugin

Inherits:
Plugin show all
Defined in:
plugins/ruberri/ruberri.rb

Constant Summary

Constants inherited from Plugin

LICENSES

Instance Attribute Summary

Attributes included from PluginLike

plugin_description

Instance Method Summary (collapse)

Methods inherited from Plugin

#about_data, #initialize

Methods included from PluginLike

#add_extensions_to_project, #add_options_to_project, #add_widgets_to_project, #create_tool_widget, #delayed_initialize, #initialize_plugin, #load_settings, #plugin_name, #query_close, #register_options, #register_with_project, #remove_extensions_from_project, #remove_from_project, #remove_options_from_project, #remove_widgets_from_project, #restore_session, #save_settings, #session_data, #setup_action, #setup_actions, #shutdown, #unload, #update_project

Constructor Details

This class inherits a constructor from Ruber::Plugin

Instance Method Details

- (Object) display(type, store, store_type, name) (private)



85
86
87
88
89
90
91
# File 'plugins/ruberri/ruberri.rb', line 85

def display type, store, store_type, name
  if type == :method
    @tool_widget.content = format_method name, store, store_type
  else 
    @tool_widget.content = format_class name, store, store_type
  end
end

- (Object) display_search_result(found) (private)



65
66
67
68
69
70
71
72
73
74
75
76
# File 'plugins/ruberri/ruberri.rb', line 65

def display_search_result found
  if found[:list] and found[:list].count > 1
    if found[:type] == :class then content = format_class_list found[:list]
    else content = format_method_list found[:list]
    end
    @tool_widget.content = content
  elsif found[:list] and found[:list].count == 1
    obj = found[:list][0]
    display found[:type], obj[:store], obj[:store_type], obj[:name]
  else @tool_widget.content = '<h1>Nothing found</h1>'
  end
end

- (Object) display_url(url) (private)



78
79
80
81
82
# File 'plugins/ruberri/ruberri.rb', line 78

def display_url url
  scheme = url.scheme
  store, type, name = url.path.split('$', 3)
  display scheme.to_sym, store, type.to_sym, name
end

Slot Signature:

display_url(QUrl)

- (Object) find_classes(drv, name) (private)



160
161
162
163
164
165
166
167
168
169
170
171
172
# File 'plugins/ruberri/ruberri.rb', line 160

def find_classes drv, name
  begin cls = drv.expand_class(Regexp.quote(name))
  rescue RDoc::RI::Driver::NotFoundError
    return 
  end
  stores = drv.classes[cls]
  return unless stores
  classes = []
  stores.each do |s|
    classes << [s.load_class(cls), s]
  end
  classes
end

- (Object) find_methods(drv, name) (private)



174
175
176
177
178
179
180
181
182
183
# File 'plugins/ruberri/ruberri.rb', line 174

def find_methods drv, name
  found = drv.load_methods_matching name
  return nil if found.empty?
  filtered = drv.filter_methods found, name
  methods = []
  filtered.each do |store, mthds|
    mthds.each{|m| methods << [m, store]}
  end
  methods.empty? ? nil : methods
end

- (Object) format_class(cls, store, store_type) (private)



113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
# File 'plugins/ruberri/ruberri.rb', line 113

def format_class cls, store, store_type
  cmd = [ruby, File.join(File.dirname(__FILE__), 'class_formatter.rb'), cls, store, store_type.to_s]
  html = nil
  err = nil
  status = nil
  Open3.popen3(*cmd) do |stdin, stdout, stderr, thr|
    html = stdout.read
    err = stderr.read
    status = thr.value
  end
  if status.success?
    @tool_widget.content = html
  else
    text = <<-EOS
<h1>Error</h1>
<p>It was impossible to loop #{cls} up in the RI database. The reported error was:</p>
<verbatim>
#{err}
</verbatim>
EOS
  end
  
end

- (Object) format_class_list(classes) (private)



93
94
95
96
97
98
99
100
101
# File 'plugins/ruberri/ruberri.rb', line 93

def format_class_list classes
  res = "<h1>Results from RI</h1>"
  classes.each do |data|
    encoded_name = Qt::Url.to_percent_encoding data[:name]
    url = "class://#{data[:store]}$#{data[:store_type]}$#{encoded_name}"
    res << %[<p><a href="#{url}">#{data[:name]} &ndash; from #{data[:friendly_store]}</a></p>]
  end
  res
end

- (Object) format_method(method, store, store_type) (private)



137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
# File 'plugins/ruberri/ruberri.rb', line 137

def format_method method, store, store_type
  cmd = [ruby, File.join(File.dirname(__FILE__), 'method_formatter.rb'), method, store, store_type.to_s]
  html = nil
  err = nil
  status = nil
  Open3.popen3(*cmd) do |stdin, stdout, stderr, thr|
    html = stdout.read
    err = stderr.read
    status = thr.value
  end
  if status.success?
    @tool_widget.content = html
  else
    text = <<-EOS
<h1>Error</h1>
<p>It was impossible to look #{method} up the RI database. The reported error was:</p>
<verbatim>
#{err}
</verbatim>
EOS
  end
end

- (Object) format_method_list(methods) (private)



103
104
105
106
107
108
109
110
111
# File 'plugins/ruberri/ruberri.rb', line 103

def format_method_list methods
  res = "<h1>Results from RI</h1>"
  methods.each do |data|
    encoded_name = Qt::Url.to_percent_encoding(data[:name])
    url = "method://#{data[:store]}$#{data[:store_type]}$#{encoded_name}"
    res << %[<p><a href="#{url}">#{data[:name]} &ndash; from #{data[:friendly_store]}</a></p>]
  end
  res
end

- (Object) ruby (private)



61
62
63
# File 'plugins/ruberri/ruberri.rb', line 61

def ruby
  Ruber[:ruby_development].interpreter_for Ruber[:world].active_document
end

- (Object) search(text)



34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
# File 'plugins/ruberri/ruberri.rb', line 34

def search text
  cmd = [ruby, File.join(File.dirname(__FILE__), 'search.rb'), text]
  list = nil
  err = nil
  status = nil
  Open3.popen3(*cmd) do |stdin, stdout, stderr, thr|
    list = stdout.read
    err = stderr.read
    status = thr.value
  end
  if status.success?
    display_search_result YAML.load(list)
  else
    text = <<-EOS
<h1>Error</h1>
<p>It was impossible to search the RI database. The reported error was:</p>
<verbatim>
#{err}
</verbatim>
EOS
    @tool_widget.content = text
  end
  
end