Class: Rock::Doc::HTML::TypeRenderingContext

Inherits:
RenderingContext show all
Defined in:
lib/rock/doc.rb

Instance Attribute Summary collapse

Attributes inherited from RenderingContext

#default_template, #object

Instance Method Summary collapse

Methods inherited from RenderingContext

#help_tip, #link_to, #render_item, #render_object

Constructor Details

#initialize(object) ⇒ TypeRenderingContext

Returns a new instance of TypeRenderingContext



194
195
196
197
198
199
# File 'lib/rock/doc.rb', line 194

def initialize(object)
    super(object, 'orogen_type_fragment.page')
    @produced_by = []
    @consumed_by = []
    @displayed_by = []
end

Instance Attribute Details

#consumed_byObject (readonly)

Returns the value of attribute consumed_by



191
192
193
# File 'lib/rock/doc.rb', line 191

def consumed_by
  @consumed_by
end

#displayed_byObject (readonly)

Returns the value of attribute displayed_by



192
193
194
# File 'lib/rock/doc.rb', line 192

def displayed_by
  @displayed_by
end

#intermediate_typeObject (readonly)

Returns the value of attribute intermediate_type



188
189
190
# File 'lib/rock/doc.rb', line 188

def intermediate_type
  @intermediate_type
end

#produced_byObject (readonly)

Returns the value of attribute produced_by



190
191
192
# File 'lib/rock/doc.rb', line 190

def produced_by
  @produced_by
end

#ruby_typeObject (readonly)

Returns the value of attribute ruby_type



189
190
191
# File 'lib/rock/doc.rb', line 189

def ruby_type
  @ruby_type
end

Instance Method Details

#has_convertions?(type, recursive = true) ⇒ Boolean

Returns:

  • (Boolean)


201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
# File 'lib/rock/doc.rb', line 201

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
        raise NotImplementedError
    end
end

#render(*template_path) ⇒ Object



286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
# File 'lib/rock/doc.rb', line 286

def render(*template_path)
    base = self.type
    typekit = Orocos.load_typekit_for(base, false)

    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

    super
end

#render_convertion_spec(base_type, convertion) ⇒ Object



222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
# File 'lib/rock/doc.rb', line 222

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(#{link_to(base_type.deference)})"
                end
            end
        end
        convertion[0].name

    else
        "converted to an unspecified type"
    end
end

#render_type_convertion(type) ⇒ Object



242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
# File 'lib/rock/doc.rb', line 242

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 << render_item(field_name, render_convertion_spec(field_type, convertion))
            else
                result << render_item(field_name, 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
                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



282
283
284
# File 'lib/rock/doc.rb', line 282

def render_type_definition_fragment(type)
    HTML.render_template("type_definition_fragment.page", binding)
end

#typeObject



186
# File 'lib/rock/doc.rb', line 186

def type; @object end