Files
RubyMotion/doc/docset_link.rb
Watson 2954d3d9ce should not replaced by part of string of large class name
we have AVAsset and AVAssetExportSessionStatusCancelled.

The following replace has been done:
AVAssetExportSessionStatusCancelled -> <a href…>AVAsset</a>ExportSessionStatusCancelled
2012-11-08 17:48:46 +09:00

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