From 1927f4e1960674b33177d361dcac681b3181f270 Mon Sep 17 00:00:00 2001 From: Phil Scherer Date: Fri, 15 Apr 2016 16:42:16 -0400 Subject: [PATCH] Add Pig Documentation --- assets/stylesheets/pages/_simple.scss | 1 + lib/docs/filters/pig/clean_html.rb | 26 ++++++++++++++++++ lib/docs/filters/pig/entries.rb | 33 +++++++++++++++++++++++ lib/docs/scrapers/pig.rb | 39 +++++++++++++++++++++++++++ 4 files changed, 99 insertions(+) create mode 100644 lib/docs/filters/pig/clean_html.rb create mode 100644 lib/docs/filters/pig/entries.rb create mode 100644 lib/docs/scrapers/pig.rb diff --git a/assets/stylesheets/pages/_simple.scss b/assets/stylesheets/pages/_simple.scss index 77745293..b5f97997 100644 --- a/assets/stylesheets/pages/_simple.scss +++ b/assets/stylesheets/pages/_simple.scss @@ -27,6 +27,7 @@ ._markdown, ._mocha, ._mongoose, +._pig, ._sinon, ._typescript, ._webpack { diff --git a/lib/docs/filters/pig/clean_html.rb b/lib/docs/filters/pig/clean_html.rb new file mode 100644 index 00000000..e3c66661 --- /dev/null +++ b/lib/docs/filters/pig/clean_html.rb @@ -0,0 +1,26 @@ +module Docs + class Pig + class CleanHtmlFilter < Filter + def call + @doc = at_css('#content') + + css('.pdflink').remove + + css('a[name]').each do |node| + node.next_element['id'] = node['name'] + end + + css('h2', 'h3').each do |node| + node.remove_attribute 'class' + end + + css('table').each do |node| + node.remove_attribute 'cellspacing' + node.remove_attribute 'cellpadding' + end + + doc + end + end + end +end diff --git a/lib/docs/filters/pig/entries.rb b/lib/docs/filters/pig/entries.rb new file mode 100644 index 00000000..d49bff47 --- /dev/null +++ b/lib/docs/filters/pig/entries.rb @@ -0,0 +1,33 @@ +module Docs + class Pig + class EntriesFilter < Docs::EntriesFilter + + def include_default_entry? + false + end + + def get_type + at_css('h1').content + end + + def additional_entries + case slug + when 'basic', 'cmds', 'func' + nodes = css('h3') + when 'cont' + nodes = css('h2, #macros + div > h3') + when 'test' + nodes = css('h2, #diagnostic-ops + div > h3') + when 'perf' + nodes = css('h2, #optimization-rules + div > h3, #specialized-joins + div > h3') + else + nodes = css('h2') + end + + nodes.each_with_object [] do |node, entries| + entries << [node.content, node['id'], get_type] + end + end + end + end +end diff --git a/lib/docs/scrapers/pig.rb b/lib/docs/scrapers/pig.rb new file mode 100644 index 00000000..bf9a13e5 --- /dev/null +++ b/lib/docs/scrapers/pig.rb @@ -0,0 +1,39 @@ +module Docs + class Pig < UrlScraper + self.name = 'Pig' + self.type = 'pig' + self.links = { + home: 'https://pig.apache.org/' + } + + html_filters.push 'pig/clean_html', 'pig/entries' + + options[:skip] = %w( pig-index.html ) + + options[:skip_patterns] = [ + /\Aapi/, + /\Ajdiff/ + ] + + options[:attribution] = <<-HTML + © 2007–2016 Apache Software Foundation
+ Licensed under the Apache Software License version 2.0. + HTML + + version '0.15.0' do + self.release = '0.15.0' + self.base_url = "http://pig.apache.org/docs/r#{release}/" + end + + version '0.14.0' do + self.release = '0.14.0' + self.base_url = "http://pig.apache.org/docs/r#{release}/" + end + + version '0.13.0' do + self.release = '0.13.0' + self.base_url = "http://pig.apache.org/docs/r#{release}/" + end + + end +end