From f424256f6ca189fceda77e0e3d9e182cd7520f7e Mon Sep 17 00:00:00 2001 From: Phil Scherer Date: Thu, 1 Jun 2017 14:54:15 -0500 Subject: [PATCH] Add Falcon documentation --- lib/docs/filters/falcon/entries.rb | 50 +++++++++++++++++++++++++++ lib/docs/filters/sphinx/clean_html.rb | 3 +- lib/docs/scrapers/falcon.rb | 27 +++++++++++++++ public/icons/docs/falcon/SOURCE | 1 + 4 files changed, 80 insertions(+), 1 deletion(-) create mode 100644 lib/docs/filters/falcon/entries.rb create mode 100644 lib/docs/scrapers/falcon.rb create mode 100644 public/icons/docs/falcon/SOURCE diff --git a/lib/docs/filters/falcon/entries.rb b/lib/docs/filters/falcon/entries.rb new file mode 100644 index 00000000..dc737d87 --- /dev/null +++ b/lib/docs/filters/falcon/entries.rb @@ -0,0 +1,50 @@ +module Docs + class Falcon + class EntriesFilter < Docs::EntriesFilter + def get_name + name = at_css('h1').content.strip + name.remove! "\u{00B6}" + name + end + + def get_type + case slug.split('/').first + when 'community' + 'Community Guide' + when 'user' + 'User Guide' + when 'api' + 'Classes and Functions' + else + 'Other' + end + end + + def additional_entries + entries = [] + + css('.class').each do |node| + class_name = node.at_css('dt > .descname').content + class_id = node.at_css('dt[id]')['id'] + entries << [class_name, class_id] + + node.css('.method').each do |n| + next unless n.at_css('dt[id]') + name = n.at_css('.descname').content + name = "#{class_name}.#{name}()" + id = n.at_css('dt[id]')['id'] + entries << [name, id] + end + end + + css('.function').each do |node| + name = "#{node.at_css('.descname').content}()" + id = node.at_css('dt[id]')['id'] + entries << [name, id] + end + + entries + end + end + end +end diff --git a/lib/docs/filters/sphinx/clean_html.rb b/lib/docs/filters/sphinx/clean_html.rb index 9775122c..020ab435 100644 --- a/lib/docs/filters/sphinx/clean_html.rb +++ b/lib/docs/filters/sphinx/clean_html.rb @@ -20,9 +20,10 @@ module Docs css('div[class*="highlight-"]', 'div[class*="hl-"]').each do |node| pre = node.at_css('pre') pre.content = pre.content - lang = node['class'][/highlight\-(\w+)/, 1] || node['class'][/hl\-(\w+)/, 1] + lang = node['class'][/code (\w+) highlight/, 1] || node['class'][/highlight\-(\w+)/, 1] || node['class'][/hl\-(\w+)/, 1] lang = 'php' if lang == 'ci' lang = 'markup' if lang == 'html+django' + lang = 'bash' if lang == 'bash' lang = 'python' if lang == 'default' || lang.start_with?('python') || lang.start_with?('ipython') pre['data-language'] = lang node.replace(pre) diff --git a/lib/docs/scrapers/falcon.rb b/lib/docs/scrapers/falcon.rb new file mode 100644 index 00000000..593e62b8 --- /dev/null +++ b/lib/docs/scrapers/falcon.rb @@ -0,0 +1,27 @@ +module Docs + class Falcon < UrlScraper + self.type = 'sphinx' + self.root_path = 'index.html' + self.links = { + home: 'https://falconframework.org/', + code: 'https://github.com/falconry/falcon' + } + + html_filters.push 'falcon/entries', 'sphinx/clean_html' + + options[:container] = '.body' + + options[:skip_patterns] = [/\Achanges/, /\A_modules/] + + options[:attribution] = <<-HTML + © 2016 Falcon Contributors
+ Licensed under the Apache 2 License. + HTML + + version '1.2.0' do + self.release = '1.2.0' + self.base_url = "https://falcon.readthedocs.io/en/#{self.version}/" + end + + end +end diff --git a/public/icons/docs/falcon/SOURCE b/public/icons/docs/falcon/SOURCE new file mode 100644 index 00000000..ec12aba9 --- /dev/null +++ b/public/icons/docs/falcon/SOURCE @@ -0,0 +1 @@ +https://github.com/falconry/falcon/blob/master/docs/_static/img/logo.jpg