Commit 1017868e authored by Daniel Bovensiepen's avatar Daniel Bovensiepen

Implement switch for line numbers

parent d83c66c8
class MRBDoc class MRBDoc
def write_documentation dir, &block def write_documentation dir, cfg, &block
block.call "MRBDOC\twrite to #{File.expand_path(dir)}" block.call "MRBDOC\twrite to #{File.expand_path(dir)}"
write(dir) do |progress| write(dir, cfg) do |progress|
block.call progress block.call progress
end end
end end
private private
def write dir def write dir, cfg
File.open(File.expand_path('Core.md', dir), 'w+') do |io| File.open(File.expand_path('Core.md', dir), 'w+') do |io|
print_core_classes(io) print_core_classes(io, cfg)
print_core_modules(io) print_core_modules(io, cfg)
end end
end end
...@@ -32,7 +32,7 @@ class MRBDoc ...@@ -32,7 +32,7 @@ class MRBDoc
core_list core_list
end end
def print_core_classes(io) def print_core_classes(io, cfg)
core_list = get_core_list :each_class core_list = get_core_list :each_class
io.puts "# Core Classes\n\n" io.puts "# Core Classes\n\n"
core_list.sort.each do |name, hsh| core_list.sort.each do |name, hsh|
...@@ -51,12 +51,12 @@ ISO Code | Mixins | Source File ...@@ -51,12 +51,12 @@ ISO Code | Mixins | Source File
#{iso} | #{mixins} | #{file} #{iso} | #{mixins} | #{file}
CLASS CLASS
print_class_methods(io, hsh) print_class_methods(io, hsh, cfg)
print_methods(io, hsh) print_methods(io, hsh, cfg)
end end
end end
def print_core_modules(io) def print_core_modules(io, cfg)
core_list = get_core_list :each_module core_list = get_core_list :each_module
io.puts "# Core Modules\n\n" io.puts "# Core Modules\n\n"
core_list.sort.each do |name, hsh| core_list.sort.each do |name, hsh|
...@@ -73,29 +73,34 @@ ISO Code | Source File ...@@ -73,29 +73,34 @@ ISO Code | Source File
#{iso} | #{file} #{iso} | #{file}
CLASS CLASS
print_class_methods(io, hsh) print_class_methods(io, hsh, cfg)
print_methods(io, hsh) print_methods(io, hsh, cfg)
end end
end end
def print_methods(io, hsh) def print_methods(io, hsh, cfg)
return unless hsh[:methods].size > 0 return unless hsh[:methods].size > 0
io.puts "### Methods\n\n" io.puts "### Methods\n\n"
hsh[:methods].sort.each do |met_name, met_hsh| hsh[:methods].sort.each do |met_name, met_hsh|
print_method(io, met_name, met_hsh) print_method(io, met_name, met_hsh, cfg)
end end
end end
def print_class_methods(io, hsh) def print_class_methods(io, hsh, cfg)
return unless hsh[:class_methods].size > 0 return unless hsh[:class_methods].size > 0
io.puts "### Class Methods\n\n" io.puts "### Class Methods\n\n"
hsh[:class_methods].sort.each do |met_name, met_hsh| hsh[:class_methods].sort.each do |met_name, met_hsh|
print_method(io, met_name, met_hsh) print_method(io, met_name, met_hsh, cfg)
end end
end end
def print_method(io, met_name, met_hsh) def print_method(io, met_name, met_hsh, cfg)
line_no = find_c_func(met_hsh[:c_func])[:line_no] if cfg[:print_line_no]
line_no_head = '| Line'
line_no = "| #{find_c_func(met_hsh[:c_func])[:line_no]}"
else
line_no, line_no_head = '', ''
end
file = find_c_file(met_hsh[:rb_class], met_hsh[:c_func]) file = find_c_file(met_hsh[:rb_class], met_hsh[:c_func])
file = file.split("#{@dir}/")[1] file = file.split("#{@dir}/")[1]
iso = met_hsh[:iso] iso = met_hsh[:iso]
...@@ -104,9 +109,9 @@ CLASS ...@@ -104,9 +109,9 @@ CLASS
io.puts <<METHOD io.puts <<METHOD
#### #{met_name} #### #{met_name}
ISO Code | Source File | C Function | Line ISO Code | Source File | C Function #{line_no_head}
--- | --- | --- --- | --- | ---
#{iso} | #{file} | #{met_hsh[:c_func]} | #{line_no} #{iso} | #{file} | #{met_hsh[:c_func]} #{line_no}
METHOD METHOD
end end
......
...@@ -7,16 +7,31 @@ require 'mrbdoc_docu' ...@@ -7,16 +7,31 @@ require 'mrbdoc_docu'
MRUBY_ROOT = ARGV[0] MRUBY_ROOT = ARGV[0]
DOC_ROOT = ARGV[1] DOC_ROOT = ARGV[1]
_WRITE_LINE_NO = ARGV[2]
raise ArgumentError.new 'mruby root missing!' if MRUBY_ROOT.nil? raise ArgumentError.new 'mruby root missing!' if MRUBY_ROOT.nil?
raise ArgumentError.new 'doc root missing!' if DOC_ROOT.nil? raise ArgumentError.new 'doc root missing!' if DOC_ROOT.nil?
if _WRITE_LINE_NO.nil?
WRITE_LINE_NO = true
else
case _WRITE_LINE_NO
when 'true'
WRITE_LINE_NO = true
when 'false'
WRITE_LINE_NO = false
else
raise ArgumentError.new 'Line no parameter has to be false or true!'
end
end
mrbdoc = MRBDoc.new mrbdoc = MRBDoc.new
mrbdoc.analyze_code MRUBY_ROOT do |progress| mrbdoc.analyze_code MRUBY_ROOT do |progress|
puts progress puts progress
end end
mrbdoc.write_documentation DOC_ROOT do |progress| cfg = {:print_line_no => WRITE_LINE_NO}
mrbdoc.write_documentation DOC_ROOT, cfg do |progress|
puts progress puts progress
end end
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment