History

Finish Erlang documentation

Thibaut Courouble committed 10 years ago

Commit d5219631 parent 8469d7114 files · +166 −75Browse files

Unified · Split

14 files
  1. assets/images/icons.png +0 −0
  2. assets/images/icons@2x.png +0 −0
  3. assets/javascripts/news.json +1 −1
  4. assets/javascripts/templates/pages/about_tmpl.coffee +5 −0
  5. assets/stylesheets/global/_icons.scss +1 −0
  6. assets/stylesheets/pages/_erlang.scss +7 −13
  7. lib/docs/filters/erlang/attribution.rb +0 −9
  8. lib/docs/filters/erlang/clean_html.rb +100 −4
  9. lib/docs/filters/erlang/entries.rb +20 −28
  10. lib/docs/filters/erlang/pre_clean_html.rb +10 −0
  11. lib/docs/scrapers/erlang.rb +25 −22
  12. public/icons/docs/erlang/16.png +0 −0
  13. public/icons/docs/erlang/16@2x.png +0 −0
  14. public/icons/docs/erlang/SOURCE +1 −2
assets/images/icons.png+0−0

Binary file not shown.

assets/images/icons@2x.png+0−0

Binary file not shown.

assets/javascripts/news.json+1−1
@@ -1,7 +1,7 @@
11 [
22 [
33 "2016-01-31",
4− "New documentation: <a href=\"/tcl_tk/\">Tcl/Tk</a>"
4+ "New documentations: <a href=\"/erlang/\">Erlang</a> and <a href=\"/tcl_tk/\">Tcl/Tk</a>"
55 ], [
66 "2016-01-24",
77 "&ldquo;Multi-version support&rdquo; has landed!\nClick <a href=\"#\" data-pick-docs>Select documentation</a> to pick which versions to use. More versions will be added in the coming weeks.\nIf you notice any bugs, please report them on <a href=\"https://github.com/Thibaut/devdocs/issues\" target=\"_blank\">GitHub</a>."
assets/javascripts/templates/pages/about_tmpl.coffee+5−0
@@ -154,6 +154,11 @@ credits = [ · 153 unmodified lines
154154 '2012 Plataformatec',
155155 'Apache',
156156 'https://raw.githubusercontent.com/elixir-lang/elixir/master/LICENSE'
157+ ], [
158+ 'Erlang',
159+ '1999-2015 Ericsson AB',
160+ 'Apache',
161+ 'https://raw.githubusercontent.com/erlang/otp/maint/LICENSE.txt'
157162 ], [
158163 'Express',
159164 '2009-2015 TJ Holowaychuk',
assets/stylesheets/global/_icons.scss+1−0
@@ -123,3 +123,4 @@ · 122 unmodified lines
123123 ._icon-relay:before { background-position: -8rem -9rem; }
124124 ._icon-phoenix:before { background-position: -9rem -9rem; }
125125 ._icon-tcl_tk:before { background-position: 0 -10rem; }
126+._icon-erlang:before { background-position: -1rem -10rem; }
assets/stylesheets/pages/_erlang.scss+7−13
@@ -1,14 +1,8 @@
1−.REFBODY {
2− margin-bottom: 20px;
3−}
4−.REFBODY+p {
5− margin-top: 30px;
6− margin-bottom: 5px;
7−}
8−.function-name {
9− font-family: $monoFont;
10− display: block;
11− margin: 0;
12− min-height: none;
13− font-weight: bold;
1+._erlang {
2+ @extend %simple;
3+
4+ h3.code { @extend %code; }
5+ .note { @extend %note; }
6+ .warning { @extend %note, %note-red; }
7+ .note .label, .warning .label { font-weight: bold; }
148 }
lib/docs/filters/erlang/attribution.rb+0−9
@@ -1,9 +0,0 @@
1−module Docs
2− class Erlang
3− class AttributionFilter < Docs::AttributionFilter
4− def attribution_link
5− %(<a href="#{base_url}" class="_attribution-link">#{base_url}</a>)
6− end
7− end
8− end
9−end
lib/docs/filters/erlang/clean_html.rb+100−4
@@ -2,10 +2,106 @@ module Docs · 1 unmodified line
22 class Erlang
33 class CleanHtmlFilter < Filter
44 def call
5− css('#leftnav').remove
6− css('#content .innertube center:last-child').remove
7− css('.function-name+br').remove
8− css('#content .footer').remove
5+ @doc = at_css('#content .innertube')
6+
7+ # frontpage
8+
9+ css('center:last-child').remove # copyright
10+
11+ css('center').each do |node|
12+ node.before(node.children).remove
13+ end
14+
15+ css('> br').remove
16+
17+ css('> font[size="+1"]:first-child').each do |node|
18+ node.name = 'h1'
19+ end
20+
21+ css('p > b:first-child:last-child > font[size="+1"]').each do |node|
22+ node = node.parent.parent
23+ node.name = 'h2'
24+ node.content = node.content
25+ end
26+
27+ css('font').each do |node|
28+ node.before(node.children).remove
29+ end
30+
31+ # others
32+
33+ # css('p > br:last-child').remove
34+
35+ css('a[name]').each do |node|
36+ parent = node.parent
37+ parent = parent.parent while parent.name == 'span'
38+ parent['id'] = node['name']
39+ node.before(node.children).remove
40+ end
41+
42+ css('h3').each do |node|
43+ node.name = 'h2'
44+ content = node.content
45+ node.content = content.capitalize if content == content.upcase
46+ end
47+
48+ css('p > span.bold_code:first-child ~ br:last-child').each do |node|
49+ parent = node.parent
50+ parent.name = 'h3'
51+ parent['class'] = 'code'
52+ parent.css('*:not(a):not(br)').each { |n| n.before(n.children).remove }
53+ node.remove
54+ parent.inner_html = parent.inner_html.strip
55+ end
56+
57+ css('span.code').each do |node|
58+ node.name = 'code'
59+ end
60+
61+ css('pre *:not(a)').each do |node|
62+ node.before(node.children).remove
63+ end
64+
65+ css('pre').each do |node|
66+ node.inner_html = node.inner_html.strip_heredoc
67+ end
68+
69+ css('.REFBODY').each do |node|
70+ if node.element_children.length == 0
71+ node.name = 'p'
72+ else
73+ node.before(node.children).remove
74+ end
75+ end
76+
77+ css('.REFTYPES').each do |node|
78+ next unless node.parent
79+ html = "<pre>"
80+ while node['class'] == 'REFTYPES'
81+ node.inner_html = node.inner_html.remove(/\n/).gsub('<br>', "\n")
82+ node.css('*:not(a)').each { |n| n.before(n.children).remove }
83+ html << node.inner_html.strip + "\n"
84+ node = node.next_element
85+ node.previous_element.remove
86+ end
87+ html.strip!
88+ html << "</pre>"
89+ node.before(html)
90+ end
91+
92+ css('.REFTYPES').remove
93+
94+ css('table').each do |node|
95+ node.remove_attribute('border')
96+ node.remove_attribute('cellpadding')
97+ node.remove_attribute('cellspacing')
98+ end
99+
100+ css('td').each do |node|
101+ node.remove_attribute('align')
102+ node.remove_attribute('valign')
103+ end
104+
9105 doc
10106 end
11107 end
lib/docs/filters/erlang/entries.rb+20−28
@@ -1,43 +1,35 @@
11 module Docs
22 class Erlang
33 class EntriesFilter < Docs::EntriesFilter
4−
54 def get_name
6− at_css('h1').try(:content).try(:strip)
5+ name = at_css('h1').content.strip
6+ name.prepend 'Guide: ' if doc.inner_html.include?('<strong>User\'s Guide</strong>')
7+ name
78 end
89
910 def get_type
10− return nil if 'STDLIB Reference Manual' == name
11− name
11+ type = subpath[/lib\/(.+?)[\-\/]/, 1]
12+ type << "/#{name}" if type == 'stdlib' && entry_nodes.length >= 10
13+ type
1214 end
1315
14− def additional_entries
15− css('div.REFBODY+p > a').map do |node|
16−
17− id = node.attribute('name').value
18−
19− # Here, "node" represents an empty <a> tag. It will later be removed
20− # by CleanTextFilter.
21− # We need to pass its id attribute to another element in order to
22− # make the function anchors in the sidebar work properly.
23− node.next_sibling['id'] = id
24− node.next_sibling['class'] = 'function-name'
25−
26− if id == name
27− # Module index page
28− [name, id, name]
29− else
30− # Erlang functions are identified
31− # by name + arity (no. of parameters).
32− # The notation is func_name/arity
16+ def include_default_entry?
17+ !at_css('.frontpage')
18+ end
3319
34− # Replaces the last hyphen with a slash.
35− # E.g: to_string-3 becomes to_string/3
36− function_name = id.gsub(/\-(?<arity>.*)$/, '/\k<arity>')
37− ["#{name}:" + function_name, id, name]
38− end
20+ def additional_entries
21+ entry_nodes.map do |node|
22+ id = node['name']
23+ name = id.gsub %r{\-(?<arity>.*)\z}, '/\k<arity>'
24+ name.remove! 'Module:'
25+ name.prepend "#{self.name}:"
26+ [name, id]
3927 end
4028 end
29+
30+ def entry_nodes
31+ @entry_nodes ||= css('div.REFBODY + p > a')
32+ end
4133 end
4234 end
4335 end
lib/docs/filters/erlang/pre_clean_html.rb+10−0
@@ -0,0 +1,10 @@
1+module Docs
2+ class Erlang
3+ class PreCleanHtmlFilter < Filter
4+ def call
5+ css('.flipMenu li[title] > a').remove
6+ doc
7+ end
8+ end
9+ end
10+end
lib/docs/scrapers/erlang.rb+25−22
@@ -1,40 +1,43 @@
11 module Docs
22 class Erlang < FileScraper
3− self.version = '18.1'
43 self.type = 'erlang'
5− self.dir = File.expand_path('~/devdocs/erlang')
6− self.base_url = 'http://www.erlang.org/doc/'
74 self.root_path = 'doc/index.html'
85 self.links = {
9− home: 'http://erlang.org/'
6+ home: 'https://www.erlang.org/',
7+ code: 'https://github.com/erlang/otp'
108 }
119
10+ html_filters.insert_after 'container', 'erlang/pre_clean_html'
1211 html_filters.push 'erlang/entries', 'erlang/clean_html'
1312
14− # The folder structure of the offline documentation
15− # differs from the online structure. We need
16− # to replace the attribution filter to generate the
17− # right attribution_link
18− text_filters.replace 'attribution', 'erlang/attribution'
13+ options[:only_patterns] = [/\Alib/]
1914
20− # Do not scrape these unnecessary links
2115 options[:skip_patterns] = [
22− /\.pdf$/,
23− /users_guide\.html$/,
24− /release_notes\.html$/,
25− /\/html\/.*_app\.html$/,
26− /\/html\/unicode_usage\.html$/,
27− /\/html\/io_protocol\.html$/
16+ /pdf/,
17+ /release_notes/,
18+ /result/,
19+ /java/,
20+ /\/html\/.*_app\.html\z/,
21+ /_examples\.html\z/,
22+ /\Alib\/edoc/,
23+ /\Alib\/erl_docgen/,
24+ /\Alib\/hipe/,
25+ /\Alib\/ose/,
26+ /\Alib\/test_server/,
27+ /\Alib\/jinterface/,
28+ /\Alib\/wx/,
29+ /\Alib\/ic/,
30+ /\Alib\/Cos/i
2831 ]
2932
30− options[:title] = false
31−
32− # Scrape stdlib documentation only
33− options[:only_patterns] = [/stdlib/]
34−
3533 options[:attribution] = <<-HTML
36− Copyright &copy; 1999-2015 Ericsson AB<br>
34+ &copy; 1999&ndash;2015 Ericsson AB<br>
3735 Licensed under the Apache License, Version 2.0.
3836 HTML
37+
38+ version '18' do
39+ self.release = '18.2'
40+ self.dir = '/Users/Thibaut/DevDocs/Docs/Erlang18'
41+ end
3942 end
4043 end
public/icons/docs/erlang/16.png+0−0

Binary file not shown.

public/icons/docs/erlang/16@2x.png+0−0

Binary file not shown.

public/icons/docs/erlang/SOURCE+1−2
@@ -1,2 +1 @@
1−http://www.pixelstech.net/images/icons/article_type/Erlang_logo.png
2−https://s3.amazonaws.com/cloud.ohloh.net/attachments/1364/erlang2_small.png
1+https://github.com/Kapeli/Dash-X-Platform-Resources