lib/rdoc/generator/markdown.rb in rdoc-markdown-0.1.10 vs lib/rdoc/generator/markdown.rb in rdoc-markdown-0.1.12
- old
+ new
@@ -3,10 +3,11 @@
gem "rdoc"
require "pathname"
require "erb"
require "reverse_markdown"
+require 'extralite'
class RDoc::Generator::Markdown
RDoc::RDoc.add_generator self
TEMPLATE_DIR = File.expand_path(
@@ -58,10 +59,14 @@
output_dir.mkpath
debug("Generate documentation in #{@output_dir}")
emit_classfiles
+
+ debug("Generate index db file: #{output_dir}/index.db")
+
+ emit_sqlite
end
private
attr_reader :options
@@ -72,10 +77,33 @@
puts "[rdoc-markdown] #{str}" if str
yield if block_given?
end
end
+ def emit_sqlite
+ db = Extralite::Database.new("#{output_dir}/index.db")
+
+ db.execute <<-SQL
+ create table contentIndex (
+ id INTEGER PRIMARY KEY,
+ name TEXT,
+ type TEXT,
+ path TEXT
+ );
+ SQL
+
+ @classes.map do |klass|
+ {
+ name: klass.full_name,
+ type: klass.type.capitalize,
+ path: turn_to_path(klass.full_name)
+ }
+ end.each do |rec|
+ db.execute "insert into contentIndex (name, type, path) values (:name, :type, :path)", rec
+ end
+ end
+
def emit_classfiles
@classes.each do |klass|
klass_methods = []
instance_methods = []
@@ -89,11 +117,11 @@
end
end
template = ERB.new File.read(File.join(TEMPLATE_DIR, "classfile.md.erb"))
- out_file = Pathname.new("#{output_dir}/#{turn_to_path klass.full_name}.md")
+ out_file = Pathname.new("#{output_dir}/#{turn_to_path klass.full_name}")
out_file.dirname.mkpath
result = template.result(binding)
File.write(out_file, result)
@@ -102,10 +130,10 @@
private
def turn_to_path(class_name)
- class_name.gsub("::", "/")
+ "#{class_name.gsub("::", "/")}.md"
end
def markdownify(input)
md= ReverseMarkdown.convert input, github_flavored: true