Quellcode durchsuchen

Update Haskell documentation (8.0.1, 7.10.3)

Thibaut Courouble vor 9 Jahren
Ursprung
Commit
130009b053

+ 6 - 3
assets/stylesheets/pages/_haskell.scss

@@ -1,4 +1,4 @@
-._haskell {
+._haskell-api {
   > h2 { @extend %block-heading; }
   > h3 { @extend %block-label; }
   h4 { font-size: 1em; }
@@ -9,10 +9,13 @@
     white-space: normal;
     @extend %code;
   }
-  p.src { @extend %block-label, %label-blue; }
+  p.src {
+    font-size: .8125rem;
+    @extend %block-label, %label-blue;
+  }
   dt.src { white-space: normal; }
 
-  .top > .subs { margin-left: 2em; }
+  > .subs { margin-left: 2em; }
   .subs p.src { margin-top: 1em; }
 
   dt > code, .complexity, .version { @extend %label; }

+ 20 - 8
lib/docs/filters/haskell/clean_html.rb

@@ -2,17 +2,29 @@ module Docs
   class Haskell
     class CleanHtmlFilter < Filter
       def call
-        root_page? ? root : other
+        if root_page? || !result[:entries].empty?
+          subpath.start_with?('users_guide') ? guide : api
+          doc.inner_html = %(<div class="#{subpath.start_with?('users_guide') ? '_sphinx' : '_haskell-api'}">#{doc.inner_html}</div>)
+          doc.child.before(at_css('h1'))
+        end
+
         doc
       end
 
-      def root
-        css('#description', '#module-list').each do |node|
-          node.before(node.children).remove
-        end
+      def guide
+        css('#indices-and-tables + ul', '#indices-and-tables').remove
+
+        Docs::Sphinx::CleanHtmlFilter.new(doc, context, result).call
       end
 
-      def other
+      def api
+        if root_page?
+          css('#description', '#module-list').each do |node|
+            node.before(node.children).remove
+          end
+          return doc
+        end
+
         css('h1').each do |node|
           node.remove if node.content == 'Documentation'
         end
@@ -28,9 +40,9 @@ module Docs
           node.before(node.children).remove
         end
 
-        css('#synopsis').remove
+        css('#synopsis', '.selflink').remove
 
-        css('#interface', 'h2 code').each do |node|
+        css('#interface', 'h2 code', 'span.keyword', 'div.top', 'div.doc', 'code code', '.inst-left').each do |node|
           node.before(node.children).remove
         end
 

+ 11 - 2
lib/docs/filters/haskell/entries.rb

@@ -23,10 +23,18 @@ module Docs
         Data-ByteString-Builder-Prim.html)
 
       def get_name
-        at_css('#module-header .caption').content.strip
+        if subpath.start_with?('users_guide')
+          name = at_css('h1').content
+          name.remove! "\u{00B6}"
+          name
+        else
+          at_css('#module-header .caption').content
+        end
       end
 
       def get_type
+        return 'Guide' if subpath.start_with?('users_guide')
+
         %w(System.Posix System.Win32 Control.Monad).each do |type|
           return type if name.start_with?(type)
         end
@@ -41,6 +49,7 @@ module Docs
       ADD_SUB_ENTRIES_KEYWORDS = %w(class module newtype)
 
       def additional_entries
+        return [] if subpath.start_with?('users_guide')
         return [] if IGNORE_ENTRIES_PATHS.include?(subpath.split('/').last)
 
         css('#synopsis > ul > li').each_with_object [] do |node, entries|
@@ -66,7 +75,7 @@ module Docs
       end
 
       def include_default_entry?
-        at_css('#synopsis > ul > li')
+        subpath.start_with?('users_guide') || at_css('#synopsis > ul > li')
       end
     end
   end

+ 37 - 8
lib/docs/scrapers/haskell.rb

@@ -2,15 +2,17 @@ module Docs
   class Haskell < UrlScraper
     self.name = 'Haskell'
     self.type = 'haskell'
-    self.release = '7.10.3'
-    self.base_url = "https://downloads.haskell.org/~ghc/#{release}/docs/html/libraries/"
-    self.root_path = 'index.html'
+    self.root_path = 'users_guide/index.html'
+    self.initial_paths = %w(libraries/index.html)
 
     html_filters.push 'haskell/entries', 'haskell/clean_html'
 
-    options[:container] = '#content'
+    options[:container] = ->(filter) { filter.subpath.start_with?('users_guide') ? '.body' : '#content' }
 
+    options[:only_patterns] = [/\Alibraries\//, /\Ausers_guide\//]
     options[:skip_patterns] = [
+      /-notes/,
+      /editing-guide/,
       /src\//,
       /doc-index/,
       /haskell2010/,
@@ -26,10 +28,37 @@ module Docs
       /GHC-IO-Encoding-Types\.html\z/i,
       /System-Posix-Process-Internals\.html\z/i
     ]
+    options[:skip] = %w(
+      users_guide/license.html
+      users_guide/genindex.html
+      users_guide/search.html
+    )
 
-    options[:attribution] = <<-HTML
-      &copy; The University of Glasgow and others<br>
-      Licensed under a BSD-style license (see top of the page).
-    HTML
+    options[:attribution] = ->(filter) do
+      if filter.subpath.start_with?('users_guide')
+        <<-HTML
+          &copy; 2002&ndash;2007 The University Court of the University of Glasgow. All rights reserved.<br>
+          Licensed under the Glasgow Haskell Compiler License.
+        HTML
+      else
+        <<-HTML
+          &copy; The University of Glasgow and others<br>
+          Licensed under a BSD-style license (see top of the page).
+        HTML
+      end
+    end
+
+    version '8' do
+      self.release = '8.0.1'
+      self.base_url = "https://downloads.haskell.org/~ghc/#{release}/docs/html/"
+    end
+
+    version '7' do
+      self.release = '7.10.3'
+      self.base_url = "https://downloads.haskell.org/~ghc/#{release}/docs/html/"
+      self.root_path = 'libraries/index.html'
+
+      options[:only_patterns] = [/\Alibraries\//]
+    end
   end
 end