diff options
author | antirez <antirez@gmail.com> | 2016-04-20 19:06:19 +0200 |
---|---|---|
committer | antirez <antirez@gmail.com> | 2016-05-10 06:40:08 +0200 |
commit | d998170809f7474c3cb9fedc2ec266eaea39fa6c (patch) | |
tree | 0c0d048badb1ace5aa05df8373793184567a5688 /src/modules/gendoc.rb | |
parent | 0fd6d548cac3db5718547a440b92a6811bdde504 (diff) | |
download | redis-d998170809f7474c3cb9fedc2ec266eaea39fa6c.tar.gz |
Simple Ruby script to generate reference doc added.
Diffstat (limited to 'src/modules/gendoc.rb')
-rw-r--r-- | src/modules/gendoc.rb | 38 |
1 files changed, 38 insertions, 0 deletions
diff --git a/src/modules/gendoc.rb b/src/modules/gendoc.rb new file mode 100644 index 000000000..6fd687c33 --- /dev/null +++ b/src/modules/gendoc.rb @@ -0,0 +1,38 @@ +# gendoc.rb -- Converts the top-comments inside module.c to modules API +# reference documentaiton in markdown format. + +# Convert the C comment to markdown +def markdown(s) + s = s.gsub(/\*\/$/,"") + s = s.gsub(/^ \* {0,1}/,"") + s = s.gsub(/^\/\* /,"") + s.chop! while s[-1] == "\n" || s[-1] == " " + return s +end + +# Given the source code array and the index at which an exported symbol was +# detected, extracts and outputs the documentation. +def docufy(src,i) + m = /RM_[A-z0-9]+/.match(src[i]) + proto = src[i].sub("{","").strip+";\n" + puts "## #{m[0]}\n\n" + puts " #{proto}\n" + comment = "" + while true + i = i-1 + comment = src[i]+comment + break if src[i] =~ /\/\*/ + end + comment = markdown(comment) + puts comment+"\n\n" +end + +puts "# Modules API reference\n\n" +src = File.open("../module.c").to_a +src.each_with_index{|line,i| + if line =~ /RM_/ && line[0] != ' ' && line[0] != '#' && line[0] != '/' + if src[i-1] =~ /\*\// + docufy(src,i) + end + end +} |