1# gendoc.rb -- Converts the top-comments inside module.c to modules API 2# reference documentation in markdown format. 3 4# Convert the C comment to markdown 5def markdown(s) 6 s = s.gsub(/\*\/$/,"") 7 s = s.gsub(/^ \* {0,1}/,"") 8 s = s.gsub(/^\/\* /,"") 9 s.chop! while s[-1] == "\n" || s[-1] == " " 10 lines = s.split("\n") 11 newlines = [] 12 lines.each{|l| 13 if l[0] != ' ' 14 l = l.gsub(/RM_[A-z()]+/){|x| "`#{x}`"} 15 l = l.gsub(/RedisModule_[A-z()]+/){|x| "`#{x}`"} 16 l = l.gsub(/REDISMODULE_[A-z]+/){|x| "`#{x}`"} 17 end 18 newlines << l 19 } 20 return newlines.join("\n") 21end 22 23# Given the source code array and the index at which an exported symbol was 24# detected, extracts and outputs the documentation. 25def docufy(src,i) 26 m = /RM_[A-z0-9]+/.match(src[i]) 27 name = m[0] 28 name = name.sub("RM_","RedisModule_") 29 proto = src[i].sub("{","").strip+";\n" 30 proto = proto.sub("RM_","RedisModule_") 31 puts "## `#{name}`\n\n" 32 puts " #{proto}\n" 33 comment = "" 34 while true 35 i = i-1 36 comment = src[i]+comment 37 break if src[i] =~ /\/\*/ 38 end 39 comment = markdown(comment) 40 puts comment+"\n\n" 41end 42 43puts "# Modules API reference\n\n" 44src = File.open("../module.c").to_a 45src.each_with_index{|line,i| 46 if line =~ /RM_/ && line[0] != ' ' && line[0] != '#' && line[0] != '/' 47 if src[i-1] =~ /\*\// 48 docufy(src,i) 49 end 50 end 51} 52