History

Add docs for Drupal

Hugo Sarti committed 11 years ago

Commit dac9b9b1 parent 422d37710 files · +147 −-2Browse files

Unified · Split

10 files
  1. assets/stylesheets/application.css.scss +1 −0
  2. assets/stylesheets/pages/_drupal.scss +10 −0
  3. lib/docs/filters/drupal/clean_html.rb +24 −0
  4. lib/docs/filters/drupal/entries.rb +25 −0
  5. lib/docs/filters/drupal/internal_urls.rb +12 −0
  6. lib/docs/filters/drupal/normalize_paths.rb +11 −0
  7. lib/docs/scrapers/drupal.rb +65 −0
  8. public/icons/docs/drupal/16.png +0 −0
  9. public/icons/docs/drupal/16@2x.png +0 −0
  10. public/icons/docs/drupal/SOURCE +1 −0
assets/stylesheets/application.css.scss+1−0
@@ -37,6 +37,7 @@ · 36 unmodified lines
3737 'pages/clojure',
3838 'pages/coffeescript',
3939 'pages/d3',
40+ 'pages/drupal',
4041 'pages/ember',
4142 'pages/express',
4243 'pages/git',
assets/stylesheets/pages/_drupal.scss+10−0
@@ -0,0 +1,10 @@
1+._drupal {
2+ h1#page-subtitle {
3+ margin-top: 0;
4+ @extend %lined-heading;
5+ }
6+
7+ h3 { @extend %block-heading; }
8+
9+ .signature { @extend %note, %note-blue; }
10+}
lib/docs/filters/drupal/clean_html.rb+24−0
@@ -0,0 +1,24 @@
1+module Docs
2+ class Drupal
3+ class CleanHtmlFilter < Filter
4+ def call
5+ root_page? ? root : other
6+ doc
7+ end
8+
9+ def root
10+ doc.inner_html = ' '
11+ end
12+
13+ def other
14+ css('#page-title-tools', '.element-invisible', '.breadcrumb', '#sidebar-first', '#api-alternatives').remove
15+ css('#aside', '#api-function-signature tr:not(.active)', '.comments').remove
16+ # Replaces the signature table from api.drupal.org with a simple pre tag
17+ css('#api-function-signature').each do |table|
18+ signature = table.css('.signature').first.inner_html
19+ table.replace '<pre class="signature">' + signature + '</pre>'
20+ end
21+ end
22+ end
23+ end
24+end
lib/docs/filters/drupal/entries.rb+25−0
@@ -0,0 +1,25 @@
1+module Docs
2+ class Drupal
3+ class EntriesFilter < Docs::EntriesFilter
4+
5+ def get_name
6+ name = css('#page-subtitle').first.content
7+ name.remove! 'function '
8+ name
9+ end
10+
11+ def path
12+ Drupal::fixUri(result[:path])
13+ end
14+
15+ def get_type
16+ type = css('dl[api-related-topics] dt')
17+ type.first ? type.first.content : nil
18+ end
19+
20+ def include_default_entry?
21+ !initial_page?
22+ end
23+ end
24+ end
25+end
lib/docs/filters/drupal/internal_urls.rb+12−0
@@ -0,0 +1,12 @@
1+module Docs
2+ class Drupal
3+ class InternalUrlsFilter < Docs::InternalUrlsFilter
4+ def internal_path_to(url)
5+ url = index_url if url == root_url
6+ path = effective_url.relative_path_to(url)
7+ URL.new(path: Drupal::fixUri(path), query: url.query, fragment: url.fragment).to_s
8+ end
9+ end
10+ end
11+end
12+
lib/docs/filters/drupal/normalize_paths.rb+11−0
@@ -0,0 +1,11 @@
1+module Docs
2+ class Drupal
3+ class NormalizePathsFilter < Docs::NormalizePathsFilter
4+
5+ def store_path
6+ p = Drupal::fixUri(@path)
7+ File.extname(p) != '.html' ? "#{p}.html" : p
8+ end
9+ end
10+ end
11+end
lib/docs/scrapers/drupal.rb+65−0
@@ -0,0 +1,65 @@
1+module Docs
2+ class Drupal < UrlScraper
3+ self.name = 'Drupal'
4+ self.type = 'drupal'
5+ self.version = '7.37'
6+ self.base_url = 'https://api.drupal.org/api/drupal/'
7+ self.initial_paths = %w(
8+ groups
9+ groups?page=1)
10+
11+ html_filters.replace 'normalize_paths', 'drupal/normalize_paths'
12+ html_filters.replace 'internal_urls', 'drupal/internal_urls'
13+
14+ html_filters.push 'drupal/entries', 'drupal/clean_html', 'title'
15+
16+ options[:container] = '#page'
17+ options[:title] = false
18+ options[:root_title] = 'Drupal - Open Source CMS | Drupal.org'
19+
20+ options[:only_patterns] = [
21+ /\/group\/[^\/]+/,
22+ /\/function\/[^\/]+/]
23+
24+ options[:skip_link] = ->(link) {
25+ begin
26+ return unless q = URL.parse(link['href']).query
27+ Hash[URI.decode_www_form(q)].has_key? "order"
28+ rescue URI::InvalidURIError
29+ false
30+ end
31+ }
32+
33+ options[:skip] = %w(
34+ 'modules-system-system.install/group/updates-7.x-extra/7',
35+ 'modules-system-system.install/group/updates-6.x-to-7.x/7')
36+
37+ options[:skip_patterns] = [
38+ /\/group\/updates\-7/,
39+ /\/group\/updates\-6/,
40+ /_update_[0-9]{4}/, # Skip update functions
41+ /\/[4-6](\.[0-9])*$/, # Skip previous versions
42+ /\/[8-9](\.[0-9])*$/, # Skip future versions
43+ /\/function\/calls\//, # Skip function calls listings
44+ /\/function\/implementations\//, # Skip hook implementation listings
45+ /\.test\/function\// # Skip test files
46+ ]
47+
48+ options[:fix_urls] = ->(url) do
49+ url.sub! /\/7$/, '' # Remove the version indicator from the current version
50+ url
51+ end
52+
53+ options[:attribution] = <<-HTML
54+ &copy; 2000&ndash;2015 by the individual contributors.<br>
55+ Licensed under the Creative Commons License, Attribution-ShareAlike2.0.<br>
56+ Drupal is a registered trademark of Dries Buytaert.
57+ HTML
58+
59+ # Method used at several places to fix special characters at urls from api.drupal.org
60+ def self.fixUri(path)
61+ p = path.gsub /%21|!|%2b|%3b|%3a/i, '-' # !+;:
62+ end
63+
64+ end
65+end
public/icons/docs/drupal/16.png+0−0

Binary file not shown.

public/icons/docs/drupal/16@2x.png+0−0

Binary file not shown.

public/icons/docs/drupal/SOURCE+1−0
@@ -0,0 +1 @@
1+https://www.drupal.org/node/9068