Przeglądaj źródła

Add Bash documentation

Jasper van Merle 7 lat temu
rodzic
commit
1d56144a4b

+ 5 - 0
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',

+ 1 - 0
assets/stylesheets/application-dark.css.scss

@@ -35,6 +35,7 @@
         'pages/angularjs',
         'pages/apache',
         'pages/async',
+        'pages/bash',
         'pages/bootstrap',
         'pages/c',
         'pages/cakephp',

+ 1 - 0
assets/stylesheets/application.css.scss

@@ -35,6 +35,7 @@
         'pages/angularjs',
         'pages/apache',
         'pages/async',
+        'pages/bash',
         'pages/bootstrap',
         'pages/c',
         'pages/cakephp',

+ 22 - 0
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;
+  }
+}

+ 63 - 0
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. "<div>Hello <span>World</span></div>" 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

+ 56 - 0
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

+ 21 - 0
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 &copy; 2000, 2001, 2002, 2007, 2008 Free Software Foundation, Inc.<br>
+      Licensed under the GNU Free Documentation License.
+    HTML
+  end
+end

BIN
public/icons/docs/bash/16.png


BIN
public/icons/docs/bash/16@2x.png


+ 1 - 0
public/icons/docs/bash/SOURCE

@@ -0,0 +1 @@
+https://github.com/odb/official-bash-logo