class OroGen::HTML::Type
Rendering object that converts a Typelib type, along with the typekit information, into a HTML page.
It needs to be given a page object which has basic services
Attributes
consumed_by[R]
definition_template[R]
displayed_by[R]
intermediate_type[R]
page[R]
produced_by[R]
ruby_type[R]
template[R]
type[R]
Public Class Methods
new(page)
click to toggle source
# File lib/orogen/html/type.rb, line 19 def initialize(page) @page = page template_path = File.join(File.dirname(__FILE__), "type_fragment.page") @template = ERB.new(File.read(template_path)) template.filename = template_path fragment_path = File.join(File.dirname(__FILE__), "type_definition_fragment.page") @definition_template = ERB.new(File.read(fragment_path)) definition_template.filename = fragment_path @produced_by = [] @consumed_by = [] @displayed_by = [] end
Public Instance Methods
has_convertions?(type, recursive = true)
click to toggle source
# File lib/orogen/html/type.rb, line 34 def has_convertions?(type, recursive = true) if type <= Typelib::NumericType return false elsif type.convertion_to_ruby return true end return if !recursive if type < Typelib::CompoundType type.enum_for(:each_field).any? do |field_name, field_type| has_convertions?(field_type, false) end elsif type < Typelib::EnumType false elsif type.respond_to?(:deference) return has_convertions?(type.deference, false) else false end end
render(type, options = Hash.new)
click to toggle source
# File lib/orogen/html/type.rb, line 131 def render(type, options = Hash.new) _, push_options = Kernel.filter_options options, :external_objects => nil @type = type base = self.type typekit = begin Orocos.load_typekit_for(base, false) rescue Orocos::TypekitTypeNotFound end @intermediate_type, @ruby_type = nil if base.contains_opaques? @intermediate_type = typekit.intermediate_type_for(type) if has_convertions?(intermediate_type) @ruby_type = intermediate_type end elsif has_convertions?(base) @ruby_type = base end page.push(nil, template.result(binding), push_options) end
render_convertion_spec(base_type, convertion)
click to toggle source
# File lib/orogen/html/type.rb, line 55 def render_convertion_spec(base_type, convertion) if spec = convertion[0] if spec == Array # The base type is most likely an array or a container. # Display the element type as well ... if base_type.respond_to?(:deference) if subconv = base_type.deference.convertion_to_ruby return "Array(#{render_convertion_spec(base_type.deference, subconv)})" else return "Array(#{page.link_to(base_type.deference)})" end end end convertion[0].name else "converted to an unspecified type" end end
render_type_convertion(type)
click to toggle source
# File lib/orogen/html/type.rb, line 75 def render_type_convertion(type) result = [] if convertion = type.convertion_to_ruby result << render_convertion_spec(type, convertion) elsif type < Typelib::CompoundType result << "<ul class=\"body-header-list\">" type.each_field do |field_name, field_type| if convertion = field_type.convertion_to_ruby result << page.render_item(field_name, render_convertion_spec(field_type, convertion)) else result << page.render_item(field_name, page.link_to(field_type)) end end result << "</ul>" elsif type < Typelib::ArrayType result << "<ul class=\"body-header-list\">" deference = if convertion = type.deference.convertion_to_ruby render_convertion_spec(type.deference, convertion) else render_convertion_spec(type.deference, [Array]) end result << "<li>#{deference}[#{type.length}]</li>" result << "</ul>" elsif type < Typelib::ContainerType result << "<ul class=\"body-header-list\">" deference = if convertion = type.deference.convertion_to_ruby render_convertion_spec(type.deference, convertion) else page.link_to(type.deference) end result << "<li>Array(#{deference})</li>" result << "</ul>" else raise NotImplementedError end result.join("\n") end
render_type_definition_fragment(type)
click to toggle source
# File lib/orogen/html/type.rb, line 115 def render_type_definition_fragment(type) definition_template.result(binding) end
render_type_link(type)
click to toggle source
# File lib/orogen/html/type.rb, line 119 def render_type_link(type) if type < Typelib::ArrayType "#{render_type_link(type.deference)}[#{type.length}]" elsif type < Typelib::ContainerType "#{type.container_kind}<#{render_type_link(type.deference)}>" elsif type < Typelib::NumericType type.name else page.link_to(type) end end