forked from MSch/erlang-docset
-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathgenerate.rb
executable file
·37 lines (31 loc) · 1.13 KB
/
generate.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
require 'nokogiri'
doc_file = ARGV.first
file_name = ARGV.first
def check_doc_type doc
sample = doc.css('h3').collect { |x| x.content }
case sample[0...2]
when ["MODULE", "MODULE SUMMARY"] then :module
else :undef
end
end
def write_html doc, file
builder = Nokogiri::HTML::Builder.new do |b|
b.html do
b.header do b << '<link href="doc.css" media="screen" rel="stylesheet" type="text/css" />' end
b.body do b << doc.css("#content").first end
end
end
File.open("_output/erlang.docset/Contents/Resources/Documents/#{file}", 'w') {|f| f.write(builder.to_html) }
end
doc = Nokogiri::HTML(ARGF.read)
case check_doc_type(doc)
when :module then
puts "CREATE TABLE IF NOT EXISTS searchIndex(id INTEGER PRIMARY KEY, name TEXT, type TEXT, path TEXT);"
#write_html(doc, file_name)
mod = doc.css("h3").first.next.next.content
puts "INSERT INTO searchIndex VALUES (NULL, '#{mod}', 'cl', '#{file_name}');"
doc.css("#content > .innertube > p > a").each do |x|
fun = x.attr('name').gsub("'", "")
puts "INSERT INTO searchIndex VALUES (NULL, '#{mod}:#{fun.sub('-', '/')}', 'func', '#{file_name}##{fun}');"
end
end