diff --git a/assets/javascripts/templates/pages/about_tmpl.coffee b/assets/javascripts/templates/pages/about_tmpl.coffee index 093b5346..ed1ad831 100644 --- a/assets/javascripts/templates/pages/about_tmpl.coffee +++ b/assets/javascripts/templates/pages/about_tmpl.coffee @@ -306,6 +306,11 @@ credits = [ '2012-2018 Scott Chacon and others', 'MIT', 'https://raw.githubusercontent.com/git/git-scm.com/master/MIT-LICENSE.txt' + ], [ + '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..6ac3e7b3 --- /dev/null +++ b/lib/docs/filters/gnu_cobol/clean_html.rb @@ -0,0 +1,74 @@ +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 horizontal lines + css('hr').remove + + # Remove acronym tags but keep the content + css('acronym').each {|node| node.name = 'span'} + + # Remove everything after Appendix B + # This includes the license text, the document changelog, the compiler changelog and the footnote + current_element = at_css('a[name="Appendix-C-_002d-GNU-Free-Documentation-License"]').previous + until current_element.nil? + next_element = current_element.next + current_element.remove + current_element = next_element + end + + # Make headers bigger + css('h4').each {|node| node.name = 'h3'} + css('h3.unnumberedsec').each {|node| node.name = 'h2'} + + # Remove the newlines + # All paragraphs are inside
tags already anyways
+ css('br').remove
+
+ # The original document contains sub-headers surrounded by equal signs
+ # Convert those to actual header elements
+ css('div[align="center"]').each do |node|
+ if node.content.include?('=' * 50)
+ previous = node.previous_element
+ if !previous.nil? && previous.name == 'div' && previous['align'] == 'center'
+ previous.name = 'h4'
+ end
+
+ node.remove
+ end
+ end
+
+ # Remove align="center" attributes
+ css('[align="center"]').remove_attribute('align')
+
+ # Convert tt tags into inline code blocks and remove any surrounding quotes
+ css('tt').each do |node|
+ node.name = 'code'
+
+ previous_node = node.previous
+ if !previous_node.nil? && previous_node.text?
+ previous_node.content = previous_node.content.sub(/([^"]?")\Z/, '')
+ end
+
+ next_node = node.next
+ if !next_node.nil? && next_node.text?
+ next_node.content = next_node.content.sub(/\A("[^"]?)/, '')
+ 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..9965359d
--- /dev/null
+++ b/lib/docs/scrapers/gnu_cobol.rb
@@ -0,0 +1,26 @@
+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 © 2000, 2001, 2002, 2007, 2008 Free Software Foundation, Inc.
+ Licensed under the GNU Free Documentation License.
+ HTML
+
+ def get_latest_version(opts)
+ doc = fetch_doc('https://open-cobol.sourceforge.io/HTML/gnucobpg.html', opts)
+ title = doc.at_css('h1').content
+ title.scan(/([0-9.]+)/)[0][0]
+ end
+ end
+end
diff --git a/public/icons/docs/gnu_cobol/16.png b/public/icons/docs/gnu_cobol/16.png
new file mode 100644
index 00000000..24a558f1
Binary files /dev/null and b/public/icons/docs/gnu_cobol/16.png differ
diff --git a/public/icons/docs/gnu_cobol/16@2x.png b/public/icons/docs/gnu_cobol/16@2x.png
new file mode 100644
index 00000000..b87c38a4
Binary files /dev/null and b/public/icons/docs/gnu_cobol/16@2x.png differ
diff --git a/public/icons/docs/gnu_cobol/SOURCE b/public/icons/docs/gnu_cobol/SOURCE
new file mode 100644
index 00000000..9aa7d9a2
--- /dev/null
+++ b/public/icons/docs/gnu_cobol/SOURCE
@@ -0,0 +1 @@
+https://sourceforge.net/p/open-cobol/icon