Browse Source

Update Flow documentation (0.46.0)

Thibaut Courouble 8 years ago
parent
commit
4fabd8bc64

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

@@ -25,6 +25,7 @@ app.views.DrupalPage =
 app.views.ElixirPage =
 app.views.EmberPage =
 app.views.ExpressPage =
+app.views.FlowPage =
 app.views.GoPage =
 app.views.ImmutablePage =
 app.views.InfluxdataPage =

+ 1 - 0
assets/stylesheets/pages/_simple.scss

@@ -23,6 +23,7 @@
 ._codeceptjs,
 ._docker,
 ._fish,
+._flow,
 ._gnu,
 ._grunt,
 ._haxe,

+ 69 - 0
lib/docs/filters/flow/clean_html.rb

@@ -0,0 +1,69 @@
+module Docs
+  class Flow
+    class CleanHtmlFilter < Filter
+      def call
+        root_page? ? root : other
+        doc
+      end
+
+      def root
+        @doc = at_css('.bg-faded + .container')
+
+        css('.row', '.col-lg-4', '.card-block').each do |node|
+          node.before(node.children).remove
+        end
+
+        css('a.card').each do |node|
+          node.at_css('.text-primary').replace %(<br><a href="#{node['href']}">Read more</a>)
+          node.before(node.children).remove
+        end
+      end
+
+      def other
+        @doc = at_css('.article')
+
+        css('.nav-tabs', '#select-platform', '.guide-controls + .list-group', '.guide-controls', 'hr').remove
+
+        css('.guide-content', '.tabs', '.tab-content').each do |node|
+          node.before(node.children).remove
+        end
+
+        css('a[id].toc').each do |node|
+          node.parent['id'] = node['id']
+          node.remove
+        end
+
+        unless at_css('h2')
+          css('h3', 'h4', 'h5').each do |node|
+            node.name = node.name.sub(/\d/) { |i| i.to_i - 1 }
+          end
+        end
+
+        unless at_css('h3')
+          css('h4', 'h5').each do |node|
+            node.name = node.name.sub(/\d/) { |i| i.to_i - 1 }
+          end
+        end
+
+        css('.__cf_email__').each do |node|
+          node.replace(decode_cloudflare_email(node['data-cfemail']))
+        end
+
+        css('.editor').each do |node|
+          pre = node.at_css('.editor-code > pre')
+          pre['data-language'] = 'javascript'
+          pre.content = pre.content
+          node.replace(pre)
+        end
+
+        css('div.highlighter-rouge').each do |node|
+          node['data-language'] = node['class'][/language-(\w+)/, 1] if node['class']
+          node.content = node.content.strip
+          node.name = 'pre'
+        end
+
+        css('.highlighter-rouge').remove_attr('class')
+      end
+    end
+  end
+end

+ 15 - 0
lib/docs/filters/flow/entries.rb

@@ -0,0 +1,15 @@
+module Docs
+  class Flow
+    class EntriesFilter < Docs::EntriesFilter
+      def get_name
+        at_css('h1').content
+      end
+
+      def get_type
+        type = at_css('.guide-nav .nav-item').content.strip
+        type.remove! %r{ \(.*}
+        type
+      end
+    end
+  end
+end

+ 9 - 8
lib/docs/scrapers/flow.rb

@@ -1,17 +1,18 @@
 module Docs
-  class Flow < React
-    self.type = 'react'
-    self.release = '0.42.0'
-    self.base_url = 'https://flowtype.org/docs/'
-    self.root_path = 'getting-started.html'
+  class Flow < UrlScraper
+    self.type = 'flow'
+    self.release = '0.46.0'
+    self.base_url = 'https://flow.org/en/docs/'
     self.links = {
       home: 'https://flowtype.org/',
       code: 'https://github.com/facebook/flow'
     }
 
-    options[:container] = '.content'
-    options[:root_title] = 'Flow Documentation'
-    options[:only_patterns] = nil
+    html_filters.push 'flow/entries', 'flow/clean_html', 'title'
+
+    options[:trailing_slash] = false
+    options[:root_title] = 'Flow'
+    options[:skip] = %w(libs install)
 
     options[:attribution] = <<-HTML
       &copy; 2013&ndash;present Facebook Inc.<br>