move the enumeration from Class to Module

This commit is contained in:
Watson
2012-11-07 23:05:35 +09:00
parent 30e285960f
commit df2501e8f0
2 changed files with 48 additions and 14 deletions

View File

@@ -219,6 +219,7 @@ namespace :doc do
# generate .md files for frameworks
frameworks_hash = {}
all_protocols = []
all_enumerations = []
ruby_files = Dir.glob(File.join(DOCSET_RUBY_FILES_DIR, '*.rb'))
ruby_files.each do |x|
data = File.read(x)
@@ -242,19 +243,23 @@ namespace :doc do
# 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
protocols = data.scan(/^module\s+([^\s\n]+) # Protocol/).flatten
# get the list of enumerations
enumerations = data.scan(/^module\s+([^\s\n]+) # Enumeration/).flatten
# get the list of functions
functions = data.scan(/^def\s+([^\s\n\(]+)/).flatten
if !classes.empty? or !protocols.empty? or !functions.empty?
ary = (frameworks_hash[framework] ||= [[], [], []])
if !classes.empty? or !protocols.empty? or !functions.empty? or !enumerations.empty?
ary = (frameworks_hash[framework] ||= [[], [], [], []])
ary[0].concat(classes)
ary[1].concat(protocols)
ary[2].concat(functions)
ary[3].concat(enumerations)
end
all_protocols.concat(protocols)
all_enumerations.concat(enumerations)
end
frameworks_hash.each do |name, ary|
classes, protocols, functions = ary
classes, protocols, functions, enumerations = ary
next if name == 'AppKit'
File.open("#{OUTPUT_DIR}/#{name}.md", 'w') do |io|
io.puts "# @markup markdown"
@@ -278,6 +283,12 @@ namespace :doc do
io.puts "- [#{func}](top-level-namespace.html##{func}%3A-instance_method)"
end
end
unless enumerations.empty?
io.puts "\n## Enumerations"
enumerations.sort.each do |enum|
io.puts "- [#{enum}](#{enum}.html)"
end
end
end
end
@@ -289,10 +300,10 @@ namespace :doc do
sh "#{YARDOC} --title 'RubyMotion API Reference' -o ../#{OUTPUT_DIR} #{rubymotion_files} #{docset_files} - ../doc/RubyMotion.md #{frameworks}"
FileUtils.ln "#{OUTPUT_DIR}/_index.html", "#{OUTPUT_DIR}/index.html" unless File.exist?("#{OUTPUT_DIR}/index.html")
# update Protocol documents
all_protocols.each do |protocol|
protocol.strip!
DocsetGenerator.modify_protocol_document("#{OUTPUT_DIR}/#{protocol}.html")
# update Enumeration documents
all_enumerations.each do |enumeration|
enumeration.strip!
DocsetGenerator.modify_enumeration_document("#{OUTPUT_DIR}/#{enumeration}.html")
end
end

View File

@@ -139,8 +139,9 @@ class DocsetGenerator
return code
end
def parse_html_constant(doc, code = "", code_struct = "")
def parse_html_constant(doc, code_const = "", code_struct = "")
doc.xpath("//div[@id='Constants_section']").each do |node|
node_abstract = node.xpath("./p[@class='abstract']")
node_declaration = node.xpath("./pre[@class='declaration']")
node_termdef = node.xpath("./dl[@class='termdef']")
@@ -151,16 +152,24 @@ class DocsetGenerator
next
end
enum_name = (decl.match(/\}\s*([^\s]+);$/m).to_a)[1]
is_enum = true if enum_name.to_s.length > 0
if is_enum
code_const << "# #{sanitize(node_abstract[i].text)}\n"
code_const << "module #{enum_name} # Enumeration\n\n"
end
node_name = node_termdef[i].xpath("./dt")
node_description = node_termdef[i].xpath("./dd")
node_name.size.times do |i|
code << " # #{sanitize(node_description[i].text.capitalize)}\n"
code << " #{node_name[i].text} = nil\n"
code_const << " # #{sanitize(node_description[i].text.capitalize)}\n"
code_const << " #{node_name[i].text} = nil\n"
end
code_const << "end\n" if is_enum
end
end
return code
return code_const
end
def find_framework_path(doc)
@@ -173,12 +182,14 @@ class DocsetGenerator
end
def parse_html_class_property_common(doc, code)
code_const = ''
code_struct = ''
parse_html_property(doc, code)
parse_html_method(doc, code)
parse_html_constant(doc, code, code_struct)
parse_html_constant(doc, code_const, code_struct)
code << "end\n"
code << code_const
code << code_struct
return code
end
@@ -212,7 +223,7 @@ class DocsetGenerator
return nil if node.empty?
code << node.text.gsub(/^/m, '# ')
code << "\nmodule #{name}\n\n"
code << "\nmodule #{name} # Protocol\n\n"
parse_html_class_property_common(doc, code)
return code
@@ -378,6 +389,18 @@ class DocsetGenerator
File.open(path, "w") { |io| io.print data }
end
def self.modify_enumeration_document(path)
unless File.exists?(path)
warn "File not exists : #{path}"
return nil
end
data = File.read(path)
data.gsub!(/\s*Module:/, 'Enumeration:')
File.open(path, "w") { |io| io.print data }
end
def initialize(outpath, paths)
@input_paths = []
paths.each do |path|