From dac9b9b03cc31f82e66325fe442fce5b35344d7a Mon Sep 17 00:00:00 2001 From: Hugo Sarti Date: Mon, 4 May 2015 20:28:41 -0300 Subject: [PATCH] Add docs for Drupal --- assets/stylesheets/application.css.scss | 1 + assets/stylesheets/pages/_drupal.scss | 10 ++++ lib/docs/filters/drupal/clean_html.rb | 24 ++++++++ lib/docs/filters/drupal/entries.rb | 25 ++++++++ lib/docs/filters/drupal/internal_urls.rb | 12 ++++ lib/docs/filters/drupal/normalize_paths.rb | 11 ++++ lib/docs/scrapers/drupal.rb | 65 +++++++++++++++++++++ public/icons/docs/drupal/16.png | Bin 0 -> 704 bytes public/icons/docs/drupal/16@2x.png | Bin 0 -> 1776 bytes public/icons/docs/drupal/SOURCE | 1 + 10 files changed, 149 insertions(+) create mode 100644 assets/stylesheets/pages/_drupal.scss create mode 100644 lib/docs/filters/drupal/clean_html.rb create mode 100644 lib/docs/filters/drupal/entries.rb create mode 100644 lib/docs/filters/drupal/internal_urls.rb create mode 100644 lib/docs/filters/drupal/normalize_paths.rb create mode 100644 lib/docs/scrapers/drupal.rb create mode 100644 public/icons/docs/drupal/16.png create mode 100644 public/icons/docs/drupal/16@2x.png create mode 100644 public/icons/docs/drupal/SOURCE diff --git a/assets/stylesheets/application.css.scss b/assets/stylesheets/application.css.scss index cc8675d3..4a8f307f 100644 --- a/assets/stylesheets/application.css.scss +++ b/assets/stylesheets/application.css.scss @@ -37,6 +37,7 @@ 'pages/clojure', 'pages/coffeescript', 'pages/d3', + 'pages/drupal', 'pages/ember', 'pages/express', 'pages/git', diff --git a/assets/stylesheets/pages/_drupal.scss b/assets/stylesheets/pages/_drupal.scss new file mode 100644 index 00000000..d1aa236e --- /dev/null +++ b/assets/stylesheets/pages/_drupal.scss @@ -0,0 +1,10 @@ +._drupal { + h1#page-subtitle { + margin-top: 0; + @extend %lined-heading; + } + + h3 { @extend %block-heading; } + + .signature { @extend %note, %note-blue; } +} \ No newline at end of file diff --git a/lib/docs/filters/drupal/clean_html.rb b/lib/docs/filters/drupal/clean_html.rb new file mode 100644 index 00000000..f44214db --- /dev/null +++ b/lib/docs/filters/drupal/clean_html.rb @@ -0,0 +1,24 @@ +module Docs + class Drupal + class CleanHtmlFilter < Filter + def call + root_page? ? root : other + doc + end + + def root + doc.inner_html = ' ' + end + + def other + css('#page-title-tools', '.element-invisible', '.breadcrumb', '#sidebar-first', '#api-alternatives').remove + css('#aside', '#api-function-signature tr:not(.active)', '.comments').remove + # 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.inner_html + table.replace '
' + signature + '
' + end + end + end + end +end diff --git a/lib/docs/filters/drupal/entries.rb b/lib/docs/filters/drupal/entries.rb new file mode 100644 index 00000000..95fa5748 --- /dev/null +++ b/lib/docs/filters/drupal/entries.rb @@ -0,0 +1,25 @@ +module Docs + class Drupal + class EntriesFilter < Docs::EntriesFilter + + def get_name + name = css('#page-subtitle').first.content + name.remove! 'function ' + name + end + + def path + Drupal::fixUri(result[:path]) + end + + def get_type + type = css('dl[api-related-topics] dt') + type.first ? type.first.content : nil + end + + def include_default_entry? + !initial_page? + end + end + end +end diff --git a/lib/docs/filters/drupal/internal_urls.rb b/lib/docs/filters/drupal/internal_urls.rb new file mode 100644 index 00000000..bc3e7bb9 --- /dev/null +++ b/lib/docs/filters/drupal/internal_urls.rb @@ -0,0 +1,12 @@ +module Docs + class Drupal + class InternalUrlsFilter < Docs::InternalUrlsFilter + def internal_path_to(url) + url = index_url if url == root_url + path = effective_url.relative_path_to(url) + URL.new(path: Drupal::fixUri(path), query: url.query, fragment: url.fragment).to_s + end + end + end +end + diff --git a/lib/docs/filters/drupal/normalize_paths.rb b/lib/docs/filters/drupal/normalize_paths.rb new file mode 100644 index 00000000..61ad5608 --- /dev/null +++ b/lib/docs/filters/drupal/normalize_paths.rb @@ -0,0 +1,11 @@ +module Docs + class Drupal + class NormalizePathsFilter < Docs::NormalizePathsFilter + + def store_path + p = Drupal::fixUri(@path) + File.extname(p) != '.html' ? "#{p}.html" : p + end + end + end +end \ No newline at end of file diff --git a/lib/docs/scrapers/drupal.rb b/lib/docs/scrapers/drupal.rb new file mode 100644 index 00000000..054b44cd --- /dev/null +++ b/lib/docs/scrapers/drupal.rb @@ -0,0 +1,65 @@ +module Docs + class Drupal < UrlScraper + self.name = 'Drupal' + self.type = 'drupal' + self.version = '7.37' + self.base_url = 'https://api.drupal.org/api/drupal/' + self.initial_paths = %w( + groups + groups?page=1) + + html_filters.replace 'normalize_paths', 'drupal/normalize_paths' + html_filters.replace 'internal_urls', 'drupal/internal_urls' + + html_filters.push 'drupal/entries', 'drupal/clean_html', 'title' + + options[:container] = '#page' + options[:title] = false + options[:root_title] = 'Drupal - Open Source CMS | Drupal.org' + + options[:only_patterns] = [ + /\/group\/[^\/]+/, + /\/function\/[^\/]+/] + + options[:skip_link] = ->(link) { + begin + return unless q = URL.parse(link['href']).query + Hash[URI.decode_www_form(q)].has_key? "order" + rescue URI::InvalidURIError + false + end + } + + options[:skip] = %w( + 'modules-system-system.install/group/updates-7.x-extra/7', + 'modules-system-system.install/group/updates-6.x-to-7.x/7') + + options[:skip_patterns] = [ + /\/group\/updates\-7/, + /\/group\/updates\-6/, + /_update_[0-9]{4}/, # Skip update functions + /\/[4-6](\.[0-9])*$/, # Skip previous versions + /\/[8-9](\.[0-9])*$/, # Skip future versions + /\/function\/calls\//, # Skip function calls listings + /\/function\/implementations\//, # Skip hook implementation listings + /\.test\/function\// # Skip test files + ] + + options[:fix_urls] = ->(url) do + url.sub! /\/7$/, '' # Remove the version indicator from the current version + url + end + + options[:attribution] = <<-HTML + © 2000–2015 by the individual contributors.
+ Licensed under the Creative Commons License, Attribution-ShareAlike2.0.
+ Drupal is a registered trademark of Dries Buytaert. + HTML + + # Method used at several places to fix special characters at urls from api.drupal.org + def self.fixUri(path) + p = path.gsub /%21|!|%2b|%3b|%3a/i, '-' # !+;: + end + + end +end diff --git a/public/icons/docs/drupal/16.png b/public/icons/docs/drupal/16.png new file mode 100644 index 0000000000000000000000000000000000000000..f731b7d3ff74900e85d3ac0fb4cbb8f64b3f9560 GIT binary patch literal 704 zcmV;x0zdtUP)M?s9>M``&~-il000McNliru-vtC05d*u2+adq}0!>Lo zK~y-)oswBdlu;Olpa1_IXGv{HZ8T8SA`v4{qM(&7DxxSbr3kVNN-`}qiwL}k2tr6& zw7e)S@5-f(5;cNMZILXyXjH5b7euDg(HdtzU5q%6BL=;9=kT59d%yR5uz+IoDhmKe zSi^s*b(~LIB~5et$WBkR&TVZ2#?Mn_mPRCl{o-p-ku*&RMjlm zEt6p{I=a8yI-OqEV?qDEe++~G^`bbI#Fmp=Kg#&_&JV^! z>gBTbAx_mB5dnrJaM@v?GYUiEC>8s?0DwC!J>OQw7!ryb`gq;@6BKFwp(P2--+Q^A zo#;jGD1`91ePQvdYbSo&AV^*~SuX&_N78ZG>SP*AVR2OUgw65q#{g~@*e5})J;w7Z z(;+IV^?pSj0ahnC+<_UG`@GppaBW&PS*XQph?_p9h~W6ce%vwlE>n3d4st6tV3usuM4-wBf5uv zIQop^tip!^5ih2z0?JK6IH_z9O0_ryHx)jx2*y(Ga0kZ7|(9((Vrc*i)Q> zHmn6j3Bl>+;(?8rCv8})Q-o+V3{Nuuuz0000M?s9>M``&~-il000McNliru-vtC05F9U*=av8f27O6H zK~z}7y_b7XRQDCfKlk3paKA1mxGyL<1ie{4XO6@tX} z%yfg z^(0AIAyWxJn$(U9-*m47X_Uui`X;*KfR399oJmbMF2 z7Hy;aRO{3-FlyI6D|bA$d;N+tTUITKP-F=q;8ay7+Y4%`?HnA(sswh6O2>_jbk-l^ zqk}35zk>YTUaHCj&ZUaMMsZy)zb|RzYD>S{(RiZwmGKKo z#Ar6tSzp3G^IXL5fSS??GB9fAX$RiT%}80E6ck_tpx5T&Tx~CJ6xVaL#WI=hahum% zU}<}wBO4L{by6i*zc=^9U$!PaH~js2`ylyMUHtiSGYvhqdvA52K~K|uj{R&ipxqsY zZhRB7?P$uc*FT+Xb!s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