mirror of
https://github.com/zhigang1992/RubyMotion.git
synced 2026-04-01 17:39:54 +08:00
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:
22
Rakefile
22
Rakefile
@@ -218,6 +218,7 @@ namespace :doc do
|
||||
|
||||
# generate .md files for frameworks
|
||||
frameworks_hash = {}
|
||||
all_protocols = []
|
||||
ruby_files = Dir.glob(File.join(DOCSET_RUBY_FILES_DIR, '*.rb'))
|
||||
ruby_files.each do |x|
|
||||
data = File.read(x)
|
||||
@@ -240,16 +241,20 @@ namespace :doc do
|
||||
next unless framework
|
||||
# get the list of classes
|
||||
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
|
||||
functions = data.scan(/^def\s+([^\s\n\(]+)/).flatten
|
||||
if !classes.empty? or !functions.empty?
|
||||
ary = (frameworks_hash[framework] ||= [[], []])
|
||||
if !classes.empty? or !protocols.empty? or !functions.empty?
|
||||
ary = (frameworks_hash[framework] ||= [[], [], []])
|
||||
ary[0].concat(classes)
|
||||
ary[1].concat(functions)
|
||||
ary[1].concat(protocols)
|
||||
ary[2].concat(functions)
|
||||
end
|
||||
all_protocols.concat(protocols)
|
||||
end
|
||||
frameworks_hash.each do |name, ary|
|
||||
classes, functions = ary
|
||||
classes, protocols, functions = ary
|
||||
next if name == 'AppKit'
|
||||
File.open("#{OUTPUT_DIR}/#{name}.md", 'w') do |io|
|
||||
io.puts "# @markup markdown"
|
||||
@@ -261,6 +266,12 @@ namespace :doc do
|
||||
io.puts "- [#{klass}](#{klass}.html)"
|
||||
end
|
||||
end
|
||||
unless protocols.empty?
|
||||
io.puts "\n## Protocols"
|
||||
protocols.sort.each do |prot|
|
||||
io.puts "- [#{prot}](#{prot}.html)"
|
||||
end
|
||||
end
|
||||
unless functions.empty?
|
||||
io.puts "\n## Functions"
|
||||
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")
|
||||
|
||||
# update Protocol documents
|
||||
protocol_name_list = File.read("#{DOCSET_RUBY_FILES_DIR}/protocol_list")
|
||||
protocol_name_list.lines.each do |protocol|
|
||||
all_protocols.each do |protocol|
|
||||
protocol.strip!
|
||||
DocsetGenerator.modify_protocol_document("#{OUTPUT_DIR}/#{protocol}.html")
|
||||
end
|
||||
|
||||
@@ -122,7 +122,7 @@ class DocsetGenerator
|
||||
end
|
||||
end
|
||||
|
||||
def parse_html_class(name, doc)
|
||||
def parse_html_class(name, doc, code)
|
||||
# Find superclass (mandatory).
|
||||
sclass = nil
|
||||
doc.xpath("//table[@class='specbox']/tr").each do |node|
|
||||
@@ -133,14 +133,6 @@ class DocsetGenerator
|
||||
end
|
||||
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.
|
||||
code << doc.xpath(".//p[@class='abstract']")[0].text.gsub(/^/m, '# ')
|
||||
if sclass == "none"
|
||||
@@ -170,25 +162,18 @@ class DocsetGenerator
|
||||
return code
|
||||
end
|
||||
|
||||
def parse_html_protocol(name, doc)
|
||||
code = ''
|
||||
|
||||
def parse_html_protocol(name, doc, code)
|
||||
# Class abstract.
|
||||
node = doc.xpath(".//p[@class='abstract']")
|
||||
return nil if node.empty?
|
||||
|
||||
code << node.text.gsub(/^/m, '# ')
|
||||
code << "\nclass #{name}\n\n"
|
||||
code << "\nmodule #{name}\n\n"
|
||||
|
||||
parse_html_method(doc, code)
|
||||
|
||||
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
|
||||
end
|
||||
|
||||
@@ -288,15 +273,7 @@ class DocsetGenerator
|
||||
return code
|
||||
end
|
||||
|
||||
def parse_html_reference(name, doc)
|
||||
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
|
||||
|
||||
def parse_html_reference(name, doc, code)
|
||||
if node = doc.xpath("//section/a[@title='Functions']")
|
||||
parse_html_function(node, code)
|
||||
end
|
||||
@@ -311,12 +288,20 @@ class DocsetGenerator
|
||||
doc = Nokogiri::HTML(data)
|
||||
title = doc.xpath('/html/head/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$/)
|
||||
parse_html_class(md[1].strip, doc)
|
||||
parse_html_class(md[1].strip, doc, code)
|
||||
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$/)
|
||||
parse_html_reference(md[1].strip, doc)
|
||||
parse_html_reference(md[1].strip, doc, code)
|
||||
end
|
||||
else
|
||||
nil
|
||||
@@ -329,23 +314,9 @@ class DocsetGenerator
|
||||
return nil
|
||||
end
|
||||
data = File.read(path)
|
||||
data.gsub!(/\s*Class:/, 'Protocol:')
|
||||
data.gsub!(/\s*Module:/, 'Protocol:')
|
||||
|
||||
doc = Nokogiri::HTML(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 }
|
||||
File.open(path, "w") { |io| io.print data }
|
||||
end
|
||||
|
||||
def initialize(outpath, paths)
|
||||
|
||||
Reference in New Issue
Block a user