| @@ -0,0 +1,65 @@ |
| 1 | +module Docs |
| 2 | + class Ocaml |
| 3 | + class EntriesFilter < Docs::EntriesFilter |
| 4 | + def get_name |
| 5 | + title = context[:html_title].gsub(/\u00A0/, " ") |
| 6 | + title = title.split.join(" ").strip |
| 7 | + title.gsub!(/^Chapter /, "") |
| 8 | + |
| 9 | + # Move preface at the beginning |
| 10 | + title.gsub!(/^(Contents)/, '00.1 \1') |
| 11 | + title.gsub!(/^(Foreword)/, '00.2 \1') |
| 12 | + |
| 13 | + # Pad chapter numbers with zeros to sort lexicographically |
| 14 | + title.gsub!(/(^\d[\. ])/, '0\1') |
| 15 | + title.gsub!(/(?<ma>^\d+\.)(?<mb>\d[\. ])/, '\k<ma>0\k<mb>') |
| 16 | + |
| 17 | + # Add dot between chapter number and title |
| 18 | + title.gsub!(/(^[\d.]+)/, '\1. ') |
| 19 | + |
| 20 | + title |
| 21 | + end |
| 22 | + |
| 23 | + def get_type |
| 24 | + if slug.start_with?('libref') |
| 25 | + if slug.start_with?('libref/index_') |
| 26 | + 'Indexes' |
| 27 | + else |
| 28 | + 'Library reference' |
| 29 | + end |
| 30 | + else |
| 31 | + 'Documentation' |
| 32 | + end |
| 33 | + end |
| 34 | + |
| 35 | + def additional_entries |
| 36 | + entries = [] |
| 37 | + |
| 38 | + module_node = css('h1').at_css('span') |
| 39 | + |
| 40 | + css('pre').each do |node| |
| 41 | + next unless span = node.at_css('span') |
| 42 | + if span['id'].nil? |
| 43 | + next |
| 44 | + elsif span['id'].start_with?('VAL') |
| 45 | + entry_type = 'Values' |
| 46 | + elsif span['id'].start_with?('MODULE') |
| 47 | + entry_type = 'Modules' |
| 48 | + elsif span['id'].start_with?('EXCEPTION') |
| 49 | + entry_type = 'Exceptions' |
| 50 | + else |
| 51 | + next |
| 52 | + end |
| 53 | + |
| 54 | + name = span.content |
| 55 | + if not module_node.nil? |
| 56 | + name = "#{name} [#{module_node.content}]" |
| 57 | + end |
| 58 | + entries << [name, span['id'], entry_type] |
| 59 | + end |
| 60 | + |
| 61 | + entries |
| 62 | + end |
| 63 | + end |
| 64 | + end |
| 65 | +end |