[devdocsgjs/main: 503/1867] Add GnuCOBOL documentation




commit 14aa61a798799e33d7cc1fe8ba391ce7af3f43dd
Author: Jasper van Merle <jaspervmerle gmail com>
Date:   Tue Nov 6 21:17:18 2018 +0100

    Add GnuCOBOL documentation

 .../javascripts/templates/pages/about_tmpl.coffee  |  5 ++
 lib/docs/filters/gnu_cobol/clean_html.rb           | 56 ++++++++++++++++++++++
 lib/docs/filters/gnu_cobol/entries.rb              | 50 +++++++++++++++++++
 lib/docs/scrapers/gnu_cobol.rb                     | 20 ++++++++
 4 files changed, 131 insertions(+)
---
diff --git a/assets/javascripts/templates/pages/about_tmpl.coffee 
b/assets/javascripts/templates/pages/about_tmpl.coffee
index c7e5a414..e0ef245f 100644
--- a/assets/javascripts/templates/pages/about_tmpl.coffee
+++ b/assets/javascripts/templates/pages/about_tmpl.coffee
@@ -290,6 +290,11 @@ credits = [
     '2005-2018 Linus Torvalds and others',
     'GPLv2',
     'https://raw.githubusercontent.com/git/git/master/COPYING'
+  ], [
+    'GnuCOBOL',
+    'Free Software Foundation',
+    'GFDL',
+    'https://www.gnu.org/licenses/fdl-1.3.en.html'
   ], [
     'Go',
     'Google, Inc.',
diff --git a/lib/docs/filters/gnu_cobol/clean_html.rb b/lib/docs/filters/gnu_cobol/clean_html.rb
new file mode 100644
index 00000000..4e0d9ef2
--- /dev/null
+++ b/lib/docs/filters/gnu_cobol/clean_html.rb
@@ -0,0 +1,56 @@
+module Docs
+  class GnuCobol
+    class CleanHtmlFilter < Filter
+      def call
+        # Replace the title
+        at_css('.settitle').content = 'GnuCOBOL'
+
+        # Remove the Table of Contents
+        # It's huge and the DevDocs sidebar is basically a direct copy
+        css('.contents, .contents-heading').remove
+
+        # Remove the changelog
+        at_css('p').remove
+        at_css('ol').remove
+
+        # Remove everything after Appendix B
+        # This includes the license text, the document changelog, the compiler changelog and the footnote
+        start_element = at_css('a[name="Appendix-C-_002d-GNU-Free-Documentation-License"]').previous_element
+        next_element = start_element.next_element
+        until start_element.nil?
+          start_element.remove
+          start_element = next_element
+          next_element = start_element.nil? ? nil : start_element.next_element
+        end
+
+        # Make headers bigger
+        css('h4').each {|node| node.name = 'h3'}
+
+        # Remove the newlines
+        # All paragraphs are inside <p> tags already anyways
+        css('br').remove
+
+        # The original document contains sub-headers surrounded by equal signs
+        # Convert that to actual header elements
+        css('div[align="center"]').each do |node|
+          if node.content.include?('=' * 50)
+            node.replace('<hr>')
+          else
+            node.remove_attribute('align')
+            node.name = 'h4'
+          end
+        end
+
+        # Remove all hr's after h4's
+        css('h4').each do |node|
+          next_element = node.next_element
+          if !next_element.nil? && next_element.name == 'hr'
+            next_element.remove
+          end
+        end
+
+        doc
+      end
+    end
+  end
+end
diff --git a/lib/docs/filters/gnu_cobol/entries.rb b/lib/docs/filters/gnu_cobol/entries.rb
new file mode 100644
index 00000000..a11e2edd
--- /dev/null
+++ b/lib/docs/filters/gnu_cobol/entries.rb
@@ -0,0 +1,50 @@
+module Docs
+  class GnuCobol
+    class EntriesFilter < Docs::EntriesFilter
+      # The entire reference is one big page, so get_name and get_type are not necessary
+
+      def additional_entries
+        entries = []
+
+        css('.contents > ul > li:not(:last-child)').each do |node|
+          parent = node.at_css('a')
+
+          entries << create_entry(parent, parent)
+
+          node.css('ul a').each do |link|
+            entries << create_entry(parent, link)
+          end
+        end
+
+        entries.compact
+      end
+
+      def create_entry(parent_link, current_link)
+        name = current_link.content
+        id = current_link['href'][1..-1]
+        type = parent_link.content
+
+        # The navigation link don't actually navigate to the correct header
+        # Instead, it references an `a` tag above it
+        # The `a` tag it is referencing is removed by a filter further down the pipeline
+        # This adds the id to the correct header element
+        target_node = at_css("a[name='#{id}']")
+        target_node.next_element.next_element['id'] = id
+
+        if name.start_with?('Appendix')
+          type = 'Appendices'
+        end
+
+        # Everything after Appendix B is removed by the clean_html filter
+        ignored_names = [
+          'Appendix C - GNU Free Documentation License',
+          'Appendix D - Summary of Document Changes',
+          'Appendix E - Summary of Compiler Changes since 2009 and version v1-1',
+          'Index'
+        ]
+
+        ignored_names.include?(name) ? nil : [name, id, type]
+      end
+    end
+  end
+end
diff --git a/lib/docs/scrapers/gnu_cobol.rb b/lib/docs/scrapers/gnu_cobol.rb
new file mode 100644
index 00000000..75d939a9
--- /dev/null
+++ b/lib/docs/scrapers/gnu_cobol.rb
@@ -0,0 +1,20 @@
+module Docs
+  class GnuCobol < UrlScraper
+    self.name = 'GnuCOBOL'
+    self.slug = 'gnu_cobol'
+    self.type = 'simple'
+    self.release = '2.2'
+    self.base_url = 'https://open-cobol.sourceforge.io/HTML/gnucobpg.html'
+    self.links = {
+      home: 'https://sourceforge.net/projects/open-cobol/',
+      code: 'https://sourceforge.net/p/open-cobol/code/HEAD/tree/trunk/'
+    }
+
+    html_filters.push 'gnu_cobol/entries', 'gnu_cobol/clean_html'
+
+    options[:attribution] = <<-HTML
+      Copyright &copy; 2000, 2001, 2002, 2007, 2008 Free Software Foundation, Inc.<br>
+      Licensed under the GNU Free Documentation License.
+    HTML
+  end
+end


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]