From de0e3ab80f79c914489730bdf7da27bb4f019c88 Mon Sep 17 00:00:00 2001 From: Romeo Van Snick Date: Sat, 24 May 2014 19:34:14 +0200 Subject: [PATCH] fix tables to work everywhere, add comments --- assets/stylesheets/pages/_haskell.scss | 59 +++++++++++++++++-- lib/docs/filters/haskell/clean_html.rb | 79 +++++++++++++++++++------- lib/docs/filters/haskell/entries.rb | 14 +---- 3 files changed, 115 insertions(+), 37 deletions(-) diff --git a/assets/stylesheets/pages/_haskell.scss b/assets/stylesheets/pages/_haskell.scss index dd8e661e..4abf9474 100644 --- a/assets/stylesheets/pages/_haskell.scss +++ b/assets/stylesheets/pages/_haskell.scss @@ -4,12 +4,36 @@ background-repeat: no-repeat; } +.empty-table .empty { + display: none; +} + +.arguments td.src { + background: #faf9e2; + width: 30%; +} + +th.src, td.src { font-family: $monoFont; font-weight: normal; font-style: normal; background: #f8f8f8; - width: 20%; +} + +caption { + font-weight: bold; + text-align: left; + font-style: italic; + font-size: 1.1em; +} + +// remove margin in descript listing +dd > pre { + @extend %pre; + margin: 0; + background: #faf9e2; + border-color: #dddaaa #dddaaa #d7d7a9; } // warnings are red @@ -44,18 +68,43 @@ td.src { order: 1; } +// add box type to "since: ..." .added { @extend %note; @extend %note-gold; } -.top { - margin-bottom: 3em; +.added-cell { + @extend %note-gold; +} + +.fields h3 { + display: none; +} + +// separate types more +.src { + margin-top: 2.5em; +} + +h1 + .top .src, +h2 + .top .src, +h3 + .top .src, +.caption + .top .src { + margin-top: 0; +} + +// but not for first type +h1 + .top, +h2 + .top, +h3 + .top, +h4 + .top { + margin-top: 0; } +// change color of example code .example { - -webkit-flex: none; - background: #faf9e2; border: 1px solid; + background: #faf9e2; border-color: #dddaaa #dddaaa #d7d7a9; } diff --git a/lib/docs/filters/haskell/clean_html.rb b/lib/docs/filters/haskell/clean_html.rb index 66c2e917..5f6105a7 100644 --- a/lib/docs/filters/haskell/clean_html.rb +++ b/lib/docs/filters/haskell/clean_html.rb @@ -4,11 +4,7 @@ module Docs def call # remove unwanted elements - 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 + css('#footer', '#package-header', '#module-header', '#synopsis', '.link', '#table-of-contents', '.package').remove # cpations in tables are h3 css('table .caption').each do |node| @@ -20,6 +16,7 @@ module Docs node.name = 'h1' end + # section css('.top > .caption').each do |node| node.name = 'h2' end @@ -34,39 +31,79 @@ module Docs 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 + # all pre's are examples + css('pre').each do |node| + node.add_css_class('example') + 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 + if node.name != "td" node.name = 'pre' end end - if at_css('h1') && at_css('h1').content == 'Haskell Hierarchical Libraries' - css('h1').remove + # check if second column of table is totally empty. + # and remove it if it is + css('table').each do |table| + empty = true + table.css('td + td').each do |snd| + empty = empty && snd['class'] =~ /empty/ + end + if empty + # remove empty column + table.css('td + td').remove + end end + # move table captions into the tables + css(".caption + table").each do |table| + caption = table.previous + caption.name = "caption" + caption.parent = table + end + + css(".caption + .show table").each do |table| + caption = table.parent.parent.css('.caption')[0] + caption.name = 'caption' + caption.parent = table + end + + # better arguments display: + css('.src + .arguments table').each do |table| + src = table.parent.previous # the function name + row = doc.document.create_element('tr') + table.css('tr')[0].before(row) + src.parent = row + src.name = "th" + src['colspan'] = 2 + end + + # remove root page title + if root_page? + at_css('h1').remove + end + + # add id to links (based on name) 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 + # make code in description into proper pre + css('dd > code').each do |node| + node.name = 'pre' end # add some informational boxes @@ -86,8 +123,8 @@ module Docs #

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.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 @@ -100,7 +137,11 @@ module Docs end elsif node.content =~ /Since: .*/ # add box to 'Since:' annotations - node.add_css_class('added') + if node.parent.parent.name == "td" + node.parent.parent.add_css_class('added-cell') + else + node.add_css_class('added') + end end end diff --git a/lib/docs/filters/haskell/entries.rb b/lib/docs/filters/haskell/entries.rb index 07de7c40..c0fbcbb6 100644 --- a/lib/docs/filters/haskell/entries.rb +++ b/lib/docs/filters/haskell/entries.rb @@ -10,6 +10,7 @@ module Docs # Array > [Array, nil] def get_name_and_type if at_css('h1') && at_css('h1').content == 'Haskell Hierarchical Libraries' + puts 'ok' name = 'Haskell' type = nil else @@ -50,19 +51,6 @@ module Docs n, t = get_name_and_type() 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