clean up complexity notation and deprecated, better caption handling

pull/99/head
Romeo Van Snick 11 years ago
parent 5e18b70afd
commit 219772ffe1

@ -0,0 +1,61 @@
._icon-haskell:before {
background-image: image-url('/icons/docs/haskell/16.png');
background-size: cover;
background-repeat: no-repeat;
}
td.src {
font-family: $monoFont;
font-weight: normal;
font-style: normal;
background: #f8f8f8;
width: 20%;
}
// warnings are red
.warning {
@extend %note;
@extend %note-red;
}
// complexity classes are blue boxes
.with-complexity {
display: flex;
justify-content: space-between;
align-items: flex-start;
align-content: stretch;
flex-direction: row;
}
.complexity {
@extend %note;
@extend %note-blue;
margin: 0;
margin-left: 1em;
margin-bottom: 0.75em;
font-style: italic;
white-space: nowrap;
flex-shrink: 0;
order:2;
}
.complexity + span {
order: 1;
}
.added {
@extend %note;
@extend %note-gold;
}
.top {
margin-bottom: 3em;
}
.example {
-webkit-flex: none;
background: #faf9e2;
border: 1px solid;
border-color: #dddaaa #dddaaa #d7d7a9;
}

@ -4,29 +4,115 @@ module Docs
def call
# remove unwanted elements
css('#footer', '#package-header', '#module-header', '#synopsis', '.link', '#table-of-contents', '.empty', '.package').remove
css('#footer', '#package-header', '#module-header', '#synopsis', '.link', '#table-of-contents', '.show .empty', '.package').remove
css('pre').each do |node|
node.add_css_class('example')
end
# cpations in tables are h3
css('table .caption').each do |node|
node.name = 'h3'
end
# turn captions into real headers
css('.caption').each do |node|
node.name = 'h1'
end
css('.top > .caption').each do |node|
node.name = 'h2'
end
css('table .caption').each do |node|
# subsections
css('.top > .subs > .caption', '.fields > .caption').each do |node|
node.name = 'h3'
end
# # turn source listing in to pre
# subsubsections
css('.top > .subs > .subs > .caption').each do |node|
node.name = 'h4'
end
css('.top > .subs > .subs > .subs > .caption').each do |node|
node.name = 'h5'
end
css('.top > .subs > .subs > .subs > .subs > .caption').each do |node|
node.name = 'h6'
end
# turn source listing in to pre
css('.src').each do |node|
if node.name == "td"
# pre = doc.create_element 'pre'
# pre.children = node.children
# node.children = [pre]
else
node.name = 'pre'
end
end
if at_css('h1') && at_css('h1').content == 'Haskell Hierarchical Libraries'
css('h1').remove
end
css('a').each do |node|
if node['name']
node['id'] = node['name']
end
end
css('.caption').each do |node|
if node.content == 'Arguments'
node.remove
end
end
# add some informational boxes
css('em').each do |node|
if node.content == 'Deprecated.'
# Make deprecated messages red.
node.parent.add_css_class('warning')
elsif node.content =~ /O\(.*\)/
# this is big_O notation, but only apply the class if this is not
# inside running text (it must be at the start of a paragraph)
# from:
# <p><em>O(n)</em>. Koel ok</p>
# to:
# <p class="with-complexity">
# <span class="complexity">O(n)</span>
# <span>Koel ok</span>
# </p>
if node.previous == nil
node.add_css_class('complexity') # add css class
node.name="span" # just make it div
node.next.content = node.next.content.gsub(/^. /, "") # remove . if directly after em
node.content = node.content.gsub(/\.$/, "") # remove trailing . if it's inside em
# reparent the nodes
cont = doc.document.create_element "p", :class => "with-complexity"
node.parent.previous = cont
par = node.parent
node.parent = cont
par.parent = cont
par.name = "span"
end
elsif node.content =~ /Since: .*/
# add box to 'Since:' annotations
node.add_css_class('added')
end
end
doc
end
end
end
end
class Nokogiri::XML::Node
def add_css_class( *classes )
existing = (self['class'] || "").split(/\s+/)
self['class'] = existing.concat(classes).uniq.join(" ")
end
end

@ -51,6 +51,18 @@ module Docs
t
end
# def additional_entries
# css('a').inject [] do |entries, node|
# name = node.content
# id = node['name']
# if id
# puts id
# entries << [name, id, nil]
# end
# entries
# end
# end
end
end
end

Loading…
Cancel
Save