소스 검색

Merge pull request #1236 from seirl/ocaml

Add documentation for OCaml
Simon Legner 5 년 전
부모
커밋
9d1649233c

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

@@ -576,6 +576,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',

파일 크기가 너무 크기때문에 변경 상태를 표시하지 않습니다.
+ 670 - 566
assets/javascripts/vendor/prism.js


+ 12 - 0
docs/file-scrapers.md

@@ -108,6 +108,18 @@ $GS = '/usr/local/opt/ghostscript/bin/gs';	# GhostScript
 
 ## NumPy
 
+## OCaml
+
+Download from https://www.ocaml.org/docs/ the HTML reference:
+https://ocaml.org/releases/4.11/ocaml-4.11-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.11/ocaml-4.11-refman-html.tar.gz
+tar xf ocaml-4.10-refman-html.tar.gz --transform 's/htmlman/ocaml/'
+```
+
 ## OpenJDK
 
 https://packages.debian.org/sid/openjdk-11-doc

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

@@ -0,0 +1,35 @@
+module Docs
+  class Ocaml
+    class CleanHtmlFilter < Filter
+      def call
+
+        css('pre, .caml-example').each do |node|
+          span = node.at_css('span[id]')
+          node['id'] = span['id'] if span
+          node['data-type'] = "#{span.content} [#{at_css('h1').content}]" if span
+          node['data-language'] = 'ocaml'
+          node.name = 'pre'
+          node.content = node.content
+        end
+
+        css('.caml-input').each do |node|
+          node.content = '# ' + node.content.strip
+        end
+
+        css('.maintitle *[style]').each do |node|
+          node.remove_attribute 'style'
+        end
+
+        css('h1').each do |node|
+          node.content = node.content
+          table = node.ancestors('table.center')
+          table.first.before(node).remove if table.present?
+        end
+
+        css('.navbar').remove
+
+        doc
+      end
+    end
+  end
+end

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

@@ -0,0 +1,59 @@
+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 > span[id]').each do |span|
+          if 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
+          name += " [#{module_node.content}]" unless module_node.nil?
+          entries << [name, span['id'], entry_type]
+        end
+        entries
+      end
+    end
+  end
+end

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

@@ -0,0 +1,30 @@
+module Docs
+  class Ocaml < FileScraper
+    self.name = 'OCaml'
+    self.type = 'ocaml'
+    self.root_path = 'index.html'
+    self.release = '4.11'
+    self.base_url = "https://www.ocaml.org/releases/#{self.release}/htmlman/"
+    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
public/icons/docs/ocaml/16.png


BIN
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

이 변경점에서 너무 많은 파일들이 변경되어 몇몇 파일들은 표시되지 않았습니다.