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
230 'https://raw.githubusercontent.com/elixir-lang/elixir/master/LICENSE'230 'https://raw.githubusercontent.com/elixir-lang/elixir/master/LICENSE'
231 ], [231 ], [
232 'Erlang',232 'Erlang',
233 '1999-2016 Ericsson AB',233 '2010-2017 Ericsson AB',
234 'Apache',234 'Apache',
235 'https://raw.githubusercontent.com/erlang/otp/maint/LICENSE.txt'235 'https://raw.githubusercontent.com/erlang/otp/maint/LICENSE.txt'
236 ], [236 ], [
assets/javascripts/vendor/prism.js+44−0
@@ -1066,6 +1066,50 @@ Prism.languages.elixir.string.forEach(function(o) { · 1065 unmodified lines
1066});1066});
1067 1067
1068 1068
1069Prism.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};
1069Prism.languages.go = Prism.languages.extend('clike', {1113Prism.languages.go = Prism.languages.extend('clike', {
1070 '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/,1114 '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/,
1071 '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/,1115 '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
24app.views.DrupalPage =24app.views.DrupalPage =
25app.views.ElixirPage =25app.views.ElixirPage =
26app.views.EmberPage =26app.views.EmberPage =
27app.views.ErlangPage =
27app.views.ExpressPage =28app.views.ExpressPage =
28app.views.FlowPage =29app.views.FlowPage =
29app.views.GoPage =30app.views.GoPage =
assets/stylesheets/pages/_erlang.scss+1−1
@@ -1,7 +1,7 @@
1._erlang {1._erlang {
2 @extend %simple;2 @extend %simple;
3 3
4 h3.code { @extend %code; }4 h3 > code { display: block; }
5 code.code { @extend %label; }5 code.code { @extend %label; }
6 .note { @extend %note; }6 .note { @extend %note; }
7 .warning { @extend %note, %note-red; }7 .warning { @extend %note, %note-red; }
lib/docs/filters/erlang/clean_html.rb+13−10
@@ -8,7 +8,7 @@ module Docs · 7 unmodified lines
8 8
9 css('center:last-child').remove # copyright9 css('center:last-child').remove # copyright
10 10
11 css('center').each do |node|11 css('center', '.example').each do |node|
12 node.before(node.children).remove12 node.before(node.children).remove
13 end13 end
14 14
@@ -30,12 +30,10 @@ module Docs · 15 unmodified lines
30 30
31 # others31 # others
32 32
33 # css('p > br:last-child').remove
34
35 css('a[name]').each do |node|33 css('a[name]').each do |node|
36 parent = node.parent34 # parent = node.parent
37 parent = parent.parent while parent.name == 'span'35 # parent = parent.parent while parent.name == 'span'
38 parent['id'] = node['name']36 (node.next_element || node.parent)['id'] ||= node['name']
39 node.before(node.children).remove37 node.before(node.children).remove
40 end38 end
41 39
@@ -48,10 +46,11 @@ module Docs · 6 unmodified lines
48 css('p > .bold_code:first-child ~ br:last-child').each do |node|46 css('p > .bold_code:first-child ~ br:last-child').each do |node|
49 parent = node.parent47 parent = node.parent
50 parent.name = 'h3'48 parent.name = 'h3'
51 parent['class'] = 'code'49 parent.css('> br').remove
52 parent.css('*:not(a):not(br)').each { |n| n.before(n.children).remove }50 parent.css('> code').each do |code|
53 node.remove51 code.css('*:not(a):not(br)').each { |n| n.before(n.children).remove }
54 parent.inner_html = parent.inner_html.strip52 code.inner_html = code.inner_html.gsub('<br>', "\n").strip
53 end
55 end54 end
56 55
57 css('pre:not(.REFTYPES) *:not(a)', 'a[href^=javascript]').each do |node|56 css('pre:not(.REFTYPES) *:not(a)', 'a[href^=javascript]').each do |node|
@@ -59,6 +58,7 @@ module Docs · 1 unmodified line
59 end58 end
60 59
61 css('pre:not(.REFTYPES)').each do |node|60 css('pre:not(.REFTYPES)').each do |node|
61 node['data-language'] = 'erlang'
62 node.inner_html = node.inner_html.strip_heredoc62 node.inner_html = node.inner_html.strip_heredoc
63 end63 end
64 64
@@ -80,6 +80,7 @@ module Docs · 15 unmodified lines
80 node = node.next_element80 node = node.next_element
81 node.previous_element.remove81 node.previous_element.remove
82 end82 end
83 html.gsub! %r{\n{2,}}, "\n"
83 html.strip!84 html.strip!
84 html << "</pre>"85 html << "</pre>"
85 node.before(html)86 node.before(html)
@@ -98,6 +99,8 @@ module Docs · 12 unmodified lines
98 node.remove_attribute('valign')99 node.remove_attribute('valign')
99 end100 end
100 101
102 css('.bold_code').remove_attr('class')
103
101 doc104 doc
102 end105 end
103 end106 end
lib/docs/filters/erlang/entries.rb+8−4
@@ -42,12 +42,14 @@ module Docs · 41 unmodified lines
42 return [] unless include_default_entry?42 return [] unless include_default_entry?
43 43
44 if subpath.start_with?('lib/')44 if subpath.start_with?('lib/')
45 entry_nodes.map do |node|45 names = Set.new
46 entry_nodes.each_with_object [] do |node, entries|
46 id = node['name']47 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-/, '')
48 name.remove! 'Module:'50 name.remove! 'Module:'
49 name.prepend "#{self.name}:"51 name.prepend "#{self.name}:"
50 [name, id]52 entries << [name, id] if names.add?(name)
51 end53 end
52 elsif subpath.start_with?('doc/')54 elsif subpath.start_with?('doc/')
53 []55 []
@@ -65,7 +67,9 @@ module Docs · 11 unmodified lines
65 67
66 def entry_nodes68 def entry_nodes
67 @entry_nodes ||= if subpath.start_with?('lib/')69 @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
69 elsif subpath.start_with?('erts')73 elsif subpath.start_with?('erts')
70 link = at_css(".flipMenu a[href='#{File.basename(subpath, '.html')}']")74 link = at_css(".flipMenu a[href='#{File.basename(subpath, '.html')}']")
71 list = link.parent.parent75 list = link.parent.parent
lib/docs/scrapers/erlang.rb+1−1
@@ -36,7 +36,7 @@ module Docs · 35 unmodified lines
36 ]36 ]
37 37
38 options[:attribution] = <<-HTML38 options[:attribution] = <<-HTML
39 &copy; 1999&ndash;2016 Ericsson AB<br>39 &copy; 2010&ndash;2017 Ericsson AB<br>
40 Licensed under the Apache License, Version 2.0.40 Licensed under the Apache License, Version 2.0.
41 HTML41 HTML
42 42