Class: OroGen::HTML::Type
- Inherits:
-
Object
- Object
- OroGen::HTML::Type
- Defined in:
- lib/orogen/html/type.rb
Overview
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
Instance Attribute Summary collapse
-
#consumed_by ⇒ Object
readonly
Returns the value of attribute consumed_by.
-
#definition_template ⇒ Object
readonly
Returns the value of attribute definition_template.
-
#displayed_by ⇒ Object
readonly
Returns the value of attribute displayed_by.
-
#intermediate_type ⇒ Object
readonly
Returns the value of attribute intermediate_type.
-
#page ⇒ Object
readonly
Returns the value of attribute page.
-
#produced_by ⇒ Object
readonly
Returns the value of attribute produced_by.
-
#ruby_type ⇒ Object
readonly
Returns the value of attribute ruby_type.
-
#template ⇒ Object
readonly
Returns the value of attribute template.
-
#type ⇒ Object
readonly
Returns the value of attribute type.
Instance Method Summary collapse
- #has_convertions?(type, recursive = true) ⇒ Boolean
-
#initialize(page) ⇒ Type
constructor
A new instance of Type.
- #render(type, options = Hash.new) ⇒ Object
- #render_convertion_spec(base_type, convertion) ⇒ Object
- #render_type_convertion(type) ⇒ Object
- #render_type_definition_fragment(type) ⇒ Object
- #render_type_link(type) ⇒ Object
Constructor Details
#initialize(page) ⇒ Type
Returns a new instance of Type
19 20 21 22 23 24 25 26 27 28 29 30 31 32 |
# 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 |
Instance Attribute Details
#consumed_by ⇒ Object (readonly)
Returns the value of attribute consumed_by
14 15 16 |
# File 'lib/orogen/html/type.rb', line 14 def consumed_by @consumed_by end |
#definition_template ⇒ Object (readonly)
Returns the value of attribute definition_template
17 18 19 |
# File 'lib/orogen/html/type.rb', line 17 def definition_template @definition_template end |
#displayed_by ⇒ Object (readonly)
Returns the value of attribute displayed_by
15 16 17 |
# File 'lib/orogen/html/type.rb', line 15 def displayed_by @displayed_by end |
#intermediate_type ⇒ Object (readonly)
Returns the value of attribute intermediate_type
11 12 13 |
# File 'lib/orogen/html/type.rb', line 11 def intermediate_type @intermediate_type end |
#page ⇒ Object (readonly)
Returns the value of attribute page
8 9 10 |
# File 'lib/orogen/html/type.rb', line 8 def page @page end |
#produced_by ⇒ Object (readonly)
Returns the value of attribute produced_by
13 14 15 |
# File 'lib/orogen/html/type.rb', line 13 def produced_by @produced_by end |
#ruby_type ⇒ Object (readonly)
Returns the value of attribute ruby_type
12 13 14 |
# File 'lib/orogen/html/type.rb', line 12 def ruby_type @ruby_type end |
#template ⇒ Object (readonly)
Returns the value of attribute template
16 17 18 |
# File 'lib/orogen/html/type.rb', line 16 def template @template end |
#type ⇒ Object (readonly)
Returns the value of attribute type
9 10 11 |
# File 'lib/orogen/html/type.rb', line 9 def type @type end |
Instance Method Details
#has_convertions?(type, recursive = true) ⇒ Boolean
34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 |
# 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) ⇒ Object
[View source]
131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 |
# File 'lib/orogen/html/type.rb', line 131 def render(type, = Hash.new) _, = Kernel. , :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), ) end |
#render_convertion_spec(base_type, convertion) ⇒ Object
[View source]
55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 |
# 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) ⇒ Object
[View source]
75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 |
# 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) ⇒ Object
[View source]
115 116 117 |
# File 'lib/orogen/html/type.rb', line 115 def render_type_definition_fragment(type) definition_template.result(binding) end |
#render_type_link(type) ⇒ Object
[View source]
119 120 121 122 123 124 125 126 127 128 129 |
# 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 |