mirror of
https://github.com/zhigang1992/RubyMotion.git
synced 2026-03-29 17:18:57 +08:00
we have AVAsset and AVAssetExportSessionStatusCancelled. The following replace has been done: AVAssetExportSessionStatusCancelled -> <a href…>AVAsset</a>ExportSessionStatusCancelled
41 lines
1.0 KiB
Ruby
41 lines
1.0 KiB
Ruby
class DocsetGenerator
|
|
class Linker
|
|
require 'nokogiri'
|
|
require 'fileutils'
|
|
|
|
def get_module_list
|
|
files = Dir.glob(File.join(@dir_path, "*.html"))
|
|
files.map { |x| File.basename(x, ".html") }
|
|
end
|
|
|
|
def initialize(dir_path)
|
|
@dir_path = dir_path
|
|
@module_list = get_module_list
|
|
end
|
|
|
|
def run(file_path)
|
|
data = File.read(file_path)
|
|
doc = Nokogiri::HTML(data)
|
|
|
|
is_update = false
|
|
nodes = []
|
|
nodes.concat(doc.xpath(".//div[@class='inline']/p"))
|
|
nodes.concat(doc.xpath(".//div[@class='docstring']/div[@class='discussion']/p"))
|
|
nodes.each do |node|
|
|
text = node.text
|
|
node.text.scan(/([A-Z]\w*)/).uniq.each do |item|
|
|
word = item.first
|
|
if @module_list.include?(word)
|
|
text.gsub!(/\b#{word}\b/, "<a href='#{word}.html'>#{word}</a>")
|
|
is_update = true
|
|
end
|
|
end
|
|
node.inner_html = text
|
|
end
|
|
|
|
if is_update
|
|
File.open(file_path, "w") { |io| io.puts doc.to_html }
|
|
end
|
|
end
|
|
end
|
|
end |