History

Add documentation for OCaml

Antoine Pietri committed 6 years ago

Commit db0746c1 parent 4eb4bfe9 files · +3130 −2689Browse files

Showing the changes to lib/docs (3 of 9 files). Show all

Unified · Split

3 files
  1. lib/docs/filters/ocaml/clean_html.rb +13 −0
  2. lib/docs/filters/ocaml/entries.rb +65 −0
  3. lib/docs/scrapers/ocaml.rb +28 −0
lib/docs/filters/ocaml/clean_html.rb+13−0
@@ -0,0 +1,13 @@
1+module Docs
2+ class Ocaml
3+ class CleanHtmlFilter < Filter
4+ def call
5+ css('pre').each do |node|
6+ node['data-language'] = 'ocaml'
7+ end
8+
9+ doc
10+ end
11+ end
12+ end
13+end
lib/docs/filters/ocaml/entries.rb+65−0
@@ -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
lib/docs/scrapers/ocaml.rb+28−0
@@ -0,0 +1,28 @@
1+module Docs
2+ class Ocaml < FileScraper
3+ self.name = 'OCaml'
4+ self.type = 'ocaml'
5+ self.root_path = 'index.html'
6+ self.links = {
7+ home: 'https://ocaml.org/',
8+ code: 'https://github.com/ocaml/ocaml'
9+ }
10+
11+ html_filters.push 'ocaml/entries', 'ocaml/clean_html'
12+
13+ options[:skip] = %w(
14+ libref/index.html
15+ )
16+
17+ options[:skip_patterns] = [
18+ /\Acompilerlibref\//,
19+ /\Alibref\/type_/,
20+ /\Alibref\/Stdlib\.\w+\.html/,
21+ ]
22+
23+ options[:attribution] = <<-HTML
24+ &copy; INRIA 1995-2020.
25+ HTML
26+
27+ end
28+end

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t