Class: Roby::GUI::ModelViews::ActionInterface

Inherits:
MetaRuby::GUI::HTML::Collection
  • Object
show all
Defined in:
lib/roby/gui/model_views/action_interface.rb

Overview

Handler class to display information about an action interface

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(page) ⇒ ActionInterface

Returns a new instance of ActionInterface.



6
7
8
# File 'lib/roby/gui/model_views/action_interface.rb', line 6

def initialize(page)
    super
end

Class Method Details

.find_definition_place(model) ⇒ Object



25
26
27
28
29
30
31
32
33
# File 'lib/roby/gui/model_views/action_interface.rb', line 25

def self.find_definition_place(model)
    location = model.definition_location.find do |location|
        return if location.label == 'require' || location.label == 'using_task_library'
        Roby.app.app_file?(location.absolute_path)
    end
    if location
        return location.absolute_path, location.lineno
    end
end

.html_defined_in(page, model, with_require: true, definition_location: nil, format: "<b>Defined in</b> %s") ⇒ Object



35
36
37
38
39
40
41
42
43
44
45
46
47
48
# File 'lib/roby/gui/model_views/action_interface.rb', line 35

def self.html_defined_in(page, model, with_require: true, definition_location: nil, format: "<b>Defined in</b> %s")
    path, lineno = *definition_location || find_definition_place(model)
    if path
        path = Pathname.new(path)
        path_link = page.link_to(path, "#{path}:#{lineno}", lineno: lineno)
        page.push(nil, "<p>#{format % [path_link]}</p>")
        if with_require
            if req_base = $LOAD_PATH.find { |p| path.fnmatch?(File.join(p, "*")) }
                req = path.relative_path_from(Pathname.new(req_base))
                page.push(nil, "<code>require '#{req.sub_ext("")}'</code>")
            end
        end
    end
end

Instance Method Details



10
11
12
13
14
15
16
# File 'lib/roby/gui/model_views/action_interface.rb', line 10

def compute_toplevel_links(model, options)
    actions = model.each_action.map do |action|
        arguments = action.arguments.map { |arg| ":#{arg.name}" }.join(", ")
        format = "#{action.name}(#{arguments}) => #{page.link_to(action.returned_type)}: #{action.doc}"
        Element.new(action.name, format, element_link_target(action, options[:interactive]), action.name, Hash.new)
    end
end

#render(model, options = Hash.new) ⇒ Object



18
19
20
21
22
23
# File 'lib/roby/gui/model_views/action_interface.rb', line 18

def render(model, options = Hash.new)
    ActionInterface.html_defined_in(page, model, with_require: true)

    actions = compute_toplevel_links(model, options)
    render_links('Actions', actions)
end