list protocols in framework index files (.md), change the way protocols are defined in ruby (now using module) and also how we keep track of them (not using a temporary file)

This commit is contained in:
Laurent Sansonetti
2012-11-05 17:14:48 +01:00
parent 3bb0137724
commit 7b48bf7acb
2 changed files with 33 additions and 52 deletions

View File

@@ -218,6 +218,7 @@ namespace :doc do
# generate .md files for frameworks # generate .md files for frameworks
frameworks_hash = {} frameworks_hash = {}
all_protocols = []
ruby_files = Dir.glob(File.join(DOCSET_RUBY_FILES_DIR, '*.rb')) ruby_files = Dir.glob(File.join(DOCSET_RUBY_FILES_DIR, '*.rb'))
ruby_files.each do |x| ruby_files.each do |x|
data = File.read(x) data = File.read(x)
@@ -240,16 +241,20 @@ namespace :doc do
next unless framework next unless framework
# get the list of classes # get the list of classes
classes = data.scan(/^class\s+([^\s\n]+)/).flatten classes = data.scan(/^class\s+([^\s\n]+)/).flatten
# get the list of protocols
protocols = data.scan(/^module\s+([^\s\n]+)/).flatten
# get the list of functions # get the list of functions
functions = data.scan(/^def\s+([^\s\n\(]+)/).flatten functions = data.scan(/^def\s+([^\s\n\(]+)/).flatten
if !classes.empty? or !functions.empty? if !classes.empty? or !protocols.empty? or !functions.empty?
ary = (frameworks_hash[framework] ||= [[], []]) ary = (frameworks_hash[framework] ||= [[], [], []])
ary[0].concat(classes) ary[0].concat(classes)
ary[1].concat(functions) ary[1].concat(protocols)
ary[2].concat(functions)
end end
all_protocols.concat(protocols)
end end
frameworks_hash.each do |name, ary| frameworks_hash.each do |name, ary|
classes, functions = ary classes, protocols, functions = ary
next if name == 'AppKit' next if name == 'AppKit'
File.open("#{OUTPUT_DIR}/#{name}.md", 'w') do |io| File.open("#{OUTPUT_DIR}/#{name}.md", 'w') do |io|
io.puts "# @markup markdown" io.puts "# @markup markdown"
@@ -261,6 +266,12 @@ namespace :doc do
io.puts "- [#{klass}](#{klass}.html)" io.puts "- [#{klass}](#{klass}.html)"
end end
end end
unless protocols.empty?
io.puts "\n## Protocols"
protocols.sort.each do |prot|
io.puts "- [#{prot}](#{prot}.html)"
end
end
unless functions.empty? unless functions.empty?
io.puts "\n## Functions" io.puts "\n## Functions"
functions.sort.each do |func| functions.sort.each do |func|
@@ -279,8 +290,7 @@ namespace :doc do
FileUtils.ln "#{OUTPUT_DIR}/_index.html", "#{OUTPUT_DIR}/index.html" unless File.exist?("#{OUTPUT_DIR}/index.html") FileUtils.ln "#{OUTPUT_DIR}/_index.html", "#{OUTPUT_DIR}/index.html" unless File.exist?("#{OUTPUT_DIR}/index.html")
# update Protocol documents # update Protocol documents
protocol_name_list = File.read("#{DOCSET_RUBY_FILES_DIR}/protocol_list") all_protocols.each do |protocol|
protocol_name_list.lines.each do |protocol|
protocol.strip! protocol.strip!
DocsetGenerator.modify_protocol_document("#{OUTPUT_DIR}/#{protocol}.html") DocsetGenerator.modify_protocol_document("#{OUTPUT_DIR}/#{protocol}.html")
end end

View File

@@ -122,7 +122,7 @@ class DocsetGenerator
end end
end end
def parse_html_class(name, doc) def parse_html_class(name, doc, code)
# Find superclass (mandatory). # Find superclass (mandatory).
sclass = nil sclass = nil
doc.xpath("//table[@class='specbox']/tr").each do |node| doc.xpath("//table[@class='specbox']/tr").each do |node|
@@ -133,14 +133,6 @@ class DocsetGenerator
end end
return nil unless sclass return nil unless sclass
code = ''
if framework_path = find_framework_path(doc)
code << "# -*- framework: #{framework_path} -*-\n\n"
else
$stderr.puts "Can't determine framework path for: #{name}"
code << "\n\n"
end
# Class abstract. # Class abstract.
code << doc.xpath(".//p[@class='abstract']")[0].text.gsub(/^/m, '# ') code << doc.xpath(".//p[@class='abstract']")[0].text.gsub(/^/m, '# ')
if sclass == "none" if sclass == "none"
@@ -170,25 +162,18 @@ class DocsetGenerator
return code return code
end end
def parse_html_protocol(name, doc) def parse_html_protocol(name, doc, code)
code = ''
# Class abstract. # Class abstract.
node = doc.xpath(".//p[@class='abstract']") node = doc.xpath(".//p[@class='abstract']")
return nil if node.empty? return nil if node.empty?
code << node.text.gsub(/^/m, '# ') code << node.text.gsub(/^/m, '# ')
code << "\nclass #{name}\n\n" code << "\nmodule #{name}\n\n"
parse_html_method(doc, code) parse_html_method(doc, code)
code << "end" code << "end"
# save protocol name into list
File.open(File.join(@rb_files_dir, "protocol_list"), 'a') do |io|
io.puts name
end
return code return code
end end
@@ -288,15 +273,7 @@ class DocsetGenerator
return code return code
end end
def parse_html_reference(name, doc) def parse_html_reference(name, doc, code)
code = ''
if framework_path = find_framework_path(doc)
code << "# -*- framework: #{framework_path} -*-\n\n"
else
#$stderr.puts "Can't determine framework path for: #{name}"
code << "\n\n"
end
if node = doc.xpath("//section/a[@title='Functions']") if node = doc.xpath("//section/a[@title='Functions']")
parse_html_function(node, code) parse_html_function(node, code)
end end
@@ -311,12 +288,20 @@ class DocsetGenerator
doc = Nokogiri::HTML(data) doc = Nokogiri::HTML(data)
title = doc.xpath('/html/head/title') title = doc.xpath('/html/head/title')
if title if title
code = ''
if framework_path = find_framework_path(doc)
code << "# -*- framework: #{framework_path} -*-\n\n"
else
#$stderr.puts "Can't determine framework path for: #{name}"
code << "\n\n"
end
if md = title.text.match(/^(.+)Class Reference$/) if md = title.text.match(/^(.+)Class Reference$/)
parse_html_class(md[1].strip, doc) parse_html_class(md[1].strip, doc, code)
elsif md = title.text.match(/^(.+)Protocol Reference$/) elsif md = title.text.match(/^(.+)Protocol Reference$/)
parse_html_protocol(md[1].strip, doc) parse_html_protocol(md[1].strip, doc, code)
elsif md = title.text.match(/^(.+) Reference$/) elsif md = title.text.match(/^(.+) Reference$/)
parse_html_reference(md[1].strip, doc) parse_html_reference(md[1].strip, doc, code)
end end
else else
nil nil
@@ -329,23 +314,9 @@ class DocsetGenerator
return nil return nil
end end
data = File.read(path) data = File.read(path)
data.gsub!(/\s*Class:/, 'Protocol:') data.gsub!(/\s*Module:/, 'Protocol:')
doc = Nokogiri::HTML(data) File.open(path, "w") { |io| io.print data }
# remove 'Inherits' box
doc.xpath("//dl[@class='box']").remove
# remove 'Methods inherited from NSObject'
doc.xpath("//h3[@class='inherited']").remove
doc.xpath("//p[@class='inherited']").remove
# remove 'Constructor Details'
doc.xpath("//div[@id='constructor_details']").remove
# remove 'Dynamic Method Handling'
doc.xpath("//div[@id='method_missing_details']").remove
File.open(path, "w") { |io| io.print doc.to_html }
end end
def initialize(outpath, paths) def initialize(outpath, paths)