瀏覽代碼

Update C and C++ documentation

Closes #269. Closes #351. Closes #439. Closes #448.
Thibaut Courouble 9 年之前
父節點
當前提交
30900c3562

+ 0 - 7
assets/javascripts/views/pages/c.coffee

@@ -1,7 +0,0 @@
-#= require views/pages/base
-
-class app.views.CPage extends app.views.BasePage
-  prepare: ->
-    @highlightCode @findAll('pre.source-c, .source-c > pre'), 'c'
-    @highlightCode @findAll('pre.source-cpp, .source-cpp > pre'), 'cpp'
-    return

+ 1 - 0
assets/javascripts/views/pages/simple.coffee

@@ -9,6 +9,7 @@ class app.views.SimplePage extends app.views.BasePage
 app.views.AngularPage =
 app.views.AngularjsPage =
 app.views.BootstrapPage =
+app.views.CPage =
 app.views.CakephpPage =
 app.views.ChaiPage =
 app.views.CrystalPage =

+ 14 - 2
assets/stylesheets/pages/_c.scss

@@ -4,6 +4,8 @@
   .fmbox { @extend %note; }
   code, .t-mark, .t-mark-rev { @extend %label; }
 
+  .t-li1 { margin: 0 0 1em; }
+
   .t-mark, .t-mark-rev {
     white-space: nowrap;
     @extend %label-green;
@@ -27,11 +29,17 @@
 
   td {
     > h3, > h5 {
-      margin: 0;
+      margin: 0 0 .5em;
       line-height: inherit;
+
+      &:only-child { margin: 0; }
     }
 
-    > ul { margin: 0; }
+    > ul, > dl {
+      margin: .5em 0;
+
+      &:only-child { margin: 0; }
+    }
 
     > .t-dsc-member-div > div { // utility/functional
       float: left;
@@ -40,6 +48,8 @@
     }
   }
 
+  .t-dcl-rev-aux > td:empty { padding: 0; }
+
   .t-inheritance-diagram {
     display: table;
     margin: 1rem 0;
@@ -48,4 +58,6 @@
     border: 1px solid $boxBorder;
     border-radius: 2px;
   }
+
+  ul > ul { margin: 0 0 .5em; }
 }

+ 56 - 4
lib/docs/filters/c/clean_html.rb

@@ -6,27 +6,56 @@ module Docs
 
         css('#siteSub', '#contentSub', '.printfooter', '.t-navbar', '.editsection', '#toc',
             '.t-dsc-sep', '.t-dcl-sep', '#catlinks', '.ambox-notice', '.mw-cite-backlink',
-            '.t-sdsc-sep:first-child:last-child', '.t-example-live-link').remove
+            '.t-sdsc-sep:first-child:last-child', '.t-example-live-link',
+            '.t-dcl-rev-num > .t-dcl-rev-aux ~ tr:not(.t-dcl-rev-aux) > td:nth-child(2)').remove
 
-        css('#bodyContent', '.mw-content-ltr', 'span[style]', 'div[class^="t-ref"]').each do |node|
+        css('#bodyContent', '.mw-content-ltr', 'span[style]', 'div[class^="t-ref"]',
+            'th > div', '.t-dsc-see', '.mainpagediv', 'code > b').each do |node|
           node.before(node.children).remove
         end
 
+        css('div > ul').each do |node|
+          node.parent.before(node.parent.children).remove
+        end
+
+        css('dl > dd:first-child:last-child > ul:first-child:last-child').each do |node|
+          dl = node.parent.parent
+          if dl.previous_element && dl.previous_element.name == 'ul'
+            dl.previous_element << node
+            dl.remove
+          else
+            dl.before(node).remove
+          end
+        end
+
+        css('dl > dd:first-child:last-child').each do |node|
+          node.parent.before(node.children).remove
+        end
+
+        css('ul').each do |node|
+          while node.next_element && node.next_element.name == 'ul'
+            node << node.next_element.children
+            node.next_element.remove
+          end
+        end
+
         css('h2 > span[id]', 'h3 > span[id]', 'h4 > span[id]', 'h5 > span[id]', 'h6 > span[id]').each do |node|
           node.parent['id'] = node['id']
           node.before(node.children).remove
         end
 
         css('table[style]', 'th[style]', 'td[style]').remove_attr('style')
+        css('table[cellpadding]').remove_attr('cellpadding')
 
         css('.t-dsc-hitem > td', '.t-dsc-header > td').each do |node|
           node.name = 'th'
           node.content = ' ' if node.content.empty?
         end
 
