Browse Source

Add Drupal 8 documentation

Thibaut Courouble 9 năm trước cách đây
mục cha
commit
c8c5a47692

+ 2 - 0
assets/stylesheets/pages/_drupal.scss

@@ -1,4 +1,6 @@
 ._drupal {
   h3 { @extend %block-heading; }
   .signature { @extend %note, %note-blue; }
+
+  span.api-deprecated { @extend %label, %label-red; }
 }

+ 17 - 4
lib/docs/filters/drupal/clean_html.rb

@@ -11,13 +11,23 @@ module Docs
       end
 
       def other
-        css('.element-invisible', '#sidebar-first', '#api-alternatives', '#aside', '.comments', '.view-filters',
-            '#api-function-signature tr:not(.active)', '.ctools-collapsible-container', 'img[width="13"]').remove
+        css('.element-invisible',
+            '#sidebar-first',
+            '#api-alternatives',
+            '#aside',
+            '.comments',
+            '.view-filters',
+            '#api-function-signature tr:not(.active)',
+            '.ctools-collapsible-container',
+            'img[width="13"]',
+            'a:contains("Expanded class hierarchy")',
+            'a:contains("All classes that implement")'
+        ).remove
 
         at_css('#main').replace(at_css('.content'))
         at_css('#page-heading').replace(at_css('#page-subtitle'))
 
-        css('th.views-field > a', '.content', 'ins').each do |node|
+        css('th.views-field > a', '.content', 'ins', '.view', '.view-content', 'div.item-list').each do |node|
           node.before(node.children).remove
         end
 
@@ -26,11 +36,14 @@ module Docs
           node['data-language'] = 'php'
         end
 
-        # Replaces the signature table from api.drupal.org with a simple pre tag
         css('#api-function-signature').each do |table|
           signature = table.css('.signature').first.at_css('code').inner_html
           table.replace '<pre class="signature">' + signature + '</pre>'
         end
+
+        css('table[class]', 'tr[class]', 'td[class]', 'th[class]').each do |node|
+          node.remove_attribute('class')
+        end
       end
     end
   end

+ 15 - 4
lib/docs/filters/drupal/entries.rb

@@ -3,14 +3,25 @@ module Docs
     class EntriesFilter < Docs::EntriesFilter
       def get_name
         name = at_css('#page-subtitle').content
-        name.remove! %r{(abstract|public|static|protected|final|function|class|constant|interface|property|global)\s+}
+        name.remove! %r{(abstract|public|static|protected|private|final|function|class|constant|interface|property|global|trait)\s+}
         name
       end
 
       def get_type
-        links = css('.breadcrumb > a')
-        type = links.length > 1 ? links[1].content.strip : name
-        type.split(/[\.\-]/).first
+        if subpath =~ /Drupal!Core!([^!]+)!/ ||
+           subpath =~ /Drupal!Component!([^!]+)!/ ||
+           subpath =~ /core!modules!([^!\/]+)/ ||
+           subpath =~ /core!includes!([^!\/]+)/
+          $1.underscore
+        elsif subpath =~ /Drupal!Core/
+          'core'
+        elsif subpath =~ /Drupal!Component/
+          'component'
+        elsif subpath =~ /core!themes/
+          'themes'
+        else
+          css('.breadcrumb > a')[1].content
+        end
       end
 
       def include_default_entry?

+ 50 - 19
lib/docs/scrapers/drupal.rb

@@ -17,29 +17,23 @@ module Docs
     options[:skip_link] = ->(link) { link['href'] =~ /[\?&]order/ }
 
     options[:skip_patterns] = [
+      /test/i,
+      /_update_[0-9]{4}/,
       /\/group\/updates\-\d/,
-      /_update_[0-9]{4}/,               # Skip update functions
-      /\/class\/hierarchy\//,           # Skip class hierarchy listings
-      /\/function\/calls\//,            # Skip function calls listings
-      /\/function\/invokes\//,          # Skip function invokations listings
-      /\/function\/overrides\//,        # Skip function overrides listings
-      /\/function\/references\//,       # Skip function references listings
-      /\/function\/implementations\//,  # Skip hook implementation listings
-      /\/function\/theme_references\//, # Skip hook references listings
-      /\.test\//,                       # Skip test files
-      /_test\//,                        # Skip test files
-      /\.test\.module\//,               # Skip test files
-      /_test\.module\//,                # Skip test files
-      /_test_/,                         # Skip test files
-      /_test\./,                        # Skip test files
-      /tests/,
-      /testing/,
+      /interface\/implements/,
+      /\/(class|interface|trait)\/hierarchy\//,
+      /\/(class|interface|trait)\/uses\//,
+      /\/(class|interface|trait)\/references\//,
+      /\/(class|interface|trait)\/annotations\//,
+      /\/function\/calls\//,
+      /\/function\/invokes\//,
+      /\/function\/overrides\//,
+      /\/function\/references\//,
+      /\/function\/implementations\//,
+      /\/function\/theme_references\//,
       /upgrade/,
       /DRUPAL_ROOT/,
-      /simpletest/,
       /constant\/constants/,
-      /interface\/implements/,
-      /interface\/hierarchy/,
       /theme_invokes/
     ]
 
@@ -49,6 +43,43 @@ module Docs
       Drupal is a registered trademark of Dries Buytaert.
     HTML
 
+    version '8' do
+      self.release = '8.1.7'
+      self.root_path = '8.1.x'
+      self.initial_paths = %w(groups/8.1.x groups/8.1.x?page=1)
+
+      options[:only_patterns] = [
+        /\/class\/[^\/]+\/8\.1\.x\z/,
+        /\/group\/[^\/]+\/8\.1\.x\z/,
+        /\/function\/[^\/]+\/8\.1\.x\z/,
+        /\/constant\/[^\/]+\/8\.1\.x\z/,
+        /\/interface\/[^\/]+\/8\.1\.x\z/,
+        /\/property\/[^\/]+\/8\.1\.x\z/,
+        /\/global\/[^\/]+\/8\.1\.x\z/,
+        /\/trait\/[^\/]+\/8\.1\.x\z/,
+        /modules.*\/8\.1\.x\z/,
+        /includes.*\/8\.1\.x\z/,
+        /\A[\w\-\.]+\.php\/8\.1\.x\z/
+      ]
+
+      options[:skip] = %w(index.php/8.1.x update.php/8.1.x)
+
+      options[:skip_patterns] += [
+        /[^\w\-\.].*\.php\/8\.1\.x\z/,
+        /\!src\!/,
+        /migrate/,
+        /Assertion/,
+        /listing_page/,
+        /update_api/,
+        /vendor/,
+        /deprecated/,
+        /namespace/,
+        /\.yml/,
+        /Plugin/,
+        /\.theme\//
+      ]
+    end
+
     version '7' do
       self.release = '7.50'
       self.root_path = '7.x'