Class: RDocF95::Generator::Context

Inherits:
Object
  • Object
show all
Includes:
MarkUp
Defined in:
lib/rdoc-f95/generator.rb

Overview

A Context is built by the parser to represent a container: contexts hold classes, modules, methods, require lists and include lists. ClassModule and TopLevel are the context objects we process here

Direct Known Subclasses

Class, File

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Methods included from MarkUp

#cvs_url, #markup, #style_url

Constructor Details

#initialize(context, options) ⇒ Context

Returns a new instance of Context.


192
193
194
195
196
197
198
# File 'lib/rdoc-f95/generator.rb', line 192

def initialize(context, options)
  @context = context
  @options = options

  # HACK ugly
  @template = options.template_class
end

Instance Attribute Details

#contextObject (readonly)

Returns the value of attribute context


156
157
158
# File 'lib/rdoc-f95/generator.rb', line 156

def context
  @context
end

Class Method Details

.build_class_list(classes, options, from, html_file, class_dir) ⇒ Object


184
185
186
187
188
189
190
# File 'lib/rdoc-f95/generator.rb', line 184

def self.build_class_list(classes, options, from, html_file, class_dir)
  classes << RDocF95::Generator::Class.new(from, html_file, class_dir, options)

  from.each_classmodule do |mod|
    build_class_list(classes, options, mod, html_file, class_dir)
  end
end

.build_indicies(toplevels, options) ⇒ Object

Generate:

  • a list of RDocF95::Generator::File objects for each TopLevel object

  • a list of RDocF95::Generator::Class objects for each first level class or module in the TopLevel objects

  • a complete list of all hyperlinkable terms (file, class, module, and method names)


167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
# File 'lib/rdoc-f95/generator.rb', line 167

def self.build_indicies(toplevels, options)
  files = []
  classes = []

  toplevels.each do |toplevel|
    files << RDocF95::Generator::File.new(toplevel, options,
                                       RDocF95::Generator::FILE_DIR)
  end

  RDocF95::TopLevel.all_classes_and_modules.each do |cls|
    build_class_list(classes, options, cls, files[0], 
                     RDocF95::Generator::CLASS_DIR)
  end

  return files, classes
end

Instance Method Details

#add_table_of_sectionsObject

create table of contents if we contain sections


496
497
498
499
500
501
502
503
504
505
506
507
508
# File 'lib/rdoc-f95/generator.rb', line 496

def add_table_of_sections
  toc = []
  @context.sections.each do |section|
    if section.title
      toc << {
        'secname' => section.title,
        'href'    => section.sequence
      }
    end
  end

  @values['toc'] = toc unless toc.empty?
end

#aref_to(target) ⇒ Object


454
455
456
457
458
459
460
# File 'lib/rdoc-f95/generator.rb', line 454

def aref_to(target)
  if @options.all_one_file
    "#" + target
  else
    url(target)
  end
end

#as_href(from_path) ⇒ Object

Returns a reference to outselves to be used as an href= the form depends on whether we're all in one file or in multiple files


211
212
213
214
215
216
217
# File 'lib/rdoc-f95/generator.rb', line 211

def as_href(from_path)
  if @options.all_one_file
    "#" + path
  else
    RDocF95::Generator.gen_url from_path, path
  end
end

#build_alias_summary_list(section) ⇒ Object

Build a list of aliases for which we couldn't find a corresponding method


261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
# File 'lib/rdoc-f95/generator.rb', line 261

def build_alias_summary_list(section)
  values = []
  @context.aliases.each do |al|
    next unless al.section == section
    res = {
      'old_name' => al.old_name,
      'new_name' => al.new_name,
    }
    if al.comment && !al.comment.empty?
      res['desc'] = markup(al.comment, true)
    end
    values << res
  end
  values
end

#build_class_list(level, from, section, infile = nil) ⇒ Object

Build the structured list of classes and modules contained in this context.


417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
# File 'lib/rdoc-f95/generator.rb', line 417

def build_class_list(level, from, section, infile=nil)
  res = ""
  prefix = "&nbsp;&nbsp;::" * level;

  from.modules.sort.each do |mod|
    next unless mod.section == section
    next if infile && !mod.defined_in?(infile)
    if mod.document_self
      res <<
        prefix <<
        "Module " <<
        href(url(mod.viewer.path), "link", mod.full_name) <<
        "<br />\n" <<
        build_class_list(level + 1, mod, section, infile)
    end
  end

  from.classes.sort.each do |cls|
    next unless cls.section == section
    next if infile && !cls.defined_in?(infile)
    if cls.document_self
      res      <<
        prefix <<
        "Class " <<
        href(url(cls.viewer.path), "link", cls.full_name) <<
        "<br />\n" <<
        build_class_list(level + 1, cls, section, infile)
    end
  end

  res
end

#build_constants_summary_list(section) ⇒ Object

Build a list of constants


280
281
282
283
284
285
286
287
288
289
290
291
292
# File 'lib/rdoc-f95/generator.rb', line 280

def build_constants_summary_list(section)
  values = []
  @context.constants.each do |co|
    next unless co.section == section
    res = {
      'name'  => co.name,
      'value' => CGI.escapeHTML(co.value)
    }
    res['desc'] = markup(co.comment, true) if co.comment && !co.comment.empty?
    values << res
  end
  values
end

#build_include_list(context) ⇒ Object


298
299
300
# File 'lib/rdoc-f95/generator.rb', line 298

def build_include_list(context)
  potentially_referenced_list(context.includes)
end

#build_method_detail_list(section) ⇒ Object

Build an array of arrays of method details. The outer array has up to six entries, public, private, and protected for both class methods, the other for instance methods. The inner arrays contain a hash for each method


