Class | Generators::ContextUser |
In: |
generators/html_generator.rb
|
Parent: | Object |
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
context | [R] |
# File generators/html_generator.rb, line 328 328: def initialize(context, options) 329: @context = context 330: @options = options 331: end
create table of contents if we contain sections
# File generators/html_generator.rb, line 610 610: def add_table_of_sections 611: toc = [] 612: @context.sections.each do |section| 613: if section.title 614: toc << { 615: 'secname' => section.title, 616: 'href' => section.sequence 617: } 618: end 619: end 620: 621: @values['toc'] = toc unless toc.empty? 622: end
# File generators/html_generator.rb, line 569 569: def aref_to(target) 570: if @options.all_one_file 571: "#" + target 572: else 573: url(target) 574: end 575: end
return 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
# File generators/html_generator.rb, line 342 342: def as_href(from_path) 343: if @options.all_one_file 344: "#" + path 345: else 346: HTMLGenerator.gen_url(from_path, path) 347: end 348: end
Build a list of aliases for which we couldn‘t find a corresponding method
# File generators/html_generator.rb, line 380 380: def build_alias_summary_list(section) 381: values = [] 382: @context.aliases.each do |al| 383: next unless al.section == section 384: res = { 385: 'old_name' => al.old_name, 386: 'new_name' => al.new_name, 387: } 388: if al.comment && !al.comment.empty? 389: res['desc'] = markup(al.comment, true) 390: end 391: values << res 392: end 393: values 394: end
Build the structured list of classes and modules contained in this context.
# File generators/html_generator.rb, line 532 532: def build_class_list(level, from, section, infile=nil) 533: res = "" 534: prefix = " ::" * level; 535: 536: from.modules.sort.each do |mod| 537: next unless mod.section == section 538: next if infile && !mod.defined_in?(infile) 539: if mod.document_self 540: res << 541: prefix << 542: "Module " << 543: href(url(mod.viewer.path), "link", mod.full_name) << 544: "<br />\n" << 545: build_class_list(level + 1, mod, section, infile) 546: end 547: end 548: 549: from.classes.sort.each do |cls| 550: next unless cls.section == section 551: next if infile && !cls.defined_in?(infile) 552: if cls.document_self 553: res << 554: prefix << 555: "Class " << 556: href(url(cls.viewer.path), "link", cls.full_name) << 557: "<br />\n" << 558: build_class_list(level + 1, cls, section, infile) 559: end 560: end 561: 562: res 563: end
Build a list of constants
# File generators/html_generator.rb, line 397 397: def build_constants_summary_list(section) 398: values = [] 399: @context.constants.each do |co| 400: next unless co.section == section 401: res = { 402: 'name' => co.name, 403: 'value' => CGI.escapeHTML(co.value) 404: } 405: res['desc'] = markup(co.comment, true) if co.comment && !co.comment.empty? 406: values << res 407: end 408: values 409: end
# File generators/html_generator.rb, line 415 415: def build_include_list(context) 416: potentially_referenced_list(context.includes) 417: end
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
# File generators/html_generator.rb, line 467 467: def build_method_detail_list(section) 468: outer = [] 469: 470: methods = @methods.sort 471: for singleton in [true, false] 472: for vis in [ :public, :protected, :private ] 473: res = [] 474: methods.each do |m| 475: if m.section == section and 476: m.document_self and 477: m.visibility == vis and 478: m.singleton == singleton 479: row = {} 480: if m.call_seq 481: row["callseq"] = m.call_seq.gsub(/->/, '→') 482: else 483: row["name"] = CGI.escapeHTML(m.name) 484: row["params"] = m.params 485: end 486: desc = m.description.strip 487: row["m_desc"] = desc unless desc.empty? 488: row["aref"] = m.aref 489: row["visibility"] = m.visibility.to_s 490: 491: alias_names = [] 492: m.aliases.each do |other| 493: if other.viewer # won't be if the alias is private 494: alias_names << { 495: 'name' => other.name, 496: 'aref' => other.viewer.as_href(path) 497: } 498: end 499: end 500: unless alias_names.empty? 501: row["aka"] = alias_names 502: end 503: 504: if @options.inline_source 505: code = m.source_code 506: row["sourcecode"] = code if code 507: else 508: code = m.src_url 509: if code 510: row["codeurl"] = code 511: row["imgurl"] = m.img_url 512: end 513: end 514: res << row 515: end 516: end 517: if res.size > 0 518: outer << { 519: "type" => vis.to_s.capitalize, 520: "category" => singleton ? "Class" : "Instance", 521: "methods" => res 522: } 523: end 524: end 525: end 526: outer 527: end
Build a summary list of all the methods in this context
# File generators/html_generator.rb, line 364 364: def build_method_summary_list(path_prefix="") 365: collect_methods unless @methods 366: meths = @methods.sort 367: res = [] 368: meths.each do |meth| 369: res << { 370: "name" => CGI.escapeHTML(meth.name), 371: "aref" => "#{path_prefix}\##{meth.aref}" 372: } 373: end 374: res 375: end
# File generators/html_generator.rb, line 411 411: def build_requires_list(context) 412: potentially_referenced_list(context.requires) {|fn| [fn + ".rb"] } 413: end
Create a list of HtmlMethod 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.
# File generators/html_generator.rb, line 355 355: def collect_methods 356: list = @context.method_list 357: unless @options.show_all 358: list = list.find_all {|m| m.visibility == :public || m.visibility == :protected || m.force_documentation } 359: end 360: @methods = list.collect {|m| HtmlMethod.new(m, self, @options) } 361: end
# File generators/html_generator.rb, line 581 581: def diagram_reference(diagram) 582: res = diagram.gsub(/((?:src|href)=")(.*?)"/) { 583: $1 + url($2) + '"' 584: } 585: res 586: end
# File generators/html_generator.rb, line 577 577: def document_self 578: @context.document_self 579: end
Find a filenames in ourselves or our parent
# File generators/html_generator.rb, line 599 599: def find_file(file, method=nil) 600: res = @context.find_file(file, method, 601: @options.ignore_case) 602: if res 603: res = res.viewer 604: end 605: res 606: end
Find a symbol in ourselves or our parent
# File generators/html_generator.rb, line 590 590: def find_symbol(symbol, method=nil) 591: res = @context.find_symbol(symbol, method, @options.ignore_case) 592: if res 593: res = res.viewer 594: end 595: res 596: end
convenience method to build a hyperlink
# File generators/html_generator.rb, line 334 334: def href(link, cls, name) 335: %{<a href="#{link}" class="#{cls}">#{name}</a>} #" 336: end
Build a list from an array of Htmlxxx 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
# File generators/html_generator.rb, line 428 428: def potentially_referenced_list(array) 429: res = [] 430: array.each do |i| 431: ref = AllReferences[i.name] 432: # if !ref 433: # container = @context.parent 434: # while !ref && container 435: # name = container.name + "::" + i.name 436: # ref = AllReferences[name] 437: # container = container.parent 438: # end 439: # end 440: 441: ref = @context.find_symbol(i.name, nil, @options.ignore_case) || \ 442: @context.find_file(i.name) 443: ref = ref.viewer if ref 444: 445: if !ref && block_given? 446: possibles = yield(i.name) 447: while !ref and !possibles.empty? 448: ref = AllReferences[possibles.shift] 449: end 450: end 451: h_name = CGI.escapeHTML(i.name) 452: if ref and ref.document_self 453: path = url(ref.path) 454: res << { "name" => h_name, "aref" => path } 455: else 456: res << { "name" => h_name } 457: end 458: end 459: res 460: end