Skip to content

Commit 4ce964c

Browse files
committed
Finish Elixir scraper
1 parent 1ff9297 commit 4ce964c

12 files changed

Lines changed: 65 additions & 66 deletions

File tree

assets/images/icons.png

561 Bytes
Loading

assets/images/[email protected]

1.85 KB
Loading

assets/javascripts/news.json

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
11
[
22
[
3+
"2015-11-08",
4+
"New documentation: <a href=\"/elixir/\">Elixir</a>"
5+
], [
36
"2015-10-18",
47
"Added a \"Copy to clipboard\" button inside each code block."
58
], [

assets/javascripts/templates/pages/about_tmpl.coffee

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -144,6 +144,11 @@ credits = [
144144
'2015 Yehuda Katz, Tom Dale and Ember.js contributors',
145145
'MIT',
146146
'https://raw.github.com/emberjs/ember.js/master/LICENSE'
147+
], [
148+
'Elixir',
149+
'2012 Plataformatec',
150+
'Apache',
151+
'https://raw.githubusercontent.com/elixir-lang/elixir/master/LICENSE'
147152
], [
148153
'Express',
149154
'2009-2015 TJ Holowaychuk',

assets/javascripts/views/pages/elixir.coffee

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,5 +2,5 @@
22

33
class app.views.ElixirPage extends app.views.BasePage
44
prepare: ->
5-
@highlightCode @findAll('pre.elixir'), 'elixir'
5+
@highlightCode @findAllByTag('pre'), 'elixir'
66
return

assets/stylesheets/global/_icons.scss

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -116,3 +116,4 @@
116116
._icon-phalcon:before { background-position: -1rem -9rem; }
117117
%icon-clipboard { background-position: -2rem -9rem; }
118118
%icon-clipboard-white { background-position: -3rem -9rem; }
119+
._icon-elixir:before { background-position: -4rem -9rem; @extend %darkIconFix !optional; }
Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,7 @@
11
._elixir {
22
@extend %simple;
3-
h3 { @extend %block-label; }
3+
4+
.type-detail { margin-bottom: 2em; }
5+
.type-detail pre { margin-left: -1rem; }
6+
._mobile & .type-detail pre { margin-left: 0; }
47
}

lib/docs/filters/elixir/clean_html.rb

Lines changed: 17 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -2,45 +2,32 @@ module Docs
22
class Elixir
33
class CleanHtmlFilter < Filter
44
def call
5+
at_css('footer', '.view-source').remove
56

6-
# Strip h1 content
7-
css('h1').each do |node|
8-
node.content = node.content.strip
9-
end
10-
11-
# Make subtitles smaller
12-
css('h2').each do |node|
7+
css('section section.docstring h2').each do |node|
138
node.name = 'h4'
149
end
1510

16-
# Remove footer
17-
at_css('footer').remove
18-
19-
# Remove behaviour after module name
20-
css('h1').each do |node|
21-
if !(node.has_attribute?('id'))
22-
node.content = node.content.split(" ")[0]
23-
end
24-
end
25-
26-
# Remove links from summary headings
27-
css('.summary > h4 > a').each do |node|
28-
node.delete('href')
11+
css('h1 .hover-link', '.detail-link').each do |node|
12+
node.parent['id'] = node['href'].remove('#')
13+
node.remove
2914
end
3015

31-
# Add elixir class to each pre for syntax highlighting
32-
css('pre').each do |node|
33-
node['class'] = "elixir"
16+
css('.details-list').each do |list|
17+
type = list['id'].remove(/s\z/)
18+
list.css('.detail-header').each do |node|
19+
node.name = 'h3'
20+
node['class'] += " #{type}"
21+
end
3422
end
3523

36-
# Rewrite .detail -> .method-detail
37-
css('.detail').each do |node|
38-
node['class'] = "method-detail"
39-
end
24+
css('.summary h2').each { |node| node.parent.before(node) }
25+
css('.summary').each { |node| node.name = 'dl' }
26+
css('.summary-signature').each { |node| node.name = 'dt' }
27+
css('.summary-synopsis').each { |node| node.name = 'dd' }
4028

41-
# Change .detail-header to h3
42-
css('.detail-header .signature').each do |node|
43-
node.name = 'h3'
29+
css('section', 'div:not(.type-detail)', 'h2 a').each do |node|
30+
node.before(node.children).remove
4431
end
4532

4633
doc

lib/docs/filters/elixir/entries.rb

Lines changed: 23 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -2,33 +2,38 @@ module Docs
22
class Elixir
33
class EntriesFilter < Docs::EntriesFilter
44
def get_name
5-
at_css('h1').content.gsub('behaviour', ' ').strip
5+
at_css('h1').content.split(' ').first.strip
66
end
77

88
def get_type
9-
return nil if (slug.split("#")[1] == "functions")
10-
slug.split("#")[1]
9+
case at_css('h1 small').try(:content)
10+
when 'exception'
11+
'Exceptions'
12+
when 'protocol'
13+
'Protocols'
14+
else
15+
name.split('.').first
16+
end
1117
end
1218

1319
def additional_entries
14-
return [] if root_page?
15-
16-
entries = []
20+
return [] if type == 'Exceptions'
1721

18-
# Add itself (moduledoc) to entries
19-
klass = at_css('h1').content.strip.split(" ")[0]
20-
entries << [klass, klass, name]
22+
css('.detail-header .signature').map do |node|
23+
id = node.parent['id']
24+
name = node.content.strip
25+
name.remove! %r{\(.*\)}
26+
name.remove! 'left '
27+
name.remove! ' right'
28+
name.sub! 'sigil_', '~'
2129

22-
# Add functions
23-
css('.summary-functions .summary-signature a').each do |node|
24-
entries << [(name + node['href']), node['href'][1..-1], name]
25-
end
30+
unless node.parent['class'].end_with?('macro') || self.name.start_with?('Kernel')
31+
name.prepend "#{self.name}."
32+
name << " (#{id.split('/').last})"
33+
end
2634

27-
return entries
28-
end
29-
30-
def include_default_entry?
31-
!initial_page?
35+
[name, id]
36+
end
3237
end
3338
end
3439
end

lib/docs/scrapers/elixir.rb

Lines changed: 11 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -3,34 +3,29 @@ class Elixir < UrlScraper
33
self.name = 'Elixir'
44
self.type = 'elixir'
55
self.version = '1.1.1'
6-
self.base_url = 'http://elixir-lang.org/docs/stable/elixir/'
7-
self.root_path = 'extra-api-reference.html'
6+
self.base_url = 'http://elixir-lang.org/docs/stable/'
7+
self.root_path = 'elixir/extra-api-reference.html'
8+
self.initial_paths = %w(
9+
eex/EEx.html
10+
ex_unit/ExUnit.html
11+
iex/IEx.html
12+
logger/Logger.html
13+
mix/Mix.html
14+
)
815
self.links = {
9-
home: 'https://elixir-lang.org/',
16+
home: 'http://elixir-lang.org/',
1017
code: 'https://github.com/elixir-lang/elixir'
1118
}
1219

1320
html_filters.push 'elixir/clean_html', 'elixir/entries', 'title'
1421

15-
# Skip exceptions
16-
options[:skip_patterns] = [/Error/]
17-
# Skip protocols
18-
options[:skip] = %w(
19-
Collectable.html
20-
Enumerable.html
21-
Inspect.html
22-
List.Chars.html
23-
String.Chars.html
24-
)
25-
26-
options[:follow_links] = ->(filter) { filter.root_page? }
2722
options[:container] = "#content"
2823
options[:title] = false
2924
options[:root_title] = 'Elixir'
3025

3126
options[:attribution] = <<-HTML
3227
&copy; 2012 Plataformatec<br>
33-
Licensed under the Apache License, Version 2.0
28+
Licensed under the Apache License, Version 2.0.
3429
HTML
3530
end
3631
end

0 commit comments

Comments
 (0)