Browse Source

Add React documentation

Thibaut 11 years ago
parent
commit
7b358f6f28

BIN
assets/images/icons.png


BIN
assets/images/icons@2x.png


+ 2 - 2
assets/javascripts/news.json

@@ -1,6 +1,6 @@
 [
-  [ "2014-12-20",
-    "New <a href=\"/rethinkdb/\">RethinkDB</a> documentation"
+  [ "2014-12-21",
+    "New <a href=\"/react/\">React</a> and <a href=\"/rethinkdb/\">RethinkDB</a> documentations"
   ], [
     "2014-11-30",
     "New <a href=\"/phpunit/\">PHPUnit</a> and <a href=\"/nokogiri/\">Nokogiri</a> documentations"

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

@@ -253,6 +253,11 @@ credits = [
     '1990-2014 Python Software Foundation<br>Python is a trademark of the Python Software Foundation.',
     'PSFL',
     'http://docs.python.org/3/license.html'
+  ], [
+    'React',
+    '2013-2014 Facebook Inc.',
+    'CC BY',
+    'https://raw.githubusercontent.com/facebook/react/master/LICENSE-docs'
   ], [
     'Redis',
     '2009-2014 Salvatore Sanfilippo',

+ 9 - 0
assets/javascripts/views/pages/react.coffee

@@ -0,0 +1,9 @@
+#= require views/pages/base
+
+class app.views.ReactPage extends app.views.BasePage
+  afterRender: ->
+    for el in @findAllByTag 'pre'
+      switch el.getAttribute('data-lang')
+        when 'html' then @highlightCode el, 'markup'
+        when 'javascript' then @highlightCode el, 'javascript'
+    return

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

@@ -57,6 +57,7 @@
         'pages/phpunit',
         'pages/postgres',
         'pages/rdoc',
+        'pages/react',
         'pages/redis',
         'pages/requirejs',
         'pages/rethinkdb',

+ 1 - 0
assets/stylesheets/components/_page.scss

@@ -15,6 +15,7 @@
 
   iframe {
     display: block;
+    margin-bottom: 1em;
     padding: 1px;
     border: 1px dotted $boxBorder;
     border-radius: 3px;

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

@@ -73,3 +73,4 @@
 ._icon-phpunit:before       { background-position: -3rem -11rem; }
 ._icon-nokogiri:before      { background-position: -4rem -11rem; }
 ._icon-rethinkdb:before     { background-position: 0 -12rem; }
+._icon-react:before         { background-position: -1rem -12rem; }

+ 8 - 0
assets/stylesheets/pages/_react.scss

@@ -0,0 +1,8 @@
+._react {
+  > h2 { @extend %block-heading; }
+  > h3 { @extend %block-label, %label-blue; }
+  > h4 { font-size: 1em; }
+
+  code { @extend %label; }
+  blockquote { @extend %note; }
+}

+ 31 - 0
lib/docs/filters/react/clean_html.rb

@@ -0,0 +1,31 @@
+module Docs
+  class React
+    class CleanHtmlFilter < Filter
+      def call
+        @doc = at_css('.inner-content')
+
+        if root_page?
+          at_css('h1').content = 'React Documentation'
+        end
+
+        css('.docs-prevnext', '.hash-link', '.edit-page-link').remove
+
+        css('a.anchor').each do |node|
+          node.parent['id'] = node['name']
+        end
+
+        css('.highlight').each do |node|
+          node.name = 'pre'
+          node['data-lang'] = node.at_css('[data-lang]')['data-lang']
+          node.content = node.content
+        end
+
+        css('blockquote > p:first-child').each do |node|
+          node.remove if node.content.strip == 'Note:'
+        end
+
+        doc
+      end
+    end
+  end
+end

+ 34 - 0
lib/docs/filters/react/entries.rb

@@ -0,0 +1,34 @@
+module Docs
+  class React
+    class EntriesFilter < Docs::EntriesFilter
+      API_SLUGS = %w(
+        top-level-api
+        component-api
+        component-specs
+      )
+
+      def get_name
+        at_css('h1').child.content
+      end
+
+      def get_type
+        link = at_css('.nav-docs-section .active')
+        section = link.ancestors('.nav-docs-section').first
+        section.at_css('h3').content
+      end
+
+      def additional_entries
+        return [] unless API_SLUGS.include?(slug)
+
+        css('.inner-content h3, .inner-content h4').map do |node|
+          name = node.content
+          name.remove! %r{[#\(\)]}
+          name.remove! %r{\w+\:}
+          id = node.at_css('.anchor')['name']
+          type = slug.include?('component') ? 'Component' : 'React'
+          [name, id, type]
+        end
+      end
+    end
+  end
+end

+ 23 - 0
lib/docs/scrapers/react.rb

@@ -0,0 +1,23 @@
+module Docs
+  class React < UrlScraper
+    self.name = 'React'
+    self.type = 'react'
+    self.version = '0.12.2'
+    self.base_url = 'http://facebook.github.io/react/docs/'
+    self.root_path = 'getting-started.html'
+
+    html_filters.push 'react/entries', 'react/clean_html'
+
+    options[:container] = '.documentationContent'
+
+    options[:skip] = %w(
+      videos.html
+      complementary-tools.html
+      examples.html)
+
+    options[:attribution] = <<-HTML
+      &copy; 2013&ndash;2014 Facebook Inc.<br>
+      Licensed under the Creative Commons Attribution 4.0 International Public License.
+    HTML
+  end
+end

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


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


+ 1 - 0
public/icons/docs/react/SOURCE

@@ -0,0 +1 @@
+https://github.com/facebook/react/blob/master/docs/img/logo.svg