351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
# File 'lib/rdoc-f95/generator.rb', line 351

def build_method_detail_list(section)
  outer = []

  methods = @methods.sort
  for singleton in [true, false]
    for vis in [ :public, :protected, :private ]
      res = []
      methods.each do |m|
        if m.section == section and
            m.document_self and
            m.visibility == vis and
            m.singleton == singleton
          row = {}
          if m.call_seq
            row["callseq"] = m.call_seq.gsub(/->/, '&rarr;')
          else
            row["name"]        = CGI.escapeHTML(m.name)
            row["params"]      = m.params
          end
          desc = m.description.strip
          row["m_desc"]      = desc unless desc.empty?
          row["aref"]        = m.aref
          row["visibility"]  = m.visibility.to_s

          alias_names = []
          m.aliases.each do |other|
            if other.viewer   # won't be if the alias is private
              alias_names << {
                'name' => other.name,
                'aref'  => other.viewer.as_href(path)
              }
            end
          end
          unless alias_names.empty?
            row["aka"] = alias_names
          end

          if @options.inline_source
            code = m.source_code
            row["sourcecode"] = code if code
          else
            code = m.src_url
            if code
              row["codeurl"] = code
              row["imgurl"]  = m.img_url
            end
          end
          res << row
        end
      end
      if res.size > 0
        outer << {
          "type"     => vis.to_s.capitalize,
          "category" => singleton ? "Class" : "Instance",
          "methods"  => res
        }
      end
    end
  end
  outer
end

#build_method_summary_list(path_prefix = "") ⇒ Object

Build a summary list of all the methods in this context


244
245
246
247
248
249
250
251
252
253
254
255
# File 'lib/rdoc-f95/generator.rb', line 244

def build_method_summary_list(path_prefix="")
  collect_methods unless @methods
  meths = @methods.sort
  res = []
  meths.each do |meth|
    res << {
      "name" => CGI.escapeHTML(meth.name),
      "aref" => "#{path_prefix}\##{meth.aref}"
    }
  end
  res
end

#build_requires_list(context) ⇒ Object


294
295
296
# File 'lib/rdoc-f95/generator.rb', line 294

def build_requires_list(context)
  potentially_referenced_list(context.requires) {|fn| [fn + ".rb"] }
end

#collect_methodsObject

Create a list of Method objects for each method in the corresponding context object. If the @options.show_all variable is set (corresponding to the --all option, we include all methods, otherwise just the public ones.


225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
# File 'lib/rdoc-f95/generator.rb', line 225

def collect_methods
  list = @context.method_list

  unless @options.show_all then
    list = list.find_all do |m|
      m.visibility == :public or
        m.visibility == :protected or
        m.force_documentation
    end
  end

  @methods = list.collect do |m|
    RDocF95::Generator::Method.new m, self, @options
  end
end

#diagram_reference(diagram) ⇒ Object


466
467
468
469
470
471
# File 'lib/rdoc-f95/generator.rb', line 466

def diagram_reference(diagram)
  res = diagram.gsub(/((?:src|href)=")(.*?)"/) {
    $1 + url($2) + '"'
  }
  res
end

#document_selfObject


462
463
464
# File 'lib/rdoc-f95/generator.rb', line 462

def document_self
  @context.document_self
end

#find_file(file, method = nil) ⇒ Object

Find a filenames in ourselves or our parent


485
486
487
488
489
490
491
# File 'lib/rdoc-f95/generator.rb', line 485

def find_file(file, method=nil)
  res = @context.find_file(file, method, @options.ignore_case)
  if res
    res = res.viewer
  end
  res
end

#find_symbol(symbol, method = nil) ⇒ Object

Find a symbol in ourselves or our parent


476
477
478
479
480
481
482
# File 'lib/rdoc-f95/generator.rb', line 476

def find_symbol(symbol, method=nil)
  res = @context.find_symbol(symbol, method, @options.ignore_case)
  if res
    res = res.viewer
  end
  res
end

#href(link, cls, name) ⇒ Object

convenience method to build a hyperlink


203
204
205
# File 'lib/rdoc-f95/generator.rb', line 203

def href(link, cls, name)
  %{<a href="#{link}" class="#{cls}">#{name}</a>} #"
end

#potentially_referenced_list(array) ⇒ Object

Build a list from an array of Context items. Look up each in the AllReferences hash: if we find a corresponding entry, we generate a hyperlink to it, otherwise just output the name. However, some names potentially need massaging. For example, you may require a Ruby file without the .rb extension, but the file names we know about may have it. To deal with this, we pass in a block which performs the massaging, returning an array of alternative names to match


311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
# File 'lib/rdoc-f95/generator.rb', line 311

def potentially_referenced_list(array)
  res = []
  array.each do |i|
    ref = AllReferences[i.name]
#         if !ref
#           container = @context.parent
#           while !ref && container
#             name = container.name + "::" + i.name
#             ref = AllReferences[name]
#             container = container.parent
#           end
#         end

    ref = @context.find_symbol(i.name, nil, @options.ignore_case)  || \
          @context.find_file(i.name)
    ref = ref.viewer if ref

    if !ref && block_given?
      possibles = yield(i.name)
      while !ref and !possibles.empty?
        ref = AllReferences[possibles.shift]
      end
    end
    h_name = CGI.escapeHTML(i.name)
    if ref and ref.document_self
      path = url(ref.path)
      res << { "name" => h_name, "aref" => path }
    else
      res << { "name" => h_name }
    end
  end
  res
end

#url(target) ⇒ Object


450
451
452
# File 'lib/rdoc-f95/generator.rb', line 450

def url(target)
  RDocF95::Generator.gen_url path, target
end