diff --git a/assets/javascripts/templates/pages/about_tmpl.coffee b/assets/javascripts/templates/pages/about_tmpl.coffee index c3c0fdec..5fc27d3c 100644 --- a/assets/javascripts/templates/pages/about_tmpl.coffee +++ b/assets/javascripts/templates/pages/about_tmpl.coffee @@ -721,6 +721,11 @@ credits = [ '2018 HashiCorp', 'MPL', 'https://raw.githubusercontent.com/hashicorp/terraform-website/master/LICENSE.md' + ], [ + 'Trio', + '2017 Nathaniel J. Smith', + 'MIT', + 'https://raw.githubusercontent.com/python-trio/trio/master/LICENSE.MIT' ], [ 'Twig', '2009-2018 The Twig Team', diff --git a/lib/docs/filters/trio/clean_html.rb b/lib/docs/filters/trio/clean_html.rb new file mode 100644 index 00000000..00919535 --- /dev/null +++ b/lib/docs/filters/trio/clean_html.rb @@ -0,0 +1,58 @@ +module Docs + class Trio + class CleanHtmlFilter < Filter + def call + @doc = at_css('div[role="main"]') + + css('.section, [itemprop=articleBody]').each do |node| + node.replace node.children + end + + css('.headerlink').remove + + css('dt').each do |node| + node.name = 'h3' + + if node.parent.classes.include? 'field-list' + node.name = 'h4' + node['style'] = 'margin: 0' + + if node.text == 'Parameters' or node.text == 'Raises' + node.next_element.css('strong').each do |n| + n.name = 'code' + end + end + else + code = doc.document.create_element 'code' + + if em = node.at_css('.property') + code.inner_html = "#{em.text.strip} " + em.remove + end + + code.inner_html += node.inner_text.strip + node.inner_html = code + end + end + + css('pre').each do |node| + node.content = node.content.strip + + classes = node.parent.parent.classes + if classes.include? 'highlight-python3' + node['data-language'] = 'python' + end + + node.parent.parent.replace(node) + end + + css('.admonition').each do |node| + node.name = 'blockquote' + node.at_css('.admonition-title').name = 'h4' + end + + doc + end + end + end +end diff --git a/lib/docs/filters/trio/entries.rb b/lib/docs/filters/trio/entries.rb new file mode 100644 index 00000000..7c6aa76b --- /dev/null +++ b/lib/docs/filters/trio/entries.rb @@ -0,0 +1,48 @@ +module Docs + class Trio + class EntriesFilter < Docs::EntriesFilter + def get_name + at_css('h1').text[0...-1] + end + + def get_type + at_css('h1').text[0...-1] + end + + def additional_entries + css('.descname').each_with_object [] do |node, entries| + name = node.text + if node.previous.classes.include? 'descclassname' + name = node.previous.text + name + end + name.strip! + + dl = node.parent.parent + + if dl.classes.include?('attribute') \ + or dl.classes.include?('method') \ + or dl.classes.include?('data') + parent = dl.parent.previous_element + cls = '' + + if n = parent.at_css('.descclassname') + cls += n.text + end + + if n = parent.at_css('.descname') + if n.text == "The nursery interface" + cls += "Nursery." + else + cls += n.text + '.' + end + end + + name = cls + name + end + + entries << [name, node.parent['id']] + end + end + end + end +end diff --git a/lib/docs/scrapers/trio.rb b/lib/docs/scrapers/trio.rb new file mode 100644 index 00000000..b8719bea --- /dev/null +++ b/lib/docs/scrapers/trio.rb @@ -0,0 +1,31 @@ +module Docs + class Trio < UrlScraper + self.type = 'simple' + self.release = '0.12.1' + self.base_url = 'https://trio.readthedocs.io/en/v0.12.1/' + self.root_path = 'index.html' + self.links = { + home: 'https://trio.readthedocs.io/', + code: 'https://github.com/python-trio/trio' + } + + html_filters.push 'trio/entries', 'trio/clean_html' + + options[:only_patterns] = [ + /reference-core/, + /reference-io/, + /reference-testing/, + /reference-hazmat/, + ] + + options[:attribution] = <<-HTML + © 2017 Nathaniel J. Smith
+ Licensed under the MIT License. + HTML + + def get_latest_version(opts) + doc = fetch_doc('https://trio.readthedocs.io/en/stable/', opts) + doc.at_css('.rst-other-versions a[href^="/en/v"]').content[1..-1] + end + end +end diff --git a/public/icons/docs/trio/16.png b/public/icons/docs/trio/16.png new file mode 100644 index 00000000..f1fbc1fa Binary files /dev/null and b/public/icons/docs/trio/16.png differ diff --git a/public/icons/docs/trio/16@2x.png b/public/icons/docs/trio/16@2x.png new file mode 100644 index 00000000..afc88081 Binary files /dev/null and b/public/icons/docs/trio/16@2x.png differ diff --git a/public/icons/docs/trio/SOURCE b/public/icons/docs/trio/SOURCE new file mode 100644 index 00000000..52a2abea --- /dev/null +++ b/public/icons/docs/trio/SOURCE @@ -0,0 +1 @@ +https://github.com/python-trio/trio/blob/37de153f858e29df3a19db9fffcd0fb3f2308951/logo/logo-transparent-no-text.svg