From 1d56144a4b71a0c1de422914e4ed2c66f14194c8 Mon Sep 17 00:00:00 2001 From: Jasper van Merle Date: Sun, 29 Jul 2018 17:20:43 -0400 Subject: [PATCH] Add Bash documentation --- .../templates/pages/about_tmpl.coffee | 5 ++ assets/stylesheets/application-dark.css.scss | 1 + assets/stylesheets/application.css.scss | 1 + assets/stylesheets/pages/_bash.scss | 22 ++++++ lib/docs/filters/bash/clean_html.rb | 63 ++++++++++++++++++ lib/docs/filters/bash/entries.rb | 56 ++++++++++++++++ lib/docs/scrapers/bash.rb | 21 ++++++ public/icons/docs/bash/16.png | Bin 0 -> 1486 bytes public/icons/docs/bash/16@2x.png | Bin 0 -> 2210 bytes public/icons/docs/bash/SOURCE | 1 + 10 files changed, 170 insertions(+) create mode 100644 assets/stylesheets/pages/_bash.scss create mode 100644 lib/docs/filters/bash/clean_html.rb create mode 100644 lib/docs/filters/bash/entries.rb create mode 100644 lib/docs/scrapers/bash.rb create mode 100644 public/icons/docs/bash/16.png create mode 100644 public/icons/docs/bash/16@2x.png create mode 100644 public/icons/docs/bash/SOURCE diff --git a/assets/javascripts/templates/pages/about_tmpl.coffee b/assets/javascripts/templates/pages/about_tmpl.coffee index b3047573..88298882 100644 --- a/assets/javascripts/templates/pages/about_tmpl.coffee +++ b/assets/javascripts/templates/pages/about_tmpl.coffee @@ -115,6 +115,11 @@ credits = [ '2010-2016 Jeremy Ashkenas, DocumentCloud', 'MIT', 'https://raw.githubusercontent.com/jashkenas/backbone/master/LICENSE' + ], [ + 'Bash', + '2000, 2001, 2002, 2007, 2008 Free Software Foundation, Inc.', + 'GFDL', + 'https://www.gnu.org/licenses/fdl-1.3.en.html' ], [ 'Bluebird', '2013-2017 Petka Antonov', diff --git a/assets/stylesheets/application-dark.css.scss b/assets/stylesheets/application-dark.css.scss index 4500f90f..e0d85477 100644 --- a/assets/stylesheets/application-dark.css.scss +++ b/assets/stylesheets/application-dark.css.scss @@ -35,6 +35,7 @@ 'pages/angularjs', 'pages/apache', 'pages/async', + 'pages/bash', 'pages/bootstrap', 'pages/c', 'pages/cakephp', diff --git a/assets/stylesheets/application.css.scss b/assets/stylesheets/application.css.scss index f7321135..251d83e9 100644 --- a/assets/stylesheets/application.css.scss +++ b/assets/stylesheets/application.css.scss @@ -35,6 +35,7 @@ 'pages/angularjs', 'pages/apache', 'pages/async', + 'pages/bash', 'pages/bootstrap', 'pages/c', 'pages/cakephp', diff --git a/assets/stylesheets/pages/_bash.scss b/assets/stylesheets/pages/_bash.scss new file mode 100644 index 00000000..c22d0493 --- /dev/null +++ b/assets/stylesheets/pages/_bash.scss @@ -0,0 +1,22 @@ +._bash { + // The page title is always the first element on the page, but not always the same type of element + // The exception is the homepage, where the links element comes first + > *:first-child:not(._links) { + @extend h1; + @extend %lined-heading; + } + + dl > dt > code, + dl > dt > kbd { + @extend %note, %note-blue; + display: block; + padding: 1px 7px 2px 7px; + margin: 28px 0 14px 0; + font-weight: bold; + font-family: $baseFont; + } + + th[align=left] { + border-left: 1px solid #d8d8d8; + } +} diff --git a/lib/docs/filters/bash/clean_html.rb b/lib/docs/filters/bash/clean_html.rb new file mode 100644 index 00000000..d35bac63 --- /dev/null +++ b/lib/docs/filters/bash/clean_html.rb @@ -0,0 +1,63 @@ +module Docs + class Bash + class CleanHtmlFilter < Filter + def call + # Remove the navigation header and footer and the lines underneath and above it + at_css('.header + hr').remove + line_above = at_xpath('//div[@class="header"]/preceding::hr[1]') + line_above.remove unless line_above.nil? + css('.header').remove + + # Remove chapter and section numbers from title + title_node = at_css('h1, h2, h3, h4, h5, h6') + title_node.content = title_node.content.gsub(/(\d+\.?)+/, '').strip + + # Remove the "D. " from names like "D. Concept Index" and "D. Function Index" + title_node.content = title_node.content[3..-1] if title_node.content.start_with?("D. ") + + # Remove columns containing a single space from tables + # In the original reference they are used to add width between two columns + xpath('//td[text()=" " and not(descendant::*)]').remove + + # Add id's to additional entry nodes + css('dl > dt > code').each do |node| + # Only take the direct text (i.e. "
Hello World
" becomes "Hello") + node['id'] = node.xpath('text()').to_s.strip + end + + # Fix hashes of index entries so they link to the correct hash on the linked page + css('table[class^=index-] td[valign=top] > a').each do |node| + path = node['href'].split('#')[0] + hash = node.content + + # Fix the index entries linking to the Special Parameters page + # There are multiple index entries that should link to the same paragraph on that page + # Example: the documentation for "$!" is equal to the documentation for "!" + if path.downcase.include?('special-parameters') + if hash.size > 1 && hash[0] == '$' + hash = hash[1..-1] + end + end + + node['href'] = path + '#' + hash + end + + # Fix index table letter hashes (the "Jump to" hashes) + css('table[class^=index-] th > a').each do |node| + node['id'] = node['name'] + end + + # Remove the rows with a horizontal line in them from the index tables + css('td[colspan="4"]').remove + + # Remove additional text from menu entry and index entry cells + css('td[valign=top]').each do |node| + link = node.at_css('a') + node.children = link unless link.nil? + end + + doc + end + end + end +end diff --git a/lib/docs/filters/bash/entries.rb b/lib/docs/filters/bash/entries.rb new file mode 100644 index 00000000..3489020f --- /dev/null +++ b/lib/docs/filters/bash/entries.rb @@ -0,0 +1,56 @@ +module Docs + class Bash + class EntriesFilter < Docs::EntriesFilter + def get_name + name = at_css('hr + a + *').content.gsub(/(\d+\.?)+/, '') + + # Remove the "D. " from names like "D. Concept Index" and "D. Function Index" + name = name[3..-1] if name.start_with?('D. ') + + name + end + + def get_type + return 'Manual: Appendices' if name.start_with?('Appendix') + return 'Manual: Indexes' if at_css('a[rel=up]').content.include?("Index") + "Manual" + end + + def additional_entries + entry_type = { + "Function Index" => "Functions", + "Index of Shell Builtin Commands" => "Builtin Commands", + "Index of Shell Reserved Words" => "Reserved Words", + "Parameter and Variable Index" => "Parameters and Variables" + }[name] + + # Only extract additional entries from certain index pages + return [] if entry_type.nil? + + entries = [] + + css('table[class^=index-] td[valign=top] > a').each_slice(2) do |entry_node, section_node| + entry_name = entry_node.content + + page = section_node['href'].split('#')[0] + hash = entry_name + + # The Special Parameters page has multiple additional entries which should link to the same paragraph + # Example: the documentation for "$!" is equal to the documentation for "!" + if page == 'special-parameters' + if hash.size > 1 && hash[0] == '$' + hash = hash[1..-1] + end + end + + # Construct path to the page which the index links to + entry_path = '/html_node/' + page + '#' + hash + + entries << [entry_name, entry_path, entry_type] + end + + entries + end + end + end +end diff --git a/lib/docs/scrapers/bash.rb b/lib/docs/scrapers/bash.rb new file mode 100644 index 00000000..feb0ddce --- /dev/null +++ b/lib/docs/scrapers/bash.rb @@ -0,0 +1,21 @@ +module Docs + class Bash < UrlScraper + self.type = 'bash' + self.release = '4.4' + self.base_url = 'https://www.gnu.org/software/bash/manual' + self.root_path = '/html_node/index.html' + self.links = { + home: 'https://www.gnu.org/software/bash/', + code: 'http://git.savannah.gnu.org/cgit/bash.git' + } + + html_filters.push 'bash/entries', 'bash/clean_html' + + options[:only_patterns] = [/\/html_node\//] + + options[:attribution] = <<-HTML + Copyright © 2000, 2001, 2002, 2007, 2008 Free Software Foundation, Inc.
+ Licensed under the GNU Free Documentation License. + HTML + end +end diff --git a/public/icons/docs/bash/16.png b/public/icons/docs/bash/16.png new file mode 100644 index 0000000000000000000000000000000000000000..2dbb2ebd62ff6757d8d8a78bbca26f66569d590d GIT binary patch literal 1486 zcmaJ>drT8|9KTrs!(f9UikijqKpE-UyK60_H)^RAgh&Y@8!Xwd*WLk5?cMF}SPz1O zVPsKfaDr3D%-$i<2|gCsLZUpU#${**IHwtCK$jp;V3T&#-mVC^KgKS(`#tjce7>(w z?qE*#j_}a+p#T7cXJ(jkr8Oe(t_qgE8)rmZTGsJt1^jNhhnhOe$Go&nRcf-R0SNwsMC}M?i*cV6uQo0#1_0LBY9~;xIuE&Ff;)K5z{~;5>wP z=%J@c6_|6tRGKA0jWSVTLs1me>XfJ^Nv+bn3aSuP10y;ZMHC2%p$Mizz=a2rqOn8~ zmTO91h$Wr$Pzld77!12yE~QJYq}gH^)#-FFqJmW_g@jOWWfYGK3W|$eR4|d8jkPnp zou)D(jw4o{(q>`xrFBUT=H4I|0&Gn zl`$loOLBB6Ym)|76dMS|V5uyL^E8`B(|Z@Ym{UUYG*?11U~1}o*T7fu?G!<~xP*C* z*^FgU9FJ2rGSj4oBo(FIPGH7#1VvORVocwzM$t5l(YRHehHBBIByA$1(&`quCfZi& zBq@H8OFZME%W?yDa57S46Uo}&C5d#Fc7pR|WAf++)T5`uf$f^_Ic@oASc% z_}=z!Z5SMJH5FF*cBOh^yH^>iu>-xwMze$AZ6jDzYR!S#ipFIkilT+0U~h1y5@V~ z_Muzi!Ih0|RHXwaqx_yJTX4;l+RvEgJLkL;l`nNn>i{)8;sq2t+%tYvwOvAQJkF|s`PA?l6Cj z?XT*6|Hq1u@`v)M4f5-4t%Dy=4~!*NbRf@-?D^bUs(HO;{|B||a~VFua?fJ*h!2OF zw0#>-h~B@()JX}4Q;uC=Glc$Q*YjJtqkcNl*ycYo*7(FV6Yi&pQO}-VI;JmwTm2w3 z@r7&+j&Cv*ru>}ctL~x(N{__px~_`t&hSYEWr3_$CqENEQ$;KVKdXRP0iaa)&Bqwf=e6# literal 0 HcmV?d00001 diff --git a/public/icons/docs/bash/16@2x.png b/public/icons/docs/bash/16@2x.png new file mode 100644 index 0000000000000000000000000000000000000000..b9456a24e7323dd9b80e26d84db1e069061b8b20 GIT binary patch literal 2210 zcmaJ@eK=J49v@+iw@}_mr=g_GyD2l7q!}->8d+?tm)0?JFpp-=F>_>0+QwT#U8F=S zA?b=$d5cxvCM9(hm*sJVHfr;%P}(S6ceH8mAJ;w4bI$MO`FuX#x6dCZ&D+aeSIb-r zgTd%>JlH>Brd{& zA_X2YG2|=r^5e;(cyvC_c{kuBWhe!N5DEfP;USTPA!Xt|=`xi25JLv>6&5=r>*#i_3nMNehiDVL|c1S~6pVQ>t}#3?iVvjidXMOGyF+$Lqih*A(Ck_n{cl2(9R?*E4hg>77y?mP><7b#R=VgN38Szi5=H

r>Z&t^NWL zAC8sSed2Jr430>Gf+8NoVKZ?`6@oy(XVBSn2S>W2gNxf~j1Ur`D_s6xT-vJKWjhEFWn?xa79587Zemynd@7qESUnfYs(PQf{MB=z zuF54UlOZk-_rHd{a;0?8^7e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--git a/public/icons/docs/bash/SOURCE b/public/icons/docs/bash/SOURCE new file mode 100644 index 00000000..1baa51d0 --- /dev/null +++ b/public/icons/docs/bash/SOURCE @@ -0,0 +1 @@ +https://github.com/odb/official-bash-logo