Add C documentation

This commit is contained in:
Thibaut 2014-02-22 18:47:30 -05:00
parent d062b2aed9
commit 5b6d9d983b
16 changed files with 177 additions and 1 deletions

Binary file not shown.

Before

Width:  |  Height:  |  Size: 15 KiB

After

Width:  |  Height:  |  Size: 15 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 39 KiB

After

Width:  |  Height:  |  Size: 40 KiB

View file

@ -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',

View file

@ -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

View file

@ -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

View file

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

View file

@ -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; }

View file

@ -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; }
}

View file

@ -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

View file

@ -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

View file

@ -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

View file

@ -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
lib/docs/scrapers/c.rb Normal file
View file

@ -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 Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 591 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.2 KiB

View file

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