Skip to content

Commit 1819d71

Browse files
committed
Update Haskell scraper
1 parent 9a43dfb commit 1819d71

File tree

13 files changed

+120
-297
lines changed

13 files changed

+120
-297
lines changed

assets/images/icons.png

531 Bytes
Loading

assets/images/icons@2x.png

676 Bytes
Loading

assets/javascripts/templates/pages/about_tmpl.coffee

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -130,6 +130,11 @@ credits = [
130130
'2014 Grunt Team',
131131
'MIT',
132132
'https://raw.githubusercontent.com/gruntjs/gruntjs.com/master/LICENSE'
133+
], [
134+
'Haskell',
135+
'The University of Glasgow',
136+
'BSD',
137+
'http://www.haskell.org/ghc/license'
133138
], [
134139
'HTTP',
135140
'1999 The Internet Society',

assets/javascripts/templates/pages/news_tmpl.coffee

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,10 @@ newsItem = (date, news) ->
2424
result
2525

2626
app.news = [
27-
[ 1400976000000, # May 25, 2014
27+
[ 1402704000000, # June 14, 2014
28+
""" New <a href="/haskell/">Haskell</a> documentation """,
29+
], [
30+
1400976000000, # May 25, 2014
2831
""" New <a href="/laravel/">Laravel</a> documentation """,
2932
], [
3033
1399161600000, # May 4, 2014

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/ember',
3636
'pages/express',
3737
'pages/go',
38+
'pages/haskell',
3839
'pages/jquery',
3940
'pages/knockout',
4041
'pages/git',

assets/stylesheets/global/_icons.scss

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,3 +57,4 @@
5757
._icon-grunt:before { background-position: -3rem -8rem; }
5858
._icon-maxcdn:before { background-position: -4rem -8rem; }
5959
._icon-laravel:before { background-position: 0 -9rem; }
60+
._icon-haskell:before { background-position: -1rem -9rem; }
Lines changed: 18 additions & 114 deletions
Original file line numberDiff line numberDiff line change
@@ -1,121 +1,25 @@
1-
._icon-haskell:before {
2-
background-image: image-url('/icons/docs/haskell/16.png');
3-
background-size: cover;
4-
background-repeat: no-repeat;
5-
}
6-
7-
.empty-table .empty {
8-
display: none;
9-
}
10-
11-
.arguments td.src {
12-
background: #faf9e2;
13-
width: 30%;
14-
}
15-
16-
th.src,
17-
td.src {
18-
font-family: $monoFont;
19-
font-weight: normal;
20-
font-style: normal;
21-
background: #f8f8f8;
22-
}
23-
24-
caption {
25-
font-weight: bold;
26-
text-align: left;
27-
font-style: italic;
28-
font-size: 1.1em;
29-
}
30-
31-
// remove margin in descript listing
32-
dd > pre {
33-
@extend %pre;
34-
margin: 0;
35-
background: #faf9e2;
36-
border-color: #dddaaa #dddaaa #d7d7a9;
37-
}
38-
39-
// warnings are red
40-
.warning {
41-
@extend %note;
42-
@extend %note-red;
43-
}
44-
45-
46-
// complexity classes are blue boxes
47-
.with-complexity {
48-
display: flex;
49-
display: -webkit-flex;
50-
51-
justify-content: space-between;
52-
-webkit-justify-content: space-between;
1+
._haskell {
2+
> h2 { @extend %block-heading; }
3+
> h3 { @extend %block-label; }
4+
h4 { font-size: 1em; }
535

54-
align-items: flex-start;
55-
-webkit-align-items: flex-start;
6+
.module + .package, p.src > .link { float: right; }
567

57-
align-content: stretch;
58-
-webkit-align-content: stretch;
59-
}
60-
61-
.complexity {
62-
@extend %note;
63-
@extend %note-blue;
64-
margin: 0;
65-
margin-left: 1em;
66-
margin-bottom: 0.75em;
67-
font-style: italic;
68-
white-space: nowrap;
69-
70-
flex-shrink: 0;
71-
-webkit-flex-shrink: 0;
72-
73-
order: 2;
74-
-webkit-order: 2;
75-
}
76-
77-
.complexity + span {
78-
order: 1;
79-
-webkit-order: 1;
80-
}
81-
82-
// add box type to "since: ..."
83-
.added {
84-
@extend %note;
85-
@extend %note-gold;
86-
}
87-
88-
.added-cell {
89-
@extend %note-gold;
90-
}
91-
92-
.fields h3 {
93-
display: none;
94-
}
8+
.src {
9+
white-space: normal;
10+
@extend %code;
11+
}
12+
p.src { @extend %block-label, %label-blue; }
13+
dt.src { white-space: normal; }
9514

96-
// separate types more
97-
.src {
98-
margin-top: 2.5em;
99-
}
15+
.top > .subs { margin-left: 2em; }
16+
.subs p.src { margin-top: 1em; }
10017

101-
h1 + .top .src,
102-
h2 + .top .src,
103-
h3 + .top .src,
104-
.caption + .top .src {
105-
margin-top: 0;
106-
}
18+
dt > code, .complexity, .version { @extend %label; }
19+
.complexity, .version { @extend %label-green; }
10720

108-
// but not for first type
109-
h1 + .top,
110-
h2 + .top,
111-
h3 + .top,
112-
h4 + .top {
113-
margin-top: 0;
114-
}
21+
table { margin: 1em 0; }
22+
td > pre { margin: 0; }
11523

116-
// change color of example code
117-
.example {
118-
border: 1px solid;
119-
background: #faf9e2;
120-
border-color: #dddaaa #dddaaa #d7d7a9;
24+
.warning { @extend %note; }
12125
}

lib/docs/filters/haskell/clean_html.rb

Lines changed: 31 additions & 130 deletions
Original file line numberDiff line numberDiff line change
@@ -2,146 +2,54 @@ module Docs
22
class Haskell
33
class CleanHtmlFilter < Filter
44
def call
5+
root_page? ? root : other
6+
doc
7+
end
58

6-
# remove unwanted elements
7-
css('#footer', '#package-header', '#module-header', '#synopsis', '.link', '#table-of-contents', '.package').remove
8-
9-
# cpations in tables are h3
10-
css('table .caption').each do |node|
11-
node.name = 'h3'
12-
end
13-
14-
# turn captions into real headers
15-
css('.caption').each do |node|
16-
node.name = 'h1'
17-
end
18-
19-
# section
20-
css('.top > .caption').each do |node|
21-
node.name = 'h2'
22-
end
23-
24-
# subsections
25-
css('.top > .subs > .caption', '.fields > .caption').each do |node|
26-
node.name = 'h3'
27-
end
28-
29-
# subsubsections
30-
css('.top > .subs > .subs > .caption').each do |node|
31-
node.name = 'h4'
32-
end
33-
34-
# ...
35-
css('.top > .subs > .subs > .subs > .caption').each do |node|
36-
node.name = 'h5'
37-
end
38-
39-
# ......
40-
css('.top > .subs > .subs > .subs > .subs > .caption').each do |node|
41-
node.name = 'h6'
42-
end
43-
44-
# all pre's are examples
45-
css('pre').each do |node|
46-
node.add_css_class('example')
9+
def root
10+
css('#description', '#module-list').each do |node|
11+
node.before(node.children).remove
4712
end
13+
end
4814

49-
# turn source listing in to pre
50-
css('.src').each do |node|
51-
if node.name != "td"
52-
node.name = 'pre'
53-
end
15+
def other
16+
css('h1').each do |node|
17+
node.remove if node.content == 'Documentation'
5418
end
5519

56-
# check if second column of table is totally empty.
57-
# and remove it if it is
58-
css('table').each do |table|
59-
empty = true
60-
table.css('td + td').each do |snd|
61-
empty = empty && snd['class'] =~ /empty/
62-
end
63-
if empty
64-
# remove empty column
65-
table.css('td + td').remove
66-
end
20+
css('h1, h2, h3, h4').each do |node|
21+
node.name = node.name.sub(/\d/) { |i| i.to_i + 1 }
6722
end
6823

69-
# move table captions into the tables
70-
css(".caption + table").each do |table|
71-
caption = table.previous
72-
caption.name = "caption"
73-
caption.parent = table
24+
at_css('#module-header').tap do |node|
25+
heading = at_css('.caption')
26+
heading.name = 'h1'
27+
node.before(heading)
28+
node.before(node.children).remove
7429
end
7530

76-
css(".caption + .show table").each do |table|
77-
caption = table.parent.parent.css('.caption')[0]
78-
caption.name = 'caption'
79-
caption.parent = table
80-
end
31+
css('#synopsis').remove
8132

82-
# better arguments display:
83-
css('.src + .arguments table').each do |table|
84-
src = table.parent.previous # the function name
85-
row = doc.document.create_element('tr')
86-
table.css('tr')[0].before(row)
87-
src.parent = row
88-
src.name = "th"
89-
src['colspan'] = 2
33+
css('#interface', 'h2 code').each do |node|
34+
node.before(node.children).remove
9035
end
9136

92-
# remove root page title
93-
if root_page?
94-
at_css('h1').remove
37+
css('a[name]').each do |node|
38+
node['id'] = node['name']
39+
node.remove_attribute('name')
9540
end
9641

97-
# add id to links (based on name)
98-
css('a').each do |node|
99-
if node['name']
100-
node['id'] = node['name']
101-
end
102-
end
103-
104-
# make code in description into proper pre
105-
css('dd > code').each do |node|
106-
node.name = 'pre'
42+
css('p.caption').each do |node|
43+
node.name = 'h4'
10744
end
10845

109-
# add some informational boxes
11046
css('em').each do |node|
111-
if node.content == 'Deprecated.'
112-
# Make deprecated messages red.
113-
node.parent.add_css_class('warning')
114-
elsif node.content =~ /O\(.*\)/
115-
# this is big_O notation, but only apply the class if this is not
116-
# inside running text (it must be at the start of a paragraph)
117-
# from:
118-
# <p><em>O(n)</em>. Koel ok</p>
119-
# to:
120-
# <p class="with-complexity">
121-
# <span class="complexity">O(n)</span>
122-
# <span>Koel ok</span>
123-
# </p>
124-
if node.previous == nil
125-
node.add_css_class('complexity') # add css class
126-
node.name="span" # just make it div
127-
node.next.content = node.next.content.gsub(/^. /, "") # remove . if directly after em
128-
node.content = node.content.gsub(/\.$/, "") # remove trailing . if it's inside em
129-
130-
# reparent the nodes
131-
cont = doc.document.create_element "p", :class => "with-complexity"
132-
node.parent.previous = cont
133-
par = node.parent
134-
node.parent = cont
135-
par.parent = cont
136-
par.name = "span"
137-
end
138-
elsif node.content =~ /Since: .*/
139-
# add box to 'Since:' annotations
140-
if node.parent.parent.name == "td"
141-
node.parent.parent.add_css_class('added-cell')
142-
else
143-
node.add_css_class('added')
144-
end
47+
if node.content.start_with?('O(')
48+
node.name = 'span'
49+
node['class'] = 'complexity'
50+
elsif node.content.start_with?('Since')
51+
node.name = 'span'
52+
node['class'] = 'version'
14553
end
14654
end
14755

@@ -150,10 +58,3 @@ def call
15058
end
15159
end
15260
end
153-
154-
class Nokogiri::XML::Node
155-
def add_css_class( *classes )
156-
existing = (self['class'] || "").split(/\s+/)
157-
self['class'] = existing.concat(classes).uniq.join(" ")
158-
end
159-
end

0 commit comments

Comments
 (0)