Browse Source

Finish Graphite scraper

Thibaut Courouble 7 years ago
parent
commit
4e56a77012

+ 1 - 1
assets/javascripts/news.json

@@ -1,7 +1,7 @@
 [
   [
     "2018-07-29",
-    "New documentations: <a href=\"/bash/\">Bash</a> and <a href=\"/pygame/\">Pygame</a>"
+    "New documentations: <a href=\"/bash/\">Bash</a>, <a href=\"/graphite/\">Graphite</a> and <a href=\"/pygame/\">Pygame</a>"
   ], [
     "2018-07-08",
     "New documentations: <a href=\"/leaflet/\">Leaflet</a>, <a href=\"/terraform/\">Terraform</a> and <a href=\"/koa/\">Koa</a>"

+ 1 - 1
assets/javascripts/templates/pages/about_tmpl.coffee

@@ -297,7 +297,7 @@ credits = [
     'https://raw.githubusercontent.com/godotengine/godot/master/LICENSE.txt'
   ], [
     'Graphite',
-    '2008-2012 Chris Davis; 2011-2016 The Graphite Project',
+    '2008-2012 Chris Davis<br>&copy; 2011-2016 The Graphite Project',
     'Apache',
     'https://raw.githubusercontent.com/graphite-project/graphite-web/master/LICENSE'
   ], [

+ 1 - 0
assets/stylesheets/global/_icons.scss

@@ -94,6 +94,7 @@
 ._icon-marionette:before    { background-position: -6rem -5rem; }
 ._icon-jsdoc:before,
 ._icon-koa:before,
+._icon-graphite:before,
 ._icon-mongoose:before      { background-position: -7rem -5rem; }
 ._icon-phpunit:before       { background-position: -8rem -5rem; }
 ._icon-nokogiri:before      { background-position: -9rem -5rem; @extend %darkIconFix !optional; }

+ 1 - 20
assets/stylesheets/pages/_graphite.scss

@@ -1,26 +1,7 @@
 ._graphite {
   @extend %simple;
 
-  h1 {
-    @extend %lined-heading;
-  }
-
-  .section:first-child h1 {
-    margin-top: 0;
-  }
-
   dl > dt {
-    @extend %note, %note-blue;
-    padding: 1px 0.5rem 2px 0.5rem;
-    font-weight: bold;
-  }
-
-  dl.function > dt {
-    code {
-      font-weight: bold;
-    }
-    em {
-      font-style: normal;
-    }
+    @extend %block-label, %label-blue;
   }
 }

+ 12 - 3
lib/docs/filters/graphite/clean_html.rb

@@ -5,10 +5,19 @@ module Docs
         # Remove the paragraph icon after all headers
         css('.headerlink').remove
 
-        # Extract the text from function titles to get rid of the inconsistent styling
         css('dl.function > dt').each do |node|
-          node['data-name'] = node.at_css('.descname').inner_html.to_s
-          node.content = node.text
+          node.content = node.content
+        end
+
+        css('.section').each do |node|
+          node.before(node.children).remove
+        end
+
+        css('div[class*="highlight-"]').each do |node|
+          node.content = node.content.strip
+          node.name = 'pre'
+          node['data-language'] = node['class'][/highlight\-(\w+)/, 1]
+          node.remove_attribute('class')
         end
 
         doc

+ 3 - 1
lib/docs/filters/graphite/entries.rb

@@ -34,7 +34,9 @@ module Docs
 
         # Functions
         css('dl.function > dt').each do |node|
-          entries << [node['data-name'], node['id'], 'List of functions']
+          name = node.at_css('.descname').content
+          name << '()'
+          entries << [name, node['id'], 'Functions']
         end
 
         entries

+ 4 - 3
lib/docs/scrapers/graphite.rb

@@ -2,18 +2,19 @@ module Docs
   class Graphite < UrlScraper
     self.type = 'graphite'
     self.release = '1.1.3'
-    self.base_url = 'http://graphite.readthedocs.io/en/latest/'
+    self.base_url = 'https://graphite.readthedocs.io/en/latest/'
     self.links = {
       code: 'https://github.com/graphite-project/graphite-web'
     }
 
-    html_filters.push 'graphite/clean_html', 'graphite/entries'
+    html_filters.push 'graphite/entries', 'graphite/clean_html'
 
     options[:container] = '.document > div'
     options[:skip] = %w(releases.html who-is-using.html composer.html search.html py-modindex.html genindex.html)
 
     options[:attribution] = <<-HTML
-      &copy; 2008-2012 Chris Davis; 2011-2016 The Graphite Project<br>
+      &copy; 2008&ndash;2012 Chris Davis<br>
+      &copy; 2011&ndash;2016 The Graphite Project<br>
       Licensed under the Apache License, Version 2.0.
     HTML
   end