Class: RDoc::Generator::Shomen
- Inherits:
-
Object
- Object
- RDoc::Generator::Shomen
- Defined in:
- lib/rdoc/generator/shomen.rb
Overview
Shomen Adaptor for RDoc utilizes the rdoc tool to parse ruby source code to build a Shomen documenation file.
RDoc is almost entirely a free-form documentation system, so it is not possible for Shomen to fully harness all the details it can support from the RDoc documentation, such as method argument descriptions.
Constant Summary collapse
- DESCRIPTION =
'Shomen documentation format'
Instance Attribute Summary collapse
-
#options ⇒ Object
readonly
User options from the command line.
Class Method Summary collapse
-
.for(options) ⇒ Object
Standard generator factory method.
- .setup_options(options) ⇒ Object
Instance Method Summary collapse
-
#attributes_all ⇒ Object
List of all attributes in all classes and modules.
-
#class_dir ⇒ Object
RDoc needs this to function.
-
#classes ⇒ Object
In the world of the RDoc Generators #classes is the same as #all_classes_and_modules.
-
#classes_toplevel ⇒ Object
Only toplevel classes and modules.
- #constants_all ⇒ Object
-
#file_dir ⇒ Object
RDoc needs this to function.
- #files ⇒ Object
- #files_hash ⇒ Object
-
#files_toplevel ⇒ Object
List of toplevel files.
-
#generate(files) ⇒ Object
Build the initial indices and output objects based on an array of top level objects containing the extracted information.
-
#methods_all ⇒ Object
List of all methods in all classes and modules.
- #output_file ⇒ Object
-
#shomen ⇒ Object
TODO: Rename ?.
Instance Attribute Details
#options ⇒ Object (readonly)
User options from the command line.
40 41 42 |
# File 'lib/rdoc/generator/shomen.rb', line 40 def @options end |
Class Method Details
.for(options) ⇒ Object
Standard generator factory method.
options - Generator options.
Returns new RDoc::Generator::Shomen instance.
35 36 37 |
# File 'lib/rdoc/generator/shomen.rb', line 35 def self.for() new() end |
.setup_options(options) ⇒ Object
43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 |
# File 'lib/rdoc/generator/shomen.rb', line 43 def self.() .source = false .yaml = false opt = .option_parser opt.separator nil opt.separator "Shomen generator options:" opt.separator nil opt.on("--yaml", "Generate YAML document instead of JSON.") do |value| .yaml = true end opt.separator nil opt.on("--source", "Include full source code for scripts.") do |value| .github = true end end |
Instance Method Details
#attributes_all ⇒ Object
List of all attributes in all classes and modules.
104 105 106 |
# File 'lib/rdoc/generator/shomen.rb', line 104 def attributes_all @attributes_all ||= classes.map{ |m| m.attributes }.flatten.sort end |
#class_dir ⇒ Object
RDoc needs this to function.
119 |
# File 'lib/rdoc/generator/shomen.rb', line 119 def class_dir ; nil ; end |
#classes ⇒ Object
In the world of the RDoc Generators #classes is the same as #all_classes_and_modules. Well, except that its sorted too. For classes sans modules, see #types.
70 71 72 |
# File 'lib/rdoc/generator/shomen.rb', line 70 def classes @classes ||= RDoc::TopLevel.all_classes_and_modules.sort end |
#classes_toplevel ⇒ Object
Only toplevel classes and modules.
75 76 77 |
# File 'lib/rdoc/generator/shomen.rb', line 75 def classes_toplevel @classes_toplevel ||= classes.select {|klass| !(RDoc::ClassModule === klass.parent) } end |
#constants_all ⇒ Object
109 110 111 |
# File 'lib/rdoc/generator/shomen.rb', line 109 def constants_all @constants_all ||= classes.map{ |c| c.constants }.flatten end |
#file_dir ⇒ Object
RDoc needs this to function.
122 |
# File 'lib/rdoc/generator/shomen.rb', line 122 def file_dir ; nil ; end |
#files ⇒ Object
80 81 82 83 84 |
# File 'lib/rdoc/generator/shomen.rb', line 80 def files @files ||= ( @files_rdoc.select{ |f| f.parser != RDoc::Parser::Simple } ) end |
#files_hash ⇒ Object
94 95 96 |
# File 'lib/rdoc/generator/shomen.rb', line 94 def files_hash @files ||= RDoc::TopLevel.files_hash end |
#files_toplevel ⇒ Object
List of toplevel files. RDoc supplies this via the #generate method.
87 88 89 90 91 |
# File 'lib/rdoc/generator/shomen.rb', line 87 def files_toplevel @files_toplevel ||= ( @files_rdoc.select{ |f| f.parser == RDoc::Parser::Simple } ) end |
#generate(files) ⇒ Object
Build the initial indices and output objects based on an array of top level objects containing the extracted information.
files - Files to document.
Returns nothing.
135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 |
# File 'lib/rdoc/generator/shomen.rb', line 135 def generate(files) @files_rdoc = files.sort @table = {} generate_constants generate_classes #generate_attributes generate_methods generate_documents generate_scripts # must be last b/c it depends on the others # TODO: method accessor fields need to be handled # THINK: Internal referencing model, YAML and JSYNC ? #ref_table = reference_table(@table) if .yaml out = @table.to_yaml else out = JSON.generate(@table) end if .op_dir == '-' puts out else File.open(output_file, 'w') do |f| f << out end unless $dryrun end #rescue StandardError => err # debug_msg "%s: %s\n %s" % [ err.class.name, err.message, err.backtrace.join("\n ") ] # raise err end |
#methods_all ⇒ Object
List of all methods in all classes and modules.
99 100 101 |
# File 'lib/rdoc/generator/shomen.rb', line 99 def methods_all @methods_all ||= classes.map{ |m| m.method_list }.flatten.sort end |
#output_file ⇒ Object
173 174 175 176 177 178 179 180 181 182 |
# File 'lib/rdoc/generator/shomen.rb', line 173 def output_file name = ['name'] vers = ['version'] if name && vers "#{name}-#{vers}.json" else 'doc.json' end end |
#shomen ⇒ Object
TODO: Rename ?
125 126 127 |
# File 'lib/rdoc/generator/shomen.rb', line 125 def shomen @table || {} end |