From db225290a3df35a223c51e24b04fb11cfbd5d9a4 Mon Sep 17 00:00:00 2001 From: Jasper van Merle Date: Thu, 12 Jul 2018 17:57:53 +0200 Subject: [PATCH] Add Graphite documentation --- .gitignore | 2 + .../templates/pages/about_tmpl.coffee | 5 +++ assets/stylesheets/application-dark.css.scss | 1 + assets/stylesheets/application.css.scss | 1 + assets/stylesheets/pages/_graphite.scss | 19 ++++++++ lib/docs/filters/graphite/clean_html.rb | 18 ++++++++ lib/docs/filters/graphite/entries.rb | 45 +++++++++++++++++++ lib/docs/scrapers/graphite.rb | 20 +++++++++ 8 files changed, 111 insertions(+) create mode 100644 assets/stylesheets/pages/_graphite.scss create mode 100644 lib/docs/filters/graphite/clean_html.rb create mode 100644 lib/docs/filters/graphite/entries.rb create mode 100644 lib/docs/scrapers/graphite.rb diff --git a/.gitignore b/.gitignore index 8b222826..9c439451 100644 --- a/.gitignore +++ b/.gitignore @@ -8,3 +8,5 @@ public/fonts public/docs/**/* !public/docs/docs.json !public/docs/**/index.json +.idea +log diff --git a/assets/javascripts/templates/pages/about_tmpl.coffee b/assets/javascripts/templates/pages/about_tmpl.coffee index fef9a024..69bc2b91 100644 --- a/assets/javascripts/templates/pages/about_tmpl.coffee +++ b/assets/javascripts/templates/pages/about_tmpl.coffee @@ -290,6 +290,11 @@ credits = [ '2014-2018 Juan Linietsky, Ariel Manzur, Godot Engine contributors', 'MIT', 'https://raw.githubusercontent.com/godotengine/godot/master/LICENSE.txt' + ], [ + 'Graphite', + '2008-2012 Chris Davis; 2011-2016 The Graphite Project', + 'Apache', + 'https://raw.githubusercontent.com/graphite-project/graphite-web/master/LICENSE' ], [ 'Grunt', 'GruntJS Team', diff --git a/assets/stylesheets/application-dark.css.scss b/assets/stylesheets/application-dark.css.scss index 4500f90f..dd7ebf77 100644 --- a/assets/stylesheets/application-dark.css.scss +++ b/assets/stylesheets/application-dark.css.scss @@ -54,6 +54,7 @@ 'pages/git', 'pages/github', 'pages/go', + 'pages/graphite', 'pages/haskell', 'pages/jekyll', 'pages/jquery', diff --git a/assets/stylesheets/application.css.scss b/assets/stylesheets/application.css.scss index f7321135..e22fa2c4 100644 --- a/assets/stylesheets/application.css.scss +++ b/assets/stylesheets/application.css.scss @@ -54,6 +54,7 @@ 'pages/git', 'pages/github', 'pages/go', + 'pages/graphite', 'pages/haskell', 'pages/jekyll', 'pages/jquery', diff --git a/assets/stylesheets/pages/_graphite.scss b/assets/stylesheets/pages/_graphite.scss new file mode 100644 index 00000000..af3e4984 --- /dev/null +++ b/assets/stylesheets/pages/_graphite.scss @@ -0,0 +1,19 @@ +._graphite { + @extend %simple; + + 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; + } + } +} diff --git a/lib/docs/filters/graphite/clean_html.rb b/lib/docs/filters/graphite/clean_html.rb new file mode 100644 index 00000000..d820a299 --- /dev/null +++ b/lib/docs/filters/graphite/clean_html.rb @@ -0,0 +1,18 @@ +module Docs + class Graphite + class CleanHtmlFilter < Filter + def call + # 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 + end + + doc + end + end + end +end diff --git a/lib/docs/filters/graphite/entries.rb b/lib/docs/filters/graphite/entries.rb new file mode 100644 index 00000000..b870db46 --- /dev/null +++ b/lib/docs/filters/graphite/entries.rb @@ -0,0 +1,45 @@ +module Docs + class Graphite + class EntriesFilter < Docs::EntriesFilter + def get_name + at_css('h1').children[0].to_s + end + + def get_type + get_name + end + + def additional_entries + entries = [] + + # Sections + css('.section').each do |node| + title = node.at_css('h2, h3') + + next if title.nil? + + # Move the id attribute to the title + # If this is excluded, the complete section will be highlighted in yellow when someone navigates to it + title['id'] = node['id'] + node.remove_attribute('id') + + entry = [title.children[0].to_s, title['id']] + + # Separate sub-sections in additional types + if title.name == 'h3' + entry.push title.xpath('parent::div[@class="section"]/preceding::h2').last.children[0].to_s + end + + entries << entry + end + + # Functions + css('dl.function > dt').each do |node| + entries << [node['data-name'], node['id'], 'List of functions'] + end + + entries + end + end + end +end diff --git a/lib/docs/scrapers/graphite.rb b/lib/docs/scrapers/graphite.rb new file mode 100644 index 00000000..1639179f --- /dev/null +++ b/lib/docs/scrapers/graphite.rb @@ -0,0 +1,20 @@ +module Docs + class Graphite < UrlScraper + self.type = 'graphite' + self.release = '1.1.3' + self.base_url = 'http://graphite.readthedocs.io/en/latest/' + self.links = { + code: 'https://github.com/graphite-project/graphite-web' + } + + html_filters.push 'graphite/clean_html', 'graphite/entries' + + options[:container] = '.document > div > .section' + options[:skip] = %w(releases.html who-is-using.html composer.html) + + options[:attribution] = <<-HTML + © 2008-2012 Chris Davis; 2011-2016 The Graphite Project
+ Licensed under the Apache License, Version 2.0. + HTML + end +end