Răsfoiți Sursa

Add C documentation

Thibaut 11 ani în urmă
părinte
comite
5b6d9d983b

BIN
assets/images/icons.png


BIN
assets/images/icons@2x.png


+ 6 - 0
assets/javascripts/templates/pages/about_tmpl.coffee

@@ -39,6 +39,7 @@ app.templates.aboutPage = -> """
   <ul>
     <li><a href="https://www.heroku.com">Heroku</a> and <a href="http://newrelic.com">New Relic</a> for providing awesome free service
     <li>Daniel Bruce for the <a href="http://www.entypo.com">Entypo</a> pictograms
+    <li><a href="http://www.jeremykratz.com/">Jeremy Kratz</a> for the C logo
   </ul>
 
   <h2 class="_lined-heading" id="faq">Questions & Answsers</h2>
@@ -83,6 +84,11 @@ credits = [
     '2010-2014 Jeremy Ashkenas, DocumentCloud',
     'MIT',
     'https://raw.github.com/jashkenas/backbone/master/LICENSE'
+  ], [
+    'C',
+    'cppreference.com',
+    'CC BY-SA',
+    'http://en.cppreference.com/w/Cppreference:Copyright/CC-BY-SA'
   ], [
     'CoffeeScript',
     '2009-2014 Jeremy Ashkenas',

+ 4 - 1
assets/javascripts/templates/pages/news_tmpl.coffee

@@ -24,7 +24,10 @@ newsItem = (date, news) ->
   result
 
 app.news = [
-  [ 1392508800000, # February 16, 2013
+  [ 1393027200000, # February 22, 2013
+    """ New <a href="/c/">C</a> documentation """,
+  ], [
+    1392508800000, # February 16, 2013
     """ New <a href="/moment/">Moment.js</a> documentation """,
   ], [
     1392163200000, # February 12, 2013

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

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

+ 1 - 0
assets/stylesheets/application.css.scss

@@ -28,6 +28,7 @@
         'components/mobile';
 
 @import 'pages/angular',
+        'pages/c',
         'pages/coffeescript',
         'pages/d3',
         'pages/ember',

+ 1 - 0
assets/stylesheets/global/_icons.scss

@@ -48,3 +48,4 @@
 ._icon-d3:before            { background-position: -4rem -6rem; }
 ._icon-knockout:before      { background-position: 0 -7rem; }
 ._icon-moment:before        { background-position: -1rem -7rem; }
+._icon-c:before             { background-position: -2rem -7rem; }

+ 22 - 0
assets/stylesheets/pages/_c.scss

@@ -0,0 +1,22 @@
+._c {
+  > h2, > h3 { @extend %block-heading; }
+  > h4 { @extend %block-label, %label-blue; }
+  > p > code { @extend %label; }
+
+  .t-dcl-begin pre {
+    margin: 0;
+    padding: 0;
+    line-height: inherit;
+    background: none;
+    border: 0;
+    box-shadow: none;
+  }
+
+  .t-lines > span { display: block; } // numeric/fenv, string/byte, etc.
+
+  .t-spar { // language/switch, language/for, etc.
+    font-style: italic;
+    color: $textColorLight;
+  }
+  .t-sdsc-nopad dl, .t-sdsc-nopad dd { margin: 0; }
+}

+ 37 - 0
lib/docs/filters/c/clean_html.rb

@@ -0,0 +1,37 @@
+module Docs
+  class C
+    class CleanHtmlFilter < Filter
+      def call
+        if root_page?
+          doc.inner_html = ' '
+          return doc
+        end
+
+        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').remove
+
+        css('#bodyContent', '.mw-content-ltr', 'span[style]').each do |node|
+          node.before(node.children).remove
+        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('.t-dsc-hitem > td', '.t-dsc-header > td').each do |node|
+          node.name = 'th'
+          node.content = ' ' if node.content.empty?
+        end
+
+        css('tt').each do |node|
+          node.name = 'code'
+        end
+
+        doc
+      end
+    end
+  end
+end

+ 44 - 0
lib/docs/filters/c/entries.rb

@@ -0,0 +1,44 @@
+module Docs
+  class C
+    class EntriesFilter < Docs::EntriesFilter
+      ADDITIONAL_NAMES = {
+        'Conditional inclusion' => %w(if else elif ifdef ifndef endif).map { |s| "##{s} directive" },
+        'Function specifiers' => ['inline specifier', '_Noreturn specifier'] }
+
+      REPLACE_NAMES = {
+        'Error directive' => '#error directive',
+        'Filename and line information' => '#line directive',
+        'Implementation defined behavior control' => '#pragma directive',
+        'Replacing text macros' => '#define directive',
+        'Source file inclusion' => '#include directive',
+        'Warning directive' => '#warning directive' }
+
+      def get_name
+        name = at_css('#firstHeading').content.strip
+        name.sub! 'C keywords: ', ''
+        name.sub! %r{\s\(.+\)}, ''
+        name = name.split(',').first
+        REPLACE_NAMES[name] || name
+      end
+
+      def get_type
+        if type = at_css('.t-navbar > div:nth-child(4) > :first-child').try(:content)
+          type.strip!
+          type.sub! ' library', ''
+          type.sub! ' utilities', ''
+          type
+        end
+      end
+
+      def additional_entries
+        names = at_css('#firstHeading').content.split(',')[1..-1]
+        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

+ 21 - 0
lib/docs/filters/c/fix_code.rb

@@ -0,0 +1,21 @@
+module Docs
+  class C
+    class FixCodeFilter < Filter
+      def call
+        css('div > span.source-c').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.content = node.content
+        end
+
+        nbsp = Nokogiri::HTML('&nbsp;').text
+        css('pre').each do |node|
+          node.content = node.content.gsub(nbsp, ' ')
+        end
+
+        doc
+      end
+    end
+  end
+end

+ 11 - 0
lib/docs/filters/c/fix_urls.rb

@@ -0,0 +1,11 @@
+module Docs
+  class C
+    class FixUrlsFilter < Filter
+      def call
+        html.gsub! File.join(C.base_url, C.root_path), C.base_url[0..-2]
+        html.gsub! %r{#{C.base_url}([^"']+?)\.html}, "#{C.base_url}\\1"
+        html
+      end
+    end
+  end
+end

+ 22 - 0
lib/docs/scrapers/c.rb

@@ -0,0 +1,22 @@
+module Docs
+  class C < FileScraper
+    self.type = 'c'
+    self.dir = '/Users/Thibaut/DevDocs/Docs/C/en/c'
+    self.base_url = 'http://en.cppreference.com/w/c/'
+    self.root_path = 'header.html'
+
+    html_filters.insert_before 'clean_html', 'c/fix_code'
+    html_filters.push 'c/entries', 'c/clean_html', 'title'
+    text_filters.push 'c/fix_urls'
+
+    options[:container] = '#content'
+    options[:title] = false
+    options[:root_title] = 'C Programming Language'
+    options[:skip] = %w(language/history.html)
+
+    options[:attribution] = <<-HTML
+      &copy; cppreference.com<br>
+      Licensed under the Creative Commons Attribution-ShareAlike Unported License v3.0.
+    HTML
+  end
+end

BIN
public/icons/docs/c/16.png


BIN
public/icons/docs/c/16@2x.png


+ 2 - 0
public/icons/docs/c/SOURCE

@@ -0,0 +1,2 @@
+http://dribbble.com/shots/799814-Standard-C-Logo
+with authorization from Jeremy Kratz