Procházet zdrojové kódy

Add documentation for OCaml

Antoine Pietri před 5 roky
rodič
revize
db0746c16e

+ 5 - 0
assets/javascripts/templates/pages/about_tmpl.coffee

@@ -541,6 +541,11 @@ credits = [
     '2005-2019 NumPy Developers',
     'BSD',
     'https://raw.githubusercontent.com/numpy/numpy/master/LICENSE.txt'
+  ], [
+    'OCaml',
+    '1995-2020 Inria',
+    'CC BY-SA',
+    'https://ocaml.org/docs/'
   ], [
     'Octave',
     '1996-2018 John W. Eaton',

Rozdílová data souboru nebyla zobrazena, protože soubor je příliš velký
+ 670 - 566
assets/javascripts/vendor/prism.js


+ 12 - 0
docs/file-scrapers.md

@@ -78,6 +78,18 @@ $GS = '/usr/local/opt/ghostscript/bin/gs';	# GhostScript
 
 ## NumPy
 
+## OCaml
+
+Download the HTML reference here:
+https://ocaml.org/releases/4.10/ocaml-4.10-refman-html.tar.gz
+and extract it as `/path/to/devdocs/docs/ocaml`:
+
+```sh
+cd /path/to/devdocs/docs
+wget https://ocaml.org/releases/4.10/ocaml-4.10-refman-html.tar.gz
+tar xf ocaml-4.10-refman-html.tar.gz --transform 's/htmlman/ocaml/'
+```
+
 ## OpenJDK
 
 ## Perl

+ 13 - 0
lib/docs/filters/ocaml/clean_html.rb

@@ -0,0 +1,13 @@
+module Docs
+  class Ocaml
+    class CleanHtmlFilter < Filter
+      def call
+        css('pre').each do |node|
+          node['data-language'] = 'ocaml'
+        end
+
+        doc
+      end
+    end
+  end
+end

+ 65 - 0
lib/docs/filters/ocaml/entries.rb

@@ -0,0 +1,65 @@
+module Docs
+  class Ocaml
+    class EntriesFilter < Docs::EntriesFilter
+      def get_name
+        title = context[:html_title].gsub(/\u00A0/, " ")
+        title = title.split.join(" ").strip
+        title.gsub!(/^Chapter /, "")
+
+        # Move preface at the beginning
+        title.gsub!(/^(Contents)/, '00.1 \1')
+        title.gsub!(/^(Foreword)/, '00.2 \1')
+
+        # Pad chapter numbers with zeros to sort lexicographically
+        title.gsub!(/(^\d[\. ])/, '0\1')
+        title.gsub!(/(?<ma>^\d+\.)(?<mb>\d[\. ])/, '\k<ma>0\k<mb>')
+
+        # Add dot between chapter number and title
+        title.gsub!(/(^[\d.]+)/, '\1. ')
+
+        title
+      end
+
+      def get_type
+        if slug.start_with?('libref')
+          if slug.start_with?('libref/index_')
+            'Indexes'
+          else
+            'Library reference'
+          end
+        else
+          'Documentation'
+        end
+      end
+
+      def additional_entries
+        entries = []
+
+        module_node = css('h1').at_css('span')
+
+        css('pre').each do |node|
+          next unless span = node.at_css('span')
+          if span['id'].nil?
+            next
+          elsif span['id'].start_with?('VAL')
+            entry_type = 'Values'
+          elsif span['id'].start_with?('MODULE')
+            entry_type = 'Modules'
+          elsif span['id'].start_with?('EXCEPTION')
+            entry_type = 'Exceptions'
+          else
+            next
+          end
+
+          name = span.content
+          if not module_node.nil?
+            name = "#{name} [#{module_node.content}]"
+          end
+          entries << [name, span['id'], entry_type]
+        end
+
+        entries
+      end
+    end
+  end
+end

+ 28 - 0
lib/docs/scrapers/ocaml.rb

@@ -0,0 +1,28 @@
+module Docs
+  class Ocaml < FileScraper
+    self.name = 'OCaml'
+    self.type = 'ocaml'
+    self.root_path = 'index.html'
+    self.links = {
+      home: 'https://ocaml.org/',
+      code: 'https://github.com/ocaml/ocaml'
+    }
+
+    html_filters.push 'ocaml/entries', 'ocaml/clean_html'
+
+    options[:skip] = %w(
+      libref/index.html
+    )
+
+    options[:skip_patterns] = [
+      /\Acompilerlibref\//,
+      /\Alibref\/type_/,
+      /\Alibref\/Stdlib\.\w+\.html/,
+    ]
+
+    options[:attribution] = <<-HTML
+      &copy; INRIA 1995-2020.
+    HTML
+
+  end
+end

binární
public/icons/docs/ocaml/16.png


binární
public/icons/docs/ocaml/16@2x.png


+ 2 - 0
public/icons/docs/ocaml/SOURCE

@@ -0,0 +1,2 @@
+https://ocaml.org/docs/logos.html
+https://github.com/ocaml/ocaml-logo/tree/master/Colour/Favicon

Některé soubory nejsou zobrazeny, neboť je v těchto rozdílových datech změněno mnoho souborů