7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
|
# File 'lib/playgroundbook_renderer/glossary_generator.rb', line 7
def generate!(parsed_chapters, chapter_names, glossary)
glossary_plist = {
'Terms' => {}
}
glossary.each do |term, definition|
glossary_plist['Terms'][term] = { 'Definition' => definition }
escaped_term = URI.escape(term)
parsed_chapters.each_with_index do |chapter, i|
pages = chapter[:page_contents]
page_names = chapter[:page_names]
chapter_name = URI.escape(chapter_names[i])
pages.each_with_index do |page, j|
page_name = URI.escape(page_names[j])
unless page.scan("](glossary://#{escaped_term})").empty?
glossary_plist['Terms'][term].merge!({
'FirstUse' => {
'Title' => page_names[j],
'PageReference' => "#{chapter_name}/#{page_name}",
}
})
break
end
end
break unless glossary_plist['Terms'][term]['FirstUse'].empty?
end
end
File.open(glossary_file_name, 'w') do |file|
file.write(glossary_plist.to_plist)
end
end
|