From c8c5a476921d092a98a63af4dd10c3a9769ee549 Mon Sep 17 00:00:00 2001 From: Thibaut Courouble Date: Sat, 23 Jul 2016 11:34:45 -0400 Subject: [PATCH] Add Drupal 8 documentation --- assets/stylesheets/pages/_drupal.scss | 2 + lib/docs/filters/drupal/clean_html.rb | 21 ++++++-- lib/docs/filters/drupal/entries.rb | 19 ++++++-- lib/docs/scrapers/drupal.rb | 69 +++++++++++++++++++-------- 4 files changed, 84 insertions(+), 27 deletions(-) diff --git a/assets/stylesheets/pages/_drupal.scss b/assets/stylesheets/pages/_drupal.scss index c865d362..405aa83c 100644 --- a/assets/stylesheets/pages/_drupal.scss +++ b/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; } } diff --git a/lib/docs/filters/drupal/clean_html.rb b/lib/docs/filters/drupal/clean_html.rb index dadddc40..41a7e350 100644 --- a/lib/docs/filters/drupal/clean_html.rb +++ b/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 '
' + signature + '
' end + + css('table[class]', 'tr[class]', 'td[class]', 'th[class]').each do |node| + node.remove_attribute('class') + end end end end diff --git a/lib/docs/filters/drupal/entries.rb b/lib/docs/filters/drupal/entries.rb index 867b5534..9da70441 100644 --- a/lib/docs/filters/drupal/entries.rb +++ b/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? diff --git a/lib/docs/scrapers/drupal.rb b/lib/docs/scrapers/drupal.rb index 09843d79..5710eb36 100644 --- a/lib/docs/scrapers/drupal.rb +++ b/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'