From e1e4a626ffeac8febb18cce32ed9015e6fb9d2e4 Mon Sep 17 00:00:00 2001 From: Matthias Guenther Date: Thu, 28 Jan 2016 22:46:21 +0100 Subject: [PATCH] Add padrino support --- lib/docs/filters/padrino/clean_html.rb | 11 ++++++++ lib/docs/filters/padrino/entries.rb | 35 ++++++++++++++++++++++++++ lib/docs/scrapers/padrino.rb | 21 ++++++++++++++++ 3 files changed, 67 insertions(+) create mode 100644 lib/docs/filters/padrino/clean_html.rb create mode 100644 lib/docs/filters/padrino/entries.rb create mode 100644 lib/docs/scrapers/padrino.rb diff --git a/lib/docs/filters/padrino/clean_html.rb b/lib/docs/filters/padrino/clean_html.rb new file mode 100644 index 00000000..eb0751c6 --- /dev/null +++ b/lib/docs/filters/padrino/clean_html.rb @@ -0,0 +1,11 @@ +module Docs + class Padrino + class CleanHtmlFilter < Filter + def call + css('.summary_toggle').remove + css('.inheritanceTree').remove + at_css('#content') + end + end + end +end diff --git a/lib/docs/filters/padrino/entries.rb b/lib/docs/filters/padrino/entries.rb new file mode 100644 index 00000000..4d33b926 --- /dev/null +++ b/lib/docs/filters/padrino/entries.rb @@ -0,0 +1,35 @@ +module Docs + class Padrino + class EntriesFilter < Docs::EntriesFilter + def get_name + name = at_css('h1, h2').content + name.remove! 'Class: ' + name.remove! 'Module: ' + end + + def get_type + type = name.dup + type.remove! %r{#.+\z} + type.split('::')[0..2].join('::') + end + + def additional_entries + return [] if root_page? + require 'cgi' + + css('.summary_signature').inject [] do |entries, node| + + name = node.children[1].attributes['title'].value + name = CGI.unescape(name) + + unless name.start_with?('_') + name.prepend self.name + entries << [name, self.name.gsub('::','/').downcase.strip + node.children[1].attributes['href'].value.slice(/\#.*/)] unless entries.any? { |entry| entry[0] == name } + end + + entries + end + end + end + end +end diff --git a/lib/docs/scrapers/padrino.rb b/lib/docs/scrapers/padrino.rb new file mode 100644 index 00000000..49cbcbd7 --- /dev/null +++ b/lib/docs/scrapers/padrino.rb @@ -0,0 +1,21 @@ +module Docs + class Padrino < UrlScraper + self.name = 'padrino' + self.slug = 'padrino' + self.type = 'ruby' + self.version = 'master' + self.release = '0.13.2' + self.base_url = 'http://www.rubydoc.info/github/padrino/padrino-framework' + self.links = { + home: 'http://padrinorb.com/', + code: 'https://github.com/padrino/padrino-framework' + } + + html_filters.push 'padrino/clean_html', 'padrino/entries' + + options[:attribution] = <<-HTML + © Padrino contributors
+ Licensed under the Creative Commons Attribution License. + HTML + end +end