-        css('tt', 'span > span.source-cpp', 'span.t-c').each do |node|
+        css('tt', 'span > span.source-cpp', 'span.t-c', 'span.t-lc', 'span.t-dsc-see-tt').each do |node|
           node.name = 'code'
-          node.content = node.content
+          node.remove_attribute('class')
+          node.content = node.content unless node.at_css('a')
         end
 
         css('div > span.source-cpp').each do |node|
@@ -43,6 +72,29 @@ module Docs
           node['href'] = node['href'].remove('.html')
         end
 
+        css('p').each do |node|
+          while node.next && (node.next.text? || node.next.name == 'a' || node.next.name == 'code')
+            node << node.next
+          end
+          node.inner_html = node.inner_html.strip
+          node << '.' if node.content =~ /[a-zA-Z0-9\)]\z/
+          node.remove if node.content.blank?
+        end
+
+        css('pre').each do |node|
+          node['data-language'] = if node['class'].try(:include?, 'cpp') || node.parent['class'].try(:include?, 'cpp')
+            'cpp'
+          else
+            'c'
+          end
+          node.remove_attribute('class')
+          node.content = node.content.gsub("\t", ' ' * 8)
+        end
+
+        css('code code', '.mw-geshi').each do |node|
+          node.before(node.children).remove
+        end
+
         css('h1 ~ .fmbox').each do |node|
           node.name = 'div'
           node.content = node.content

+ 5 - 10
lib/docs/filters/c/entries.rb

@@ -22,12 +22,11 @@ module Docs
       end
 
       def get_type
-        if type = at_css('.t-navbar > div:nth-child(4) > :first-child').try(:content)
-          type.strip!
-          type.remove! ' library'
-          type.remove! ' utilities'
-          type
-        end
+        type = at_css('.t-navbar > div:nth-child(4) > :first-child').try(:content)
+        type.strip!
+        type.remove! ' library'
+        type.remove! ' utilities'
+        type
       end
 
       def additional_entries
@@ -35,10 +34,6 @@ module Docs
         names.concat ADDITIONAL_NAMES[name] || []
         names.map { |name| [name] }
       end
-
-      def include_default_entry?
-        at_css '.t-navbar > div:nth-child(4) > a'
-      end
     end
   end
 end

+ 2 - 2
lib/docs/filters/c/fix_code.rb

@@ -2,10 +2,10 @@ module Docs
   class C
     class FixCodeFilter < Filter
       def call
-        css('div > span.source-c').each do |node|
+        css('div > span.source-c', 'div > span.source-cpp').each do |node|
           node.inner_html = node.inner_html.gsub(/<br>\n?/, "\n").gsub("\n</p>\n", "</p>\n")
           node.parent.name = 'pre'
-          node.parent['class'] = 'source-c'
+          node.parent['class'] = node['class']
           node.parent.content = node.content
         end
 

+ 9 - 7
lib/docs/filters/cpp/entries.rb

@@ -12,9 +12,16 @@ module Docs
         name = at_css('#firstHeading').content.strip
         name.remove! 'C++ concepts: '
         name.remove! 'C++ keywords: '
-        name.remove! 'C++ '
+        name.remove! 'C++ ' unless name == 'C++ language'
         name.remove! %r{\s\(.+\)}
         name.sub! %r{\AStandard library header <(.+)>\z}, '\1'
+        if name.include?('operator') && name.include?(',')
+          name.sub!(%r{operator.+([\( ])}, 'operators (') || name.sub!(%r{operator.+}, 'operators')
+          name.sub! '  ', ' '
+          name << ')' unless name.last == ')' || name.exclude?('(')
+          name.sub! '()', ''
+          name.sub! %r{\(.+\)}, '' if !name.start_with?('operator') && name.length > 50
+        end
         name = name.split(',').first
         REPLACE_NAMES[name] || name
       end
@@ -35,18 +42,13 @@ module Docs
       end
 
       def additional_entries
-        return [] unless include_default_entry?
+        return [] if root_page? || self.name.start_with?('operators')
         names = at_css('#firstHeading').content.remove(%r{\(.+?\)}).split(',')[1..-1]
         names.each(&:strip!).reject! do |name|
           name.size <= 2 || name == '...' || name =~ /\A[<>]/ || name.start_with?('operator')
         end
         names.map { |name| [name] }
       end
-
-      def include_default_entry?
-        return @include_default_entry if defined? @include_default_entry
-        @include_default_entry = at_css('.t-navbar > div:nth-child(4) > a') && at_css('#firstHeading').content !~ /\A\s*operator./
-      end
     end
   end
 end