101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
|
# File 'lib/sdoc/merge.rb', line 101
def merge_search_index
items = []
@indexes = {}
@directories.each_with_index do |dir, i|
name = @names[i]
url = @urls.empty? ? name : @urls[i]
filename = File.join dir, RDoc::Generator::SDoc::SEARCH_INDEX_FILE
data = open(filename).read.sub(/var search_data =\s*/, '')
subindex = JSON.parse(data, :max_nesting => 0)
@indexes[name] = subindex
searchIndex = subindex["index"]["searchIndex"]
longSearchIndex = subindex["index"]["longSearchIndex"]
subindex["index"]["info"].each_with_index do |info, j|
info[2] = url + '/' + info[2]
info[6] = i
items << {
:info => info,
:searchIndex => searchIndex[j],
:longSearchIndex => name + ' ' + longSearchIndex[j]
}
end
end
items.sort! do |a, b|
[a[:info][5], a[:info][0], a[:info][6], a[:info][1]] <=> [b[:info][5], b[:info][0], b[:info][6], b[:info][1]]
end
index = {
:searchIndex => items.map{|item| item[:searchIndex]},
:longSearchIndex => items.map{|item| item[:longSearchIndex]},
:info => items.map{|item| item[:info]}
}
search_data = {
:index => index,
:badges => @names
}
dst = File.join @op_dir, RDoc::Generator::SDoc::SEARCH_INDEX_FILE
FileUtils.mkdir_p File.dirname(dst)
File.open(dst, "w", 0644) do |f|
f.write('var search_data = '); f.write(search_data.to_json(:max_nesting => 0))
end
end
|