From 4e56a77012091a6c11ad514af80a292d9cd50056 Mon Sep 17 00:00:00 2001 From: Thibaut Courouble Date: Sun, 29 Jul 2018 18:12:33 -0400 Subject: [PATCH] Finish Graphite scraper --- assets/javascripts/news.json | 2 +- .../templates/pages/about_tmpl.coffee | 2 +- assets/stylesheets/global/_icons.scss | 1 + assets/stylesheets/pages/_graphite.scss | 21 +------------------ lib/docs/filters/graphite/clean_html.rb | 15 ++++++++++--- lib/docs/filters/graphite/entries.rb | 4 +++- lib/docs/scrapers/graphite.rb | 7 ++++--- 7 files changed, 23 insertions(+), 29 deletions(-) diff --git a/assets/javascripts/news.json b/assets/javascripts/news.json index 875cef4f..435913f6 100644 --- a/assets/javascripts/news.json +++ b/assets/javascripts/news.json @@ -1,7 +1,7 @@ [ [ "2018-07-29", - "New documentations: Bash and Pygame" + "New documentations: Bash, Graphite and Pygame" ], [ "2018-07-08", "New documentations: Leaflet, Terraform and Koa" diff --git a/assets/javascripts/templates/pages/about_tmpl.coffee b/assets/javascripts/templates/pages/about_tmpl.coffee index a2c264db..60ed00c2 100644 --- a/assets/javascripts/templates/pages/about_tmpl.coffee +++ b/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
© 2011-2016 The Graphite Project', 'Apache', 'https://raw.githubusercontent.com/graphite-project/graphite-web/master/LICENSE' ], [ diff --git a/assets/stylesheets/global/_icons.scss b/assets/stylesheets/global/_icons.scss index 098f176b..5dfb1034 100644 --- a/assets/stylesheets/global/_icons.scss +++ b/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; } diff --git a/assets/stylesheets/pages/_graphite.scss b/assets/stylesheets/pages/_graphite.scss index 8522976c..341d581c 100644 --- a/assets/stylesheets/pages/_graphite.scss +++ b/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; } } diff --git a/lib/docs/filters/graphite/clean_html.rb b/lib/docs/filters/graphite/clean_html.rb index d820a299..783b788a 100644 --- a/lib/docs/filters/graphite/clean_html.rb +++ b/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 diff --git a/lib/docs/filters/graphite/entries.rb b/lib/docs/filters/graphite/entries.rb index d33f63c1..32d96ce6 100644 --- a/lib/docs/filters/graphite/entries.rb +++ b/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 diff --git a/lib/docs/scrapers/graphite.rb b/lib/docs/scrapers/graphite.rb index 31f39c3e..692fda33 100644 --- a/lib/docs/scrapers/graphite.rb +++ b/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 - © 2008-2012 Chris Davis; 2011-2016 The Graphite Project
+ © 2008–2012 Chris Davis
+ © 2011–2016 The Graphite Project
Licensed under the Apache License, Version 2.0. HTML end