History

Add GnuCOBOL documentation

Jasper van Merle committed 8 years ago

Commit 14aa61a1 parent e7d7a144 files · +131 −0Browse files

Unified · Split

4 files
  1. assets/javascripts/templates/pages/about_tmpl.coffee +5 −0
  2. lib/docs/filters/gnu_cobol/clean_html.rb +56 −0
  3. lib/docs/filters/gnu_cobol/entries.rb +50 −0
  4. lib/docs/scrapers/gnu_cobol.rb +20 −0
assets/javascripts/templates/pages/about_tmpl.coffee+5−0
@@ -290,6 +290,11 @@ credits = [ · 289 unmodified lines
290 '2005-2018 Linus Torvalds and others',290 '2005-2018 Linus Torvalds and others',
291 'GPLv2',291 'GPLv2',
292 'https://raw.githubusercontent.com/git/git/master/COPYING'292 'https://raw.githubusercontent.com/git/git/master/COPYING'
293 ], [
294 'GnuCOBOL',
295 'Free Software Foundation',
296 'GFDL',
297 'https://www.gnu.org/licenses/fdl-1.3.en.html'
293 ], [298 ], [
294 'Go',299 'Go',
295 'Google, Inc.',300 'Google, Inc.',
lib/docs/filters/gnu_cobol/clean_html.rb+56−0
@@ -0,0 +1,56 @@
1module Docs
2 class GnuCobol
3 class CleanHtmlFilter < Filter
4 def call
5 # Replace the title
6 at_css('.settitle').content = 'GnuCOBOL'
7
8 # Remove the Table of Contents
9 # It's huge and the DevDocs sidebar is basically a direct copy
10 css('.contents, .contents-heading').remove
11
12 # Remove the changelog
13 at_css('p').remove
14 at_css('ol').remove
15
16 # Remove everything after Appendix B
17 # This includes the license text, the document changelog, the compiler changelog and the footnote
18 start_element = at_css('a[name="Appendix-C-_002d-GNU-Free-Documentation-License"]').previous_element
19 next_element = start_element.next_element
20 until start_element.nil?
21 start_element.remove
22 start_element = next_element
23 next_element = start_element.nil? ? nil : start_element.next_element
24 end
25
26 # Make headers bigger
27 css('h4').each {|node| node.name = 'h3'}
28
29 # Remove the newlines
30 # All paragraphs are inside <p> tags already anyways
31 css('br').remove
32
33 # The original document contains sub-headers surrounded by equal signs
34 # Convert that to actual header elements
35 css('div[align="center"]').each do |node|
36 if node.content.include?('=' * 50)
37 node.replace('<hr>')
38 else
39 node.remove_attribute('align')
40 node.name = 'h4'
41 end
42 end
43
44 # Remove all hr's after h4's
45 css('h4').each do |node|
46 next_element = node.next_element
47 if !next_element.nil? && next_element.name == 'hr'
48 next_element.remove
49 end
50 end
51
52 doc
53 end
54 end
55 end
56end
lib/docs/filters/gnu_cobol/entries.rb+50−0
@@ -0,0 +1,50 @@
1module Docs
2 class GnuCobol
3 class EntriesFilter < Docs::EntriesFilter
4 # The entire reference is one big page, so get_name and get_type are not necessary
5
6 def additional_entries
7 entries = []
8
9 css('.contents > ul > li:not(:last-child)').each do |node|
10 parent = node.at_css('a')
11
12 entries << create_entry(parent, parent)
13
14 node.css('ul a').each do |link|
15 entries << create_entry(parent, link)
16 end
17 end
18
19 entries.compact
20 end
21
22 def create_entry(parent_link, current_link)
23 name = current_link.content
24 id = current_link['href'][1..-1]
25 type = parent_link.content
26
27 # The navigation link don't actually navigate to the correct header
28 # Instead, it references an `a` tag above it
29 # The `a` tag it is referencing is removed by a filter further down the pipeline
30 # This adds the id to the correct header element
31 target_node = at_css("a[name='#{id}']")
32 target_node.next_element.next_element['id'] = id
33
34 if name.start_with?('Appendix')
35 type = 'Appendices'
36 end
37
38 # Everything after Appendix B is removed by the clean_html filter
39 ignored_names = [
40 'Appendix C - GNU Free Documentation License',
41 'Appendix D - Summary of Document Changes',
42 'Appendix E - Summary of Compiler Changes since 2009 and version v1-1',
43 'Index'
44 ]
45
46 ignored_names.include?(name) ? nil : [name, id, type]
47 end
48 end
49 end
50end
lib/docs/scrapers/gnu_cobol.rb+20−0
@@ -0,0 +1,20 @@
1module Docs
2 class GnuCobol < UrlScraper
3 self.name = 'GnuCOBOL'
4 self.slug = 'gnu_cobol'
5 self.type = 'simple'
6 self.release = '2.2'
7 self.base_url = 'https://open-cobol.sourceforge.io/HTML/gnucobpg.html'
8 self.links = {
9 home: 'https://sourceforge.net/projects/open-cobol/',
10 code: 'https://sourceforge.net/p/open-cobol/code/HEAD/tree/trunk/'
11 }
12
13 html_filters.push 'gnu_cobol/entries', 'gnu_cobol/clean_html'
14
15 options[:attribution] = <<-HTML
16 Copyright &copy; 2000, 2001, 2002, 2007, 2008 Free Software Foundation, Inc.<br>
17 Licensed under the GNU Free Documentation License.
18 HTML
19 end
20end