History

Improve Erlang documentation

Fixes #626.

Thibaut Courouble committed 9 years ago

Commit b626a9d1 parent d126ad97 files · +69 −17Browse files

Unified · Split

7 files
  1. assets/javascripts/templates/pages/about_tmpl.coffee +1 −1
  2. assets/javascripts/vendor/prism.js +44 −0
  3. assets/javascripts/views/pages/simple.coffee +1 −0
  4. assets/stylesheets/pages/_erlang.scss +1 −1
  5. lib/docs/filters/erlang/clean_html.rb +13 −10
  6. lib/docs/filters/erlang/entries.rb +8 −4
  7. lib/docs/scrapers/erlang.rb +1 −1
assets/javascripts/templates/pages/about_tmpl.coffee+1−1
@@ -230,7 +230,7 @@ credits = [ · 229 unmodified lines
230230 'https://raw.githubusercontent.com/elixir-lang/elixir/master/LICENSE'
231231 ], [
232232 'Erlang',
233− '1999-2016 Ericsson AB',
233+ '2010-2017 Ericsson AB',
234234 'Apache',
235235 'https://raw.githubusercontent.com/erlang/otp/maint/LICENSE.txt'
236236 ], [
assets/javascripts/vendor/prism.js+44−0
@@ -1066,6 +1066,50 @@ Prism.languages.elixir.string.forEach(function(o) { · 1065 unmodified lines
10661066 });
10671067
10681068
1069+Prism.languages.erlang = {
1070+ 'comment': /%.+/,
1071+ 'string': {
1072+ pattern: /"(?:\\?.)*?"/,
1073+ greedy: true
1074+ },
1075+ 'quoted-function': {
1076+ pattern: /'(?:\\.|[^'\\])+'(?=\()/,
1077+ alias: 'function'
1078+ },
1079+ 'quoted-atom': {
1080+ pattern: /'(?:\\.|[^'\\])+'/,
1081+ alias: 'atom'
1082+ },
1083+ 'boolean': /\b(?:true|false)\b/,
1084+ 'keyword': /\b(?:fun|when|case|of|end|if|receive|after|try|catch)\b/,
1085+ 'number': [
1086+ /\$\\?./,
1087+ /\d+#[a-z0-9]+/i,
1088+ /(?:\b|-)\d*\.?\d+([Ee][+-]?\d+)?\b/
1089+ ],
1090+ 'function': /\b[a-z][\w@]*(?=\()/,
1091+ 'variable': {
1092+ // Look-behind is used to prevent wrong highlighting of atoms containing "@"
1093+ pattern: /(^|[^@])(?:\b|\?)[A-Z_][\w@]*/,
1094+ lookbehind: true
1095+ },
1096+ 'operator': [
1097+ /[=\/<>:]=|=[:\/]=|\+\+?|--?|[=*\/!]|\b(?:bnot|div|rem|band|bor|bxor|bsl|bsr|not|and|or|xor|orelse|andalso)\b/,
1098+ {
1099+ // We don't want to match <<
1100+ pattern: /(^|[^<])<(?!<)/,
1101+ lookbehind: true
1102+ },
1103+ {
1104+ // We don't want to match >>
1105+ pattern: /(^|[^>])>(?!>)/,
1106+ lookbehind: true
1107+ }
1108+ ],
1109+ 'atom': /\b[a-z][\w@]*/,
1110+ 'punctuation': /[()[\]{}:;,.#|]|<<|>>/
1111+
1112+};
10691113 Prism.languages.go = Prism.languages.extend('clike', {
10701114 'keyword': /\b(break|case|chan|const|continue|default|defer|else|fallthrough|for|func|go(to)?|if|import|interface|map|package|range|return|select|struct|switch|type|var)\b/,
10711115 'builtin': /\b(bool|byte|complex(64|128)|error|float(32|64)|rune|string|u?int(8|16|32|64|)|uintptr|append|cap|close|complex|copy|delete|imag|len|make|new|panic|print(ln)?|real|recover)\b/,
assets/javascripts/views/pages/simple.coffee+1−0
@@ -24,6 +24,7 @@ app.views.DockerPage = · 23 unmodified lines
2424 app.views.DrupalPage =
2525 app.views.ElixirPage =
2626 app.views.EmberPage =
27+app.views.ErlangPage =
2728 app.views.ExpressPage =
2829 app.views.FlowPage =
2930 app.views.GoPage =
assets/stylesheets/pages/_erlang.scss+1−1
@@ -1,7 +1,7 @@
11 ._erlang {
22 @extend %simple;
33
4− h3.code { @extend %code; }
4+ h3 > code { display: block; }
55 code.code { @extend %label; }
66 .note { @extend %note; }
77 .warning { @extend %note, %note-red; }
lib/docs/filters/erlang/clean_html.rb+13−10
@@ -8,7 +8,7 @@ module Docs · 7 unmodified lines
88
99 css('center:last-child').remove # copyright
1010
11− css('center').each do |node|
11+ css('center', '.example').each do |node|
1212 node.before(node.children).remove
1313 end
1414
@@ -30,12 +30,10 @@ module Docs · 15 unmodified lines
3030
3131 # others
3232
33− # css('p > br:last-child').remove
34−
3533 css('a[name]').each do |node|
36− parent = node.parent
37− parent = parent.parent while parent.name == 'span'
38− parent['id'] = node['name']
34+ # parent = node.parent
35+ # parent = parent.parent while parent.name == 'span'
36+ (node.next_element || node.parent)['id'] ||= node['name']
3937 node.before(node.children).remove
4038 end
4139
@@ -48,10 +46,11 @@ module Docs · 6 unmodified lines
4846 css('p > .bold_code:first-child ~ br:last-child').each do |node|
4947 parent = node.parent
5048 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
49+ parent.css('> br').remove
50+ parent.css('> code').each do |code|
51+ code.css('*:not(a):not(br)').each { |n| n.before(n.children).remove }
52+ code.inner_html = code.inner_html.gsub('<br>', "\n").strip
53+ end
5554 end
5655
5756 css('pre:not(.REFTYPES) *:not(a)', 'a[href^=javascript]').each do |node|
@@ -59,6 +58,7 @@ module Docs · 1 unmodified line
5958 end
6059
6160 css('pre:not(.REFTYPES)').each do |node|
61+ node['data-language'] = 'erlang'
6262 node.inner_html = node.inner_html.strip_heredoc
6363 end
6464
@@ -80,6 +80,7 @@ module Docs · 15 unmodified lines
8080 node = node.next_element
8181 node.previous_element.remove
8282 end
83+ html.gsub! %r{\n{2,}}, "\n"
8384 html.strip!
8485 html << "</pre>"
8586 node.before(html)
@@ -98,6 +99,8 @@ module Docs · 12 unmodified lines
9899 node.remove_attribute('valign')
99100 end
100101
102+ css('.bold_code').remove_attr('class')
103+
101104 doc
102105 end
103106 end
lib/docs/filters/erlang/entries.rb+8−4
@@ -42,12 +42,14 @@ module Docs · 41 unmodified lines
4242 return [] unless include_default_entry?
4343
4444 if subpath.start_with?('lib/')
45− entry_nodes.map do |node|
45+ names = Set.new
46+ entry_nodes.each_with_object [] do |node, entries|
4647 id = node['name']
47− name = id.gsub %r{\-(?<arity>.*)\z}, '/\k<arity>'
48+ name = id.remove %r{\-\d*\z}
49+ name << ' (type)' if name.sub!(/\Atype-/, '')
4850 name.remove! 'Module:'
4951 name.prepend "#{self.name}:"
50− [name, id]
52+ entries << [name, id] if names.add?(name)
5153 end
5254 elsif subpath.start_with?('doc/')
5355 []
@@ -65,7 +67,9 @@ module Docs · 11 unmodified lines
6567
6668 def entry_nodes
6769 @entry_nodes ||= if subpath.start_with?('lib/')
68− css('div.REFBODY + p > a')
70+ css('p + div.REFBODY').each_with_object [] do |node, result|
71+ result.concat(node.previous_element.css('a[name]').to_a)
72+ end
6973 elsif subpath.start_with?('erts')
7074 link = at_css(".flipMenu a[href='#{File.basename(subpath, '.html')}']")
7175 list = link.parent.parent
lib/docs/scrapers/erlang.rb+1−1
@@ -36,7 +36,7 @@ module Docs · 35 unmodified lines
3636 ]
3737
3838 options[:attribution] = <<-HTML
39− &copy; 1999&ndash;2016 Ericsson AB<br>
39+ &copy; 2010&ndash;2017 Ericsson AB<br>
4040 Licensed under the Apache License, Version 2.0.
4141 HTML
4242