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
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
create table of contents if we contain sections
# File lib/generators/templates/application/merb_core/doc/rdoc/generators/merb_generator.rb, line 522 522: def add_table_of_sections 523: toc = [] 524: @context.sections.each do |section| 525: if section.title 526: toc << { 527: 'secname' => section.title, 528: 'href' => section.sequence 529: } 530: end 531: end 532: 533: @values['toc'] = toc unless toc.empty? 534: end
create table of contents if we contain sections
# File lib/generators/templates/application/merb_stack/doc/rdoc/generators/merb_generator.rb, line 522 522: def add_table_of_sections 523: toc = [] 524: @context.sections.each do |section| 525: if section.title 526: toc << { 527: 'secname' => section.title, 528: 'href' => section.sequence 529: } 530: end 531: end 532: 533: @values['toc'] = toc unless toc.empty? 534: end
Build a list of aliases for which we couldn’t find a corresponding method
# File lib/generators/templates/application/merb_core/doc/rdoc/generators/merb_generator.rb, line 312 312: def build_alias_summary_list(section) 313: values = [] 314: @context.aliases.each do |al| 315: next unless al.section == section 316: res = { 317: 'old_name' => al.old_name, 318: 'new_name' => al.new_name, 319: } 320: if al.comment && !al.comment.empty? 321: res['desc'] = markup(al.comment, true) 322: end 323: values << res 324: end 325: values 326: end
Build a list of aliases for which we couldn’t find a corresponding method
# File lib/generators/templates/application/merb_stack/doc/rdoc/generators/merb_generator.rb, line 312 312: def build_alias_summary_list(section) 313: values = [] 314: @context.aliases.each do |al| 315: next unless al.section == section 316: res = { 317: 'old_name' => al.old_name, 318: 'new_name' => al.new_name, 319: } 320: if al.comment && !al.comment.empty? 321: res['desc'] = markup(al.comment, true) 322: end 323: values << res 324: end 325: values 326: end
Build the structured list of classes and modules contained in this context.
# File lib/generators/templates/application/merb_core/doc/rdoc/generators/merb_generator.rb, line 466 466: def build_class_list(level, from, section, infile=nil) 467: res = "" 468: prefix = " ::" * level; 469: 470: from.modules.sort.each do |mod| 471: next unless mod.section == section 472: next if infile && !mod.defined_in?(infile) 473: if mod.document_self 474: res << 475: prefix << 476: "Module " << 477: href(mod.viewer.path, "link", mod.full_name) << 478: "<br />\n" << 479: build_class_list(level + 1, mod, section, infile) 480: end 481: end 482: 483: from.classes.sort.each do |cls| 484: next unless cls.section == section 485: next if infile && !cls.defined_in?(infile) 486: if cls.document_self 487: res << 488: prefix << 489: "Class " << 490: href(cls.viewer.path, "link", cls.full_name) << 491: "<br />\n" << 492: build_class_list(level + 1, cls, section, infile) 493: end 494: end 495: 496: res 497: end
Build the structured list of classes and modules contained in this context.
# File lib/generators/templates/application/merb_stack/doc/rdoc/generators/merb_generator.rb, line 466 466: def build_class_list(level, from, section, infile=nil) 467: res = "" 468: prefix = " ::" * level; 469: 470: from.modules.sort.each do |mod| 471: next unless mod.section == section 472: next if infile && !mod.defined_in?(infile) 473: if mod.document_self 474: res << 475: prefix << 476: "Module " << 477: href(mod.viewer.path, "link", mod.full_name) << 478: "<br />\n" << 479: build_class_list(level + 1, mod, section, infile) 480: end 481: end 482: 483: from.classes.sort.each do |cls| 484: next unless cls.section == section 485: next if infile && !cls.defined_in?(infile) 486: if cls.document_self 487: res << 488: prefix << 489: "Class " << 490: href(cls.viewer.path, "link", cls.full_name) << 491: "<br />\n" << 492: build_class_list(level + 1, cls, section, infile) 493: end 494: end 495: 496: res 497: end
Build a list of constants
# File lib/generators/templates/application/merb_stack/doc/rdoc/generators/merb_generator.rb, line 329 329: def build_constants_summary_list(section) 330: values = [] 331: @context.constants.each do |co| 332: next unless co.section == section 333: res = { 334: 'name' => co.name, 335: 'value' => CGI.escapeHTML(co.value) 336: } 337: res['desc'] = markup(co.comment, true) if co.comment && !co.comment.empty? 338: values << res 339: end 340: values 341: end
Build a list of constants
# File lib/generators/templates/application/merb_core/doc/rdoc/generators/merb_generator.rb, line 329 329: def build_constants_summary_list(section) 330: values = [] 331: @context.constants.each do |co| 332: next unless co.section == section 333: res = { 334: 'name' => co.name, 335: 'value' => CGI.escapeHTML(co.value) 336: } 337: res['desc'] = markup(co.comment, true) if co.comment && !co.comment.empty? 338: values << res 339: end 340: values 341: end
# File lib/generators/templates/application/merb_core/doc/rdoc/generators/merb_generator.rb, line 347 347: def build_include_list(context) 348: potentially_referenced_list(context.includes) 349: end
# File lib/generators/templates/application/merb_stack/doc/rdoc/generators/merb_generator.rb, line 347 347: def build_include_list(context) 348: potentially_referenced_list(context.includes) 349: 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 lib/generators/templates/application/merb_core/doc/rdoc/generators/merb_generator.rb, line 398 398: def build_method_detail_list(section) 399: outer = [] 400: 401: methods = @methods.sort 402: for singleton in [true, false] 403: for vis in [ :public, :protected, :private ] 404: res = [] 405: methods.each do |m| 406: if m.section == section and 407: m.document_self and 408: m.visibility == vis and 409: m.singleton == singleton 410: row = {} 411: if m.call_seq 412: row["callseq"] = m.call_seq.gsub(/->/, '→') 413: else 414: row["name"] = CGI.escapeHTML(m.name) 415: row["params"] = m.params 416: end 417: desc = m.description.strip 418: row["m_desc"] = desc unless desc.empty? 419: row["aref"] = m.aref 420: row["href"] = m.path 421: row["m_seq"] = m.seq 422: row["visibility"] = m.visibility.to_s 423: 424: alias_names = [] 425: m.aliases.each do |other| 426: if other.viewer # won't be if the alias is private 427: alias_names << { 428: 'name' => other.name, 429: 'href' => other.viewer.path, 430: 'aref' => other.viewer.aref 431: } 432: end 433: end 434: unless alias_names.empty? 435: row["aka"] = alias_names 436: end 437: 438: #if @options.inline_source 439: code = m.source_code 440: row["sourcecode"] = code if code 441: #else 442: # code = m.src_url 443: #if code 444: # row["codeurl"] = code 445: # row["imgurl"] = m.img_url 446: #end 447: #end 448: res << row 449: end 450: end 451: if res.size > 0 452: outer << { 453: "type" => vis.to_s.capitalize, 454: "category" => singleton ? "Class" : "Instance", 455: "methods" => res 456: } 457: end 458: end 459: end 460: outer 461: 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 lib/generators/templates/application/merb_stack/doc/rdoc/generators/merb_generator.rb, line 398 398: def build_method_detail_list(section) 399: outer = [] 400: 401: methods = @methods.sort 402: for singleton in [true, false] 403: for vis in [ :public, :protected, :private ] 404: res = [] 405: methods.each do |m| 406: if m.section == section and 407: m.document_self and 408: m.visibility == vis and 409: m.singleton == singleton 410: row = {} 411: if m.call_seq 412: row["callseq"] = m.call_seq.gsub(/->/, '→') 413: else 414: row["name"] = CGI.escapeHTML(m.name) 415: row["params"] = m.params 416: end 417: desc = m.description.strip 418: row["m_desc"] = desc unless desc.empty? 419: row["aref"] = m.aref 420: row["href"] = m.path 421: row["m_seq"] = m.seq 422: row["visibility"] = m.visibility.to_s 423: 424: alias_names = [] 425: m.aliases.each do |other| 426: if other.viewer # won't be if the alias is private 427: alias_names << { 428: 'name' => other.name, 429: 'href' => other.viewer.path, 430: 'aref' => other.viewer.aref 431: } 432: end 433: end 434: unless alias_names.empty? 435: row["aka"] = alias_names 436: end 437: 438: #if @options.inline_source 439: code = m.source_code 440: row["sourcecode"] = code if code 441: #else 442: # code = m.src_url 443: #if code 444: # row["codeurl"] = code 445: # row["imgurl"] = m.img_url 446: #end 447: #end 448: res << row 449: end 450: end 451: if res.size > 0 452: outer << { 453: "type" => vis.to_s.capitalize, 454: "category" => singleton ? "Class" : "Instance", 455: "methods" => res 456: } 457: end 458: end 459: end 460: outer 461: end
Build a summary list of all the methods in this context
# File lib/generators/templates/application/merb_stack/doc/rdoc/generators/merb_generator.rb, line 295 295: def build_method_summary_list(path_prefix="") 296: collect_methods unless @methods 297: meths = @methods.sort 298: res = [] 299: meths.each do |meth| 300: res << { 301: "name" => CGI.escapeHTML(meth.name), 302: "aref" => meth.aref, 303: "href" => meth.path 304: } 305: end 306: res 307: end
Build a summary list of all the methods in this context
# File lib/generators/templates/application/merb_core/doc/rdoc/generators/merb_generator.rb, line 295 295: def build_method_summary_list(path_prefix="") 296: collect_methods unless @methods 297: meths = @methods.sort 298: res = [] 299: meths.each do |meth| 300: res << { 301: "name" => CGI.escapeHTML(meth.name), 302: "aref" => meth.aref, 303: "href" => meth.path 304: } 305: end 306: res 307: end
# File lib/generators/templates/application/merb_stack/doc/rdoc/generators/merb_generator.rb, line 343 343: def build_requires_list(context) 344: potentially_referenced_list(context.requires) {|fn| [fn + ".rb"] } 345: end
# File lib/generators/templates/application/merb_core/doc/rdoc/generators/merb_generator.rb, line 343 343: def build_requires_list(context) 344: potentially_referenced_list(context.requires) {|fn| [fn + ".rb"] } 345: 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 lib/generators/templates/application/merb_core/doc/rdoc/generators/merb_generator.rb, line 286 286: def collect_methods 287: list = @context.method_list 288: unless @options.show_all 289: list = list.find_all {|m| m.visibility == :public || m.visibility == :protected || m.force_documentation } 290: end 291: @methods = list.collect {|m| HtmlMethod.new(m, self, @options) } 292: 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 lib/generators/templates/application/merb_stack/doc/rdoc/generators/merb_generator.rb, line 286 286: def collect_methods 287: list = @context.method_list 288: unless @options.show_all 289: list = list.find_all {|m| m.visibility == :public || m.visibility == :protected || m.force_documentation } 290: end 291: @methods = list.collect {|m| HtmlMethod.new(m, self, @options) } 292: end
# File lib/generators/templates/application/merb_stack/doc/rdoc/generators/merb_generator.rb, line 503 503: def diagram_reference(diagram) 504: res = diagram.gsub(/((?:src|href)=")(.*?)"/) { 505: $1 + $2 + '"' 506: } 507: res 508: end
# File lib/generators/templates/application/merb_core/doc/rdoc/generators/merb_generator.rb, line 503 503: def diagram_reference(diagram) 504: res = diagram.gsub(/((?:src|href)=")(.*?)"/) { 505: $1 + $2 + '"' 506: } 507: res 508: end
# File lib/generators/templates/application/merb_core/doc/rdoc/generators/merb_generator.rb, line 499 499: def document_self 500: @context.document_self 501: end
# File lib/generators/templates/application/merb_stack/doc/rdoc/generators/merb_generator.rb, line 499 499: def document_self 500: @context.document_self 501: end
Find a symbol in ourselves or our parent
# File lib/generators/templates/application/merb_stack/doc/rdoc/generators/merb_generator.rb, line 512 512: def find_symbol(symbol, method=nil) 513: res = @context.find_symbol(symbol, method) 514: if res 515: res = res.viewer 516: end 517: res 518: end
Find a symbol in ourselves or our parent
# File lib/generators/templates/application/merb_core/doc/rdoc/generators/merb_generator.rb, line 512 512: def find_symbol(symbol, method=nil) 513: res = @context.find_symbol(symbol, method) 514: if res 515: res = res.viewer 516: end 517: res 518: end
convenience method to build a hyperlink # Where’s the DRY in this?? Put this in the template where it belongs
# File lib/generators/templates/application/merb_stack/doc/rdoc/generators/merb_generator.rb, line 277 277: def href(link, cls, name) 278: %{"<a href=\"#\" onclick=\"jsHref('#{link}');\" class=\"#{cls}\">#{name}</a>"} 279: end
convenience method to build a hyperlink # Where’s the DRY in this?? Put this in the template where it belongs
# File lib/generators/templates/application/merb_core/doc/rdoc/generators/merb_generator.rb, line 277 277: def href(link, cls, name) 278: %{"<a href=\"#\" onclick=\"jsHref('#{link}');\" class=\"#{cls}\">#{name}</a>"} 279: 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 lib/generators/templates/application/merb_core/doc/rdoc/generators/merb_generator.rb, line 360 360: def potentially_referenced_list(array) 361: res = [] 362: array.each do |i| 363: ref = AllReferences[i.name] 364: # if !ref 365: # container = @context.parent 366: # while !ref && container 367: # name = container.name + "::" + i.name 368: # ref = AllReferences[name] 369: # container = container.parent 370: # end 371: # end 372: 373: ref = @context.find_symbol(i.name) 374: ref = ref.viewer if ref 375: 376: if !ref && block_given? 377: possibles = yield(i.name) 378: while !ref and !possibles.empty? 379: ref = AllReferences[possibles.shift] 380: end 381: end 382: h_name = CGI.escapeHTML(i.name) 383: if ref and ref.document_self 384: path = ref.path 385: res << { "name" => h_name, "href" => path } 386: else 387: res << { "name" => h_name, "href" => "" } 388: end 389: end 390: res 391: 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 lib/generators/templates/application/merb_stack/doc/rdoc/generators/merb_generator.rb, line 360 360: def potentially_referenced_list(array) 361: res = [] 362: array.each do |i| 363: ref = AllReferences[i.name] 364: # if !ref 365: # container = @context.parent 366: # while !ref && container 367: # name = container.name + "::" + i.name 368: # ref = AllReferences[name] 369: # container = container.parent 370: # end 371: # end 372: 373: ref = @context.find_symbol(i.name) 374: ref = ref.viewer if ref 375: 376: if !ref && block_given? 377: possibles = yield(i.name) 378: while !ref and !possibles.empty? 379: ref = AllReferences[possibles.shift] 380: end 381: end 382: h_name = CGI.escapeHTML(i.name) 383: if ref and ref.document_self 384: path = ref.path 385: res << { "name" => h_name, "href" => path } 386: else 387: res << { "name" => h_name, "href" => "" } 388: end 389: end 390: res 391: end
Disabled; run with --debug to generate this.
Generated with the Darkfish Rdoc Generator 1.1.6.