Skip to content

Commit 1d56144

Browse files
jmerleThibaut
authored andcommitted
Add Bash documentation
1 parent 34fe833 commit 1d56144

10 files changed

Lines changed: 170 additions & 0 deletions

File tree

assets/javascripts/templates/pages/about_tmpl.coffee

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -115,6 +115,11 @@ credits = [
115115
'2010-2016 Jeremy Ashkenas, DocumentCloud',
116116
'MIT',
117117
'https://raw.githubusercontent.com/jashkenas/backbone/master/LICENSE'
118+
], [
119+
'Bash',
120+
'2000, 2001, 2002, 2007, 2008 Free Software Foundation, Inc.',
121+
'GFDL',
122+
'https://www.gnu.org/licenses/fdl-1.3.en.html'
118123
], [
119124
'Bluebird',
120125
'2013-2017 Petka Antonov',

assets/stylesheets/application-dark.css.scss

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@
3535
'pages/angularjs',
3636
'pages/apache',
3737
'pages/async',
38+
'pages/bash',
3839
'pages/bootstrap',
3940
'pages/c',
4041
'pages/cakephp',

assets/stylesheets/application.css.scss

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@
3535
'pages/angularjs',
3636
'pages/apache',
3737
'pages/async',
38+
'pages/bash',
3839
'pages/bootstrap',
3940
'pages/c',
4041
'pages/cakephp',
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
._bash {
2+
// The page title is always the first element on the page, but not always the same type of element
3+
// The exception is the homepage, where the links element comes first
4+
> *:first-child:not(._links) {
5+
@extend h1;
6+
@extend %lined-heading;
7+
}
8+
9+
dl > dt > code,
10+
dl > dt > kbd {
11+
@extend %note, %note-blue;
12+
display: block;
13+
padding: 1px 7px 2px 7px;
14+
margin: 28px 0 14px 0;
15+
font-weight: bold;
16+
font-family: $baseFont;
17+
}
18+
19+
th[align=left] {
20+
border-left: 1px solid #d8d8d8;
21+
}
22+
}
Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
module Docs
2+
class Bash
3+
class CleanHtmlFilter < Filter
4+
def call
5+
# Remove the navigation header and footer and the lines underneath and above it
6+
at_css('.header + hr').remove
7+
line_above = at_xpath('//div[@class="header"]/preceding::hr[1]')
8+
line_above.remove unless line_above.nil?
9+
css('.header').remove
10+
11+
# Remove chapter and section numbers from title
12+
title_node = at_css('h1, h2, h3, h4, h5, h6')
13+
title_node.content = title_node.content.gsub(/(\d+\.?)+/, '').strip
14+
15+
# Remove the "D. " from names like "D. Concept Index" and "D. Function Index"
16+
title_node.content = title_node.content[3..-1] if title_node.content.start_with?("D. ")
17+
18+
# Remove columns containing a single space from tables
19+
# In the original reference they are used to add width between two columns
20+
xpath('//td[text()=" " and not(descendant::*)]').remove
21+
22+
# Add id's to additional entry nodes
23+
css('dl > dt > code').each do |node|
24+
# Only take the direct text (i.e. "<div>Hello <span>World</span></div>" becomes "Hello")
25+
node['id'] = node.xpath('text()').to_s.strip
26+
end
27+
28+
# Fix hashes of index entries so they link to the correct hash on the linked page
29+
css('table[class^=index-] td[valign=top] > a').each do |node|
30+
path = node['href'].split('#')[0]
31+
hash = node.content
32+
33+
# Fix the index entries linking to the Special Parameters page
34+
# There are multiple index entries that should link to the same paragraph on that page
35+
# Example: the documentation for "$!" is equal to the documentation for "!"
36+
if path.downcase.include?('special-parameters')
37+
if hash.size > 1 && hash[0] == '$'
38+
hash = hash[1..-1]
39+
end
40+
end
41+
42+
node['href'] = path + '#' + hash
43+
end
44+
45+
# Fix index table letter hashes (the "Jump to" hashes)
46+
css('table[class^=index-] th > a').each do |node|
47+
node['id'] = node['name']
48+
end
49+
50+
# Remove the rows with a horizontal line in them from the index tables
51+
css('td[colspan="4"]').remove
52+
53+
# Remove additional text from menu entry and index entry cells
54+
css('td[valign=top]').each do |node|
55+
link = node.at_css('a')
56+
node.children = link unless link.nil?
57+
end
58+
59+
doc
60+
end
61+
end
62+
end
63+
end

lib/docs/filters/bash/entries.rb

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
module Docs
2+
class Bash
3+
class EntriesFilter < Docs::EntriesFilter
4+
def get_name
5+
name = at_css('hr + a + *').content.gsub(/(\d+\.?)+/, '')
6+
7+
# Remove the "D. " from names like "D. Concept Index" and "D. Function Index"
8+
name = name[3..-1] if name.start_with?('D. ')
9+
10+
name
11+
end
12+
13+
def get_type
14+
return 'Manual: Appendices' if name.start_with?('Appendix')
15+
return 'Manual: Indexes' if at_css('a[rel=up]').content.include?("Index")
16+
"Manual"
17+
end
18+
19+
def additional_entries
20+
entry_type = {
21+
"Function Index" => "Functions",
22+
"Index of Shell Builtin Commands" => "Builtin Commands",
23+
"Index of Shell Reserved Words" => "Reserved Words",
24+
"Parameter and Variable Index" => "Parameters and Variables"
25+
}[name]
26+
27+
# Only extract additional entries from certain index pages
28+
return [] if entry_type.nil?
29+
30+
entries = []
31+
32+
css('table[class^=index-] td[valign=top] > a').each_slice(2) do |entry_node, section_node|
33+
entry_name = entry_node.content
34+
35+
page = section_node['href'].split('#')[0]
36+
hash = entry_name
37+
38+
# The Special Parameters page has multiple additional entries which should link to the same paragraph
39+
# Example: the documentation for "$!" is equal to the documentation for "!"
40+
if page == 'special-parameters'
41+
if hash.size > 1 && hash[0] == '$'
42+
hash = hash[1..-1]
43+
end
44+
end
45+
46+
# Construct path to the page which the index links to
47+
entry_path = '/html_node/' + page + '#' + hash
48+
49+
entries << [entry_name, entry_path, entry_type]
50+
end
51+
52+
entries
53+
end
54+
end
55+
end
56+
end

lib/docs/scrapers/bash.rb

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
module Docs
2+
class Bash < UrlScraper
3+
self.type = 'bash'
4+
self.release = '4.4'
5+
self.base_url = 'https://www.gnu.org/software/bash/manual'
6+
self.root_path = '/html_node/index.html'
7+
self.links = {
8+
home: 'https://www.gnu.org/software/bash/',
9+
code: 'http://git.savannah.gnu.org/cgit/bash.git'
10+
}
11+
12+
html_filters.push 'bash/entries', 'bash/clean_html'
13+
14+
options[:only_patterns] = [/\/html_node\//]
15+
16+
options[:attribution] = <<-HTML
17+
Copyright &copy; 2000, 2001, 2002, 2007, 2008 Free Software Foundation, Inc.<br>
18+
Licensed under the GNU Free Documentation License.
19+
HTML
20+
end
21+
end

public/icons/docs/bash/16.png

1.45 KB
Loading

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

2.16 KB
Loading

public/icons/docs/bash/SOURCE

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
https://github.com/odb/official-bash-logo

0 commit comments

Comments
 (0)