From 1017868e786c5e07218523b8686b9f11a7a81eb7 Mon Sep 17 00:00:00 2001 From: Daniel Bovensiepen Date: Tue, 15 Apr 2014 13:05:40 +0800 Subject: Implement switch for line numbers --- doc/language/mrbdoc/lib/mrbdoc_docu.rb | 43 +++++++++++++++++++--------------- 1 file changed, 24 insertions(+), 19 deletions(-) (limited to 'doc/language/mrbdoc/lib/mrbdoc_docu.rb') diff --git a/doc/language/mrbdoc/lib/mrbdoc_docu.rb b/doc/language/mrbdoc/lib/mrbdoc_docu.rb index 116228927..b2f45851e 100644 --- a/doc/language/mrbdoc/lib/mrbdoc_docu.rb +++ b/doc/language/mrbdoc/lib/mrbdoc_docu.rb @@ -1,18 +1,18 @@ class MRBDoc - def write_documentation dir, &block + def write_documentation dir, cfg, &block block.call "MRBDOC\twrite to #{File.expand_path(dir)}" - write(dir) do |progress| + write(dir, cfg) do |progress| block.call progress end end private - def write dir + def write dir, cfg File.open(File.expand_path('Core.md', dir), 'w+') do |io| - print_core_classes(io) - print_core_modules(io) + print_core_classes(io, cfg) + print_core_modules(io, cfg) end end @@ -32,7 +32,7 @@ class MRBDoc core_list end - def print_core_classes(io) + def print_core_classes(io, cfg) core_list = get_core_list :each_class io.puts "# Core Classes\n\n" core_list.sort.each do |name, hsh| @@ -51,12 +51,12 @@ ISO Code | Mixins | Source File #{iso} | #{mixins} | #{file} CLASS - print_class_methods(io, hsh) - print_methods(io, hsh) + print_class_methods(io, hsh, cfg) + print_methods(io, hsh, cfg) end end - def print_core_modules(io) + def print_core_modules(io, cfg) core_list = get_core_list :each_module io.puts "# Core Modules\n\n" core_list.sort.each do |name, hsh| @@ -73,29 +73,34 @@ ISO Code | Source File #{iso} | #{file} CLASS - print_class_methods(io, hsh) - print_methods(io, hsh) + print_class_methods(io, hsh, cfg) + print_methods(io, hsh, cfg) end end - def print_methods(io, hsh) + def print_methods(io, hsh, cfg) return unless hsh[:methods].size > 0 io.puts "### Methods\n\n" 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 - def print_class_methods(io, hsh) + def print_class_methods(io, hsh, cfg) return unless hsh[:class_methods].size > 0 io.puts "### Class Methods\n\n" 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 - def print_method(io, met_name, met_hsh) - line_no = find_c_func(met_hsh[:c_func])[:line_no] + def print_method(io, met_name, met_hsh, cfg) + 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 = file.split("#{@dir}/")[1] iso = met_hsh[:iso] @@ -104,9 +109,9 @@ CLASS io.puts < Date: Tue, 15 Apr 2014 18:28:16 +0800 Subject: merge @mattn's win-compatibility --- doc/language/generator.rb | 9 ++++++--- doc/language/mrbdoc/lib/mrbdoc_docu.rb | 2 +- doc/language/mrbdoc/mrbdoc.rb | 1 + 3 files changed, 8 insertions(+), 4 deletions(-) (limited to 'doc/language/mrbdoc/lib/mrbdoc_docu.rb') diff --git a/doc/language/generator.rb b/doc/language/generator.rb index a94e8011b..c5bab1f84 100755 --- a/doc/language/generator.rb +++ b/doc/language/generator.rb @@ -6,7 +6,10 @@ c_dir = File.dirname(__FILE__) MRUBY_ROOT = File.expand_path("#{c_dir}/../..") DOC_DIR = File.expand_path(c_dir) -cmd = "#{DOC_DIR}/mrbdoc/mrbdoc.rb #{MRUBY_ROOT} #{DOC_DIR}" -PTY.spawn(cmd) do |i,o,pid| - i.each { |l| print l } +cmd = "ruby #{DOC_DIR}/mrbdoc/mrbdoc.rb #{MRUBY_ROOT} #{DOC_DIR} false" +IO.popen(cmd, "r+") do |io| + io.close_write + while line = io.gets + puts line + end end diff --git a/doc/language/mrbdoc/lib/mrbdoc_docu.rb b/doc/language/mrbdoc/lib/mrbdoc_docu.rb index b2f45851e..4dc20a5a3 100644 --- a/doc/language/mrbdoc/lib/mrbdoc_docu.rb +++ b/doc/language/mrbdoc/lib/mrbdoc_docu.rb @@ -10,7 +10,7 @@ class MRBDoc private def write dir, cfg - File.open(File.expand_path('Core.md', dir), 'w+') do |io| + File.open(File.expand_path('Core.md', dir), 'wb+') do |io| print_core_classes(io, cfg) print_core_modules(io, cfg) end diff --git a/doc/language/mrbdoc/mrbdoc.rb b/doc/language/mrbdoc/mrbdoc.rb index 5a8e4641a..cafdf112a 100755 --- a/doc/language/mrbdoc/mrbdoc.rb +++ b/doc/language/mrbdoc/mrbdoc.rb @@ -8,6 +8,7 @@ require 'mrbdoc_docu' MRUBY_ROOT = ARGV[0] DOC_ROOT = ARGV[1] _WRITE_LINE_NO = ARGV[2] +STDOUT.sync = true raise ArgumentError.new 'mruby root missing!' if MRUBY_ROOT.nil? raise ArgumentError.new 'doc root missing!' if DOC_ROOT.nil? -- cgit v1.2